This clock took a long time to get right! However, there's enough interesting stuff going on in the circuitry that its worth explaining how some of the decisions were made and why they work.
This tutorial was written for a slightly older version, there are some minor differences, the differences do not affect the overall functionality.
There is a 2.1mm jack J1for center-positive ~9VDC power supplies. D1 is a protection diode, in the kit this is a schottky to avoid mixups but a 1N4001 is fine too. C1 and C2 provide input noise filtration. The input voltage is called 9V but it can range from 7V to 16V depending on the wall wart used.
The regulator is a classic 7805, TO-220 style. On the board layout, we use the ground plane as a basic heatsink. This part passes about 150mA and it gets a little hot.
D2 is another diode, this one is used to prevent the tiny coin cell from back-powering the 7805 which has huge quiescent current (like 2mA). We use a schottkey so that the voltage drop is about 0.2V. C3 andC4 are output noise filtration caps.
The boost circuit works by connecting the power inductor L1 to ground that current can flow through it by turning on Q2. After a little bit of time, we disconnect the from ground (by turning off Q2) this means that there is no longer a path for the current in L1 to flow to ground. When this happens, the voltage across the inductor increases (this is the electric property of inductors) and charges up C6 . When the voltage increases to the level we want it to be (30V+) we turn on Q2 again which allows the current in L1 to flow back to ground. If we do this fast enough, and C6 large enough, the voltage on C6 is smoothed out and we get a nice steady high voltage.
The timing of turning off/on Q2 allows us to modify the output voltage. Normally there is a feedback resistor to the microcontroller but it is not here because we are running it open-loop. To drive Q2 we use the PWM output from the microcontroller and adjust the duty cycle to vary brightness.
- The voltage in is nominally 9 to 12VDC
- The current draw for the IV-18 tubes is about 8mA per digit and 11mA for the grid. Remember, though, that we only light up one digit at a time! So we need about 20mA total (we also meaured this in-circuit to verify)
- The voltage output is going to be between 30V-50V (its really much too bright after that point)
- The PWM output speed of the microcontroller is F_CPU / 256 = 8 MHz / 256 = 31.25KHz (period of 32 useconds)
The optimal transfer between Vin and Vout is:
Vo/Vi = 1 / (1-D) where D is the duty cycle.Solving for D = 1 - (Vi/Vo) and plugging in numbers:
For Vo = 50V and Vi = 9V, D = 82% (maximum)So the duty range will be between 60% and 82%. That would correspond to between ~150 and 220 out of 256, but note that when the PWM signal is low the switch is on so we need to invert that to a range of about 36 to 106 (in the code we actually use about 20 to 90).
For Vo = 30V and Vi = 12V D = 60% (minimum)
OK so our PWM range is good, we just want to keep it between around 10% and 90% which we do.
Next, we need to make sure that the inductor continuously dumps current into C6 the entire time Q2 is off (continuous conduction mode). This is dependant on a lot of variables:
D*T*Vin/(2*L) < iout/(1-D)Note that T is period time and is = 1/frequency. Solving for L, we choose the lowest duty cycle which will give us the upper bound for the inductor:
D*Vin * (1-D) / (freq * 2 * Iout ) < LThis is our upper limit, so lets just say L = 2200uH (a standard value). Note that for 9V->60 we need L > 918uH which is our lower bound and our average case is a duty cycle of about 70% which is 1500uH.
D = 60% (0.6)
iout = 20mA (0.02 Amp)
Vin = 12V nominal
1/T = freq = 31250 HzL > 0.6 * 12 * (1 - 0.6) / (31250* 2 * 0.02)
L > 2304 uH
We also want to make sure that we have a enough current capacity, so lets calculate the maximum current that builds up in the inductor. We now have to pick this for the -smallest- inductor, in the case of 9V boosting to 50V, an 82% duty cycle.
Ipk = (Vin * D)/(f * L)So! We want to make sure our inductor is > 2200 uH and will not saturate below 0.24 A.
Ipk = (9 * 0.82)/(31250 * .001) = 0.24 Amp
The important thing to note here is that, for a given package (size) of inductor, the higher the inductance the lower the current capability.
Since this is a through-hole kit, we have to stick with a radial/axial inductor.
It looks like we're good to go with this group of inductors as the max current capacity of the 2200uH is well above our minimum 0.25 Any value higher than that will be OK as the Ipk will fall faster than the IDCmax
In reality, you don't need such high inductances because our system is not running on a battery and doesn't require a great power supply with low ripple and good efficiency. Inducances 270uH and lower worked just fine, the converter is operating in discontinuous mode which is not as efficient. Its also not as easy to calculate the precise specifications. Luckily this is a very indiscriminate tube and is cool with ripple and voltage fluctuations.
The diode is a schottky type, and needs to have a breakdown voltage larger than the maximum boost voltage (in this case 60V) we're using MBR160 with 60V breakdown.
One way to improve the design to reduce the size and power requirements of the inductor is to increase the frequency. Doubling the frequency halves the required inductance and current requirements of the inductor!
Thanks tons to Riad at jfet.org for the idea and calculations! (He has some great clock designs, so check them out)
The VFD tube is the display for the clock. It has 9 digits, 8 of which are standard 7 segment plus dot displays. The leftmost digital has only a * and -. Instead of having 60+ connections for each segment, the display is gridded out so that you can only turn on one digit at a time (1-9) with the selected segments (A-H). The microcontroller sweeps through all of the digits in order at >100Hz so that it appears as if they are all lit up at once.
The segment lines are to be powered with 30-60VDC only. There is also a ground connection and a VBias pin, which is used for the display filament. In theory the filament should be driven with a 60Hz AC supply but DC is acceptable in this case.
Because the VFD runs at high voltages, a microcontroller cant drive them directly. We could use high voltage transistors and use those as buffers but that would take a lot of space so instead we use a VFD controller chip, this one in particular is called the MAX6921. Its quite nice in that you can control it with only 3 or 4 lines (SPI protocol). The output pins of the driver go to the header which is connected to the VFD.
There is also a PNP transistor that we use to turn off both the filament DC bias voltage and the power to the driver. This saves power when the clock is in sleep mode.
Finally we get to the brains of the project, an AVR microcontroller. This one in particular is the ATmega168V or 168P. The V or P designation means it can run at 1.8V voltages, otherwise the chip requires 4V or more to run and that is more than the battery backup voltage
ISP is the In-circuit Serial Programming header, it is a standard 6-pin male header in the standard layout for AVR programmers
Since this project is a clock, it needs to tell time accurately. Q1, C8 and C9 are the 32.768KHz clock crystal that allows the chip to keep time. The internal oscillator is not nearly precise enough and external resonators or crystals are better but still not as good. 32.768KHz has a nice property that it oscillates 2^15 times per second which makes the timer math easy. Q1 should have 12.5 pF load capacitance. C8/C9 are chosen to match this capacitance and are equal to approximately 2* the load capacitance. The reason they are 22pF and not 25pF is that there is 3pF capacitance just for the chip, PCB and socket. With proper matching, the clock should keep time to 0.002 % accuracy or better - about 2 seconds a day.
There are some interface buttons S1, S2 and S3 these are for setting the clock and displaying the date. SW1 is a SPDT right-angle slide switch which turns the alarm on and off. There are no external pull-ups because we are using the ones internal to the AVR.
There is also a piezo buzzer SPK, used for the alarm function. There are two pins used on either side. For low volume, one pin is connected to ground and the other pin oscillates to create a 5 Vpp squarewave. For high volume, the first pin is made to oscillate opposite from the second, this creates the appearance of a 10 Vpp square wave which is much louder!
R1 and R2 are a resistor divider that allows the microcontroller to be alerted when the DC adapter loses power. If the power supply is at 4.5V or higher, then the voltage at the input pin is
Vpin = Vsupply * R2 / (R1+R2)
4.5V * 100/(100+270) = 1.22V
Which means that, at worst, the voltage is 1.22V
When the power dies, and goes to battery backup, the voltage is about:
3V * 100/(100+270) = 0.8V
The input pin on the microcontroller is connected to the analog comparator. The other side of the comparator is connected to the internal band-gap reference, a voltage that is the same no matter what the power supply is at. According to the datasheet, the bandgap is at 1.1V and at most is 1.2V. When the input voltage drops below this reference of 1.1V (which corresponds to 4VDC), the microcontroller receives an interrupt immediately indicating that the power died. Because the microcontroller is extremely fast, it can go into sleep mode within 100 cycles (12.5 microseconds). The faster it goes into sleep mode the less power is consumed so this is much faster than checking an ADC pin every second. C10 is just there to stabilize the divider and prevent power spikes from turning the clock off.
R4 and the two pads CT1 and CT2 are not used in general and are basically intended for hacks and mods, adding sensors or using the clock to trigger an output.