Project includes:

Helper Spreadsheet

EagleCAD CCT & PCB files

MikroBasic Firmware Source

**Signing Up**

## Step 1: How does it work?

(http://ww1.microchip.com/downloads/en/AppNotes/91053b.pdf )

The illustration below is excerpted from TB053. It outlines the basic principle behind the SMPS. A microcontroller grounds a FET (Q1), allowing a charge to build in inductor L1. When the FET is turned off, the charge flows through diode D1 into capacitor C1. Vvfb is a voltage divider feedback that allows the microcontroller to monitor the high voltage and activate the FET as needed to maintain the desired voltage.

## Step 2: Inductor characteristics

The inductors I used are "C&D Technologies Inductors RADIAL LEAD 100uH" (Mouser part 580-18R104C, 1.2 amp, $1.40), (Mouser part 580-22R104C, 0.67 amp, $0.59). I chose these inductors because they are very small, very cheap, yet have decent power ratings.

We already know the max continuous rating of our coil (0.67 amps for the 22R104C), but we need to know how long it will take to charge (rise time). Rather than use a fixed charge time (see equation 6 in TB053) to determine the required coil amps, we can interrogate equation 6 and solve for rise time: (note: equation 6 in TB053 is wrong, it should be L, not 2L)

(Volts in/Inductor uH)*rise_time=Peak Amps

-becomes-

(Inductor uH/Volts in) * Peak Amps = rise time.

-using the 22R104C with a 5 volt supply gives the following-

(100/5)*0.67=13.5uS

It will take 13.5 uS to fully charge the inductor coil at 5 volts. Obviously, this value will vary with different supply voltages.

As noted in TB053:

"The current in an inductor cannot change instantaneously. When Q1 is switched off, the current in L1 continues to flow through D1 to the storage capacitor, C1, and the load, RL. Thus, the current in the inductor decreases linearly in time from the peak current."

We can determine the amount of time it takes the current to flow out of inductor using TB05 equation 7. In practice this time is very short. This equation is implemented in the included spreadsheet, but will not be discussed here.

How much power can we get out of a 0.67 amp inductor? Total power is determined by the following equation (tb053 equation 5):

Power=(((rise time)*(Volts in)

^{2)/(2*Inductor uH))}

-using our previous values we find-

1.68 Watts=(13.5uS*5volts

^{2)/(2*100uH)}

-convert watts to mA-

mA=((Power Watts)/(output volts))*1000

-using an output voltage of 180 we find-

9.31mA = (1.68Watts/180volts)*1000

We can get a maximum of 9.31 mA from this coil with a 5 volt supply, ignoring all inefficiencies and switching losses. Greater output power can be achieved by increasing the supply voltage.

All of these calculations are implemented in "Table 1: Coil Calculations for High Voltage Power Supply" of the spreadsheet included with this instructable. Several example coils are entered.

## Step 3: Driving the SMPS with a Microcontroller

We already know the required rise time from our previous calculations: 13.5uS. TB053 suggests that rise time be 75% of the period. I determined my period value by multiplying the rise time by 1.33: 17.9uS. This is consistent with the suggestion in TB053 and ensures that the inductor stays in discontinuous mode â€“ discharging completely after each charge. It is possible to calculate a more exact period by adding the calculated rise time to the calculated fall time, but I have not attempted this.

Now we can determine the actual duty cycle and period values to enter into the microcontroller to get the desired time intervals. In the Microchip PIC Mid-range manual we find the following equations (http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf ):

PWM Duty Cycle uS =(10 bit Duty Cycle Value) * (1/ oscillator Frequency) * Prescaler

If we set prescaler to 1 and beat this equation with an algebra stick we get:

10 bit Duty Cycle Value = PWM Duty Cycle uS * Oscillator Frequency

Substitute the Duty Cycle uS for calculated rise time, and assume a 8 Mhz oscillator frequency:

107 = 13.5uS * 8Mhz

107 is entered into the PIC to get a duty cycle of 13.5uS.

Next, we determine the PWM Period Value. From the Mid-Range Manual we get the following equation:

PWM period uS = ((PWM period value) + 1) * 4 * (1/oscillator frequency) * (prescale value)

Again, we set prescaler to 1 and harass the equation for PWM period value, giving us:

PWM period value = ((PWM Period uS/(4/Oscillator frequency))-1)

Substitute Period uS for (1.33*rise time), and assume a 8 Mhz oscillator frequency:

35= ((17.9/(4/8))-1)

35 is entered into the PIC to get a period of 17.9uS. But wait! Isn't the period shorter than the duty cycle? No - PICs have a 10 bit duty cycle register and a 8 bit period register. There is more resolution for the duty cycle value, thus its value will sometimes be larger than the period value - especially at high frequencies.

All of these calculations are implemented in "Table 2. PWM Calculations" of the spreadsheet included with this instructable. Several example coils are entered.

## Step 4: PCB design

I looked at several existing designs when making this PCB. Here are my notes re:important design characteristics:

1.I followed the Microchip APP note and used a TC4427A to drive the FET. This A) protects the microcontroller from flyback voltages coming off the FET, and B) can drive the FET at higher voltages than the PIC for faster/harder switching with better efficiency.

2.The distance from the PWM of the PIC to the FET is minimized.

3. FET, inductor, capacitors packed really tight.

4. Fat supply trace.

5. Good ground between FET and wall-wort connection point.

I chose the PIC 12F683 microcontroller for this project. This is a 8 pin PIC with hardware PWM, 4 analog to digital converters, 8Mhz internal oscillator, and 256 byte EEPROM. Most importantly, I had one on had from a previous project. I used the IRF740 FET because of its high acclaim on the Neonixie-L list. There are 2 capacitors to smooth the HV supply. One is a electrolytic (high temperature, 250 volts, 1uF), the other is a metal film (250 volts, 0.47uf). The latter is much larger and more expensive ($0.50 vs $0.05), but necessary to get a clean output.

There are two voltage feedback circuits in this design. The first allows the PIC to sense the output voltage and apply pulses to the FET as needed to maintain the desired level. "Table3. High Voltage Feedback Network Calculations" can be used to determine the correct feedback value given the 3 resistor voltage divider and desired output voltage. Fine tuning is done with the 1k trimmer resistor.

The second feedback measures the supply voltage so the PIC can determine optimal rise time (and period/duty cycle values). From the equations in step 1 we found that the inductor rise time is dependent on the supply voltage. It is possible to enter exact values from the spreadsheet into your PIC, but if the power supply is changed the values are no longer optimal. If running from batteries, the voltage will decrease as the batteries discharge necessitating a longer rise time. My solution was to let the PIC calculate all of this and set its own values (see firmware).

The three pin jumper selects the supply source for the TC4427A and inductor coil. It is possible to run both from the 7805 5 volt regulator, but better efficiencies and higher output is achieved with a bigger supply voltage. Both the TC4427a and the IRF740 FET will withstand up to ~20 volts. Since the PIC will calibrate for any given supply voltage it makes sense to feed these directly from the power supply. This is especially important in battery operation - no need to waste power in the 7805, just feed the inductor directly from the cells.

The LEDs are optional, but handy for trouble shooting. The 'left' LED (yellow in my boards) indicates that HV feedback is under the desired point, while the right LED (red in my design) indicates it is over. In practice you get a nice PWM effect in which the LEDS glow in intensity relative to the current load. If the red LED turns (solid) off it indicates that, despite its best effort, the PIC can't keep the output voltage at the desired level. In other words, the load exceeds the SMPS maximum output.

DONT FORGET THE JUMPER WIRES SHOWN IN RED!

Partlist

Part Value

C1 1uF 250V

C3 47uF 50V

C4 47uF (50V)

C5 0.1uF

C6 .1uf

C7 4u7 (50V)

C8 0.1uF

C9 0.1uF

C11 0.47uF/250V

D1 600V 250ns

IC2 TC4427a

IC5 7805 5volt regulator

IC7 PIC 12F683

L1 Inductor (22R104C)

LED1

LED2

Q1 IRF740

R1 120K

R2 0.47K

R3 1K Linear Trimmer

R4 330 Ohm

R5 100K

R6 330 Ohm

R7 10K

SV1 3 Pin Header

X2 3 Screw Terminal

## Step 5: Firmware

If you need a PIC programmer, consider my enhanced JDM2 programmer board also posted at instructables (http://www.instructables.com/ex/i/6D80A0F6DA311028931A001143E7E506/?ALLSTEPS ).

Basic operation:

1.When power is applied the PIC starts.

2.PIC delays for 1 second to allow voltages to stabilize.

3.PIC reads the supply voltage feedback and calculates optimal duty cycle and period values.

4.PIC logs the ADC reading, duty cycle, and period values to the EEPROM. This allows some trouble shooting and helps diagnose catastrophic failures. EEPROM address 0 is the write pointer. One 4 byte log is saved each time the SMPS is (re-)started. The first 2 bytes are ADC high/low, third byte is lower 8 bits of duty cycle value, fourth byte is the period value. A total of 50 calibrations (200 bytes) are logged before the write pointer rolls over and starts again at EEPROM address 1. The most recent log will be located at pointer-4. These can be read out of the chip using a PIC programmer. The upper 55 bytes are left free for future enhancements (see improvements).

5.PIC enters endless loop - high voltage feedback value is measured. If it is below the desired value the PWM duty cycle registers are loaded with the calculated value - NOTE: the lower two bits are important and must be loaded into CPP1CON 5:4 , upper 8 bits go into CRP1L. If the feedback is above the desired value, the PIC loads the duty cycle registers with 0. This is a 'pulse skip' system. I decided on pulse skip for two reasons: 1) at such high frequencies there isn't a lot of duty width to play with (0-107 in our example, much less at higher supply voltages), and 2) frequency modulation is possible, and gives a lot more room for adjustment (35-255 in our example), but ONLY DUTY IS DOUBLE BUFFERED IN HARDWARE. Changing the frequency while the PWM is operating can have 'strange' effects.

Using the firmware:

Several calibration steps are required to use the firmware. These values must be compiled into the firmware. Some steps are optional, but will help you get the most out of your power supply.

const v_ref as float=5.1 'float

const supply_ratio as float=11.35 'float

const osc_freq as float=8 'float

const L_Ipeak as float=67 'float

const fb_value as word=290 'word

These values can be found at the top of the firmware code. Find the values and set as follows.

v_ref

This is the voltage reference of the ADC. This is needed to determine the actual supply voltage to include in the equations described in step1. If the PIC is run from an 7805 5volt regulator we can expect around 5 volts. Using a multimeter measure the voltage between the PIC power pin (PIN1) and ground at the screw terminal. My exact value was 5.1 volts. Enter this value here.

supply_ratio

The supply voltage divider consists of a 100K and 10K resistor. Theoretically the feedback should equal the supply voltage divided by 11 (see Table 5. Supply Voltage Feedback Network Calculations). In practice, resistors have various tolerances and are not exact values. To find the exact feedback ratio:

1.Measure the supply voltage between the screw terminals.

2.Measure the feedback voltage between PIC pin 7 and ground at the screw terminal.

3.Divide Supply V by FB V to get an exact ratio.

You can also use "Table 6. Supply Voltage Feedback Calibration".

osc_freq

Simply the oscillator frequency. I use the 12F683 internal 8Mhz oscillator, so I enter a value of 8.

L_Ipeak

Multiply the inductor coil uH by the maximum continuous amps to get this value. In the example the 22r104C is a 100uH coil with a rating of .67amps continuous. 100*.67=67. Multiplying the value here eliminates one 32 bit floating point variable and calculation that would otherwise have to be done on the PIC. This value is calculated in "Table 1: Coil Calculations for High Voltage Power Supply".

fb_value

This is the actual integer value the PIC will use to determine if the high voltage output is above or below the desired level. Use Table 3 to determine the ratio between the HV output and feedback voltage when the linear trimmer is in the center position. Using the center value gives adjustment room on either side. Next, enter this ratio and your exact voltage reference in "Table 4. High Voltage Feedback ADC Set Value" to determine the fb_value.

After you find these values enter them into the code and compile. Burn the HEX to the PIC and you're ready to go! REMEMBER: EEPROM byte 0 is the log write pointer. Set it to 1 to begin logging to byte 1 on a fresh pic.

Because of the calibration, the FET and inductor should never become warm. Nor should you hear a ringing sound from the inductor coil. Both of these conditions indicate a calibration error. Check the data log in the EEPROM to help determine where your problem might be.

## Step 6: Improvements

1.Put the screw terminal closer to FET for better ground path.

2.Fatten the supply trace to the capacitors and inductor.

3.Add a stable voltage reference to improve operation from batteries and supply voltages less than 7 volts (where the output of the 7805 dips below 5 volts).

4.Use the upper 55 EEPROM bytes to log fascinating bit of useless data - total run time, overload events, min/max/average load.

-ian

instructables-at-whereisian-dot-com

Are you sure the equation 6 in TB053 is wrong? I have made a simple PIC program that I use to switch 12 volts across a a 1.1A 100uF inductor and using the equation (using L instead of 2L), I get 100/12 * 1.1 = 9.16uS. Multiply this by 1.33 gives 12.18uS. So a frequency of 82KHz.

When I run this code, I scope the output and I am indeed getting 82KHz, but even with a 75% duty cycle, the maximum voltage I can get is about 74V.

If the equation in the notes were correct I would have (2*100) / 12 * 1.1 = 18.33uS

18.33 * 1.33 = 24.38uS

Giving a 41KHz PWM frequency, which I think would give me a better voltage output.

All I can find on the internet about inductor charging time involves a series resistor. Please can you explain where you got the equation from.

Craig.

Actually, I think my problem may be that my diode isn't quick enough. I have just ordered some FR305, 250ns diodes. I'll see if that makes a difference.

Just out of interest, I have also got an a voltage divider on my input voltage to an analogue pin of the PIC which will alter the frequency depending on the input voltage. At the moment, I only have 2 settings, <5.5V and 5.5 - 12V, but may incorporate some more.

I've changed the diode, but still no luck. 68v is the most I can get out of it.

I'm running the frequencies as calculated in the instructable, but no luck. Any advice?

Great instructable Ian. Really appreciate the explanations on SMPS operation, calculations of inductor values etc. Thanks for sharing. :)

Hey Ian,

Thanks for the awesome instructables! I really learned a great deal from it and you explained everything so thoroughly. I appreciate it. I'm hoping to use this circuit for a clock I'm building. Because of my design I already have regulated voltage rails so I'm assuming I don't need some of the components. I'm also using a different microcontroller for regulating voltage so the PIC wouldn't be needed. I was wondering if you could help me slim down your design, or at least tell me which components I can omit. I'm not quite versed in analog electronics so this is a bit new to me. I get the basics but I'm still a bit confused. Feel free to PM me. Thanks again!

A quick web search for "nixie tube" would provide you with far more information than I can or care to include in a posting.

How do you fab your boards? Do you use a home etch kit or do you order online? Most places I've checked are pretty steep for one-off orders. Got a recommendation?

Thx,

PT

Would it be possible/feasible to make a 300W power supply with something like this? Obviously, some modifications would be required.

I'm building a hot-air rework station, and having trouble finding a (cheap) power supply in the 300W range. I've always wanted to make your SMPS, and it would be cool to use it in my project. The PSU would be used to power a heating element like this: http://www.sparkfun.com/commerce/product_info.php?products_id=73

I would need to be able to adjust the power going to the heating element, so the pump would probably be powered separately just to keep things simple.

(I want the couch on your website)

A few thoughts:

1) Sure, you can make a 300W version with enough/big enough induction coils, but there are much better 'topologies' for such a large SMPS. I would suggest you talk to the helpful people on the Yahoo 'Switchmode' mailing list.

2)My hot air gun is pretty heavy. I bet it has a transformer coil rather than an SMPS. This would prob. be easier to deal with.

3) Have you checked the cost of cheap chineese hot air stations? I got mine for only 3x more than the element you link to (about $100). I bet in the end it is cheaper to buy one then put it together, and much safer too. 300 W is a lot of power to provide (in terms of component cost), and you need some heavy duty casing material etc.

This is the hot air rework station (and soldering iron and smoke extractor) that I bought for around $100 (shop around for better prices then amazon):

http://www.amazon.com/Aoyue-968-Digital-Rework-Station/dp/B000HDG0AO

It is the AOYUE 968. This cheap brand is even recommend by sparkfun in their hot air tutorial. I've had mine for almost a year, and I totally love it. The hot air gun is great, but I've really enjoyed having a quality adjustable soldering iron (I used $10 fire starters before this). The smoke extractor saves a bunch of time because I don't have to hold my head away every time nasty smoke rises from the solder and rosin. I believe (have read several times, but not tried) that this iron is compatible with Hakko (expensive/major rework station brand) parts (tips, heating elements, etc).

As you might divine, I am a fanboi for this tool. It was so cheap, and now i feel not having it was holding me back. I solder QFN on a regular basis without breaking a sweat. Give it some consideration, it was much cheaper than I thought and it will probably last forever for light-medium duty work.

http://www.instructables.com/ex/i/DA49B952E2CE10288F99001143E7E506/