3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Switch Mode Altoids iPOD Charger using 3 'AA' batteries

Step 4FIRMWARE

FIRMWARE
FIRMWARE
Complete details of the SMPS firmware are outlined in the nixie SMPS instructable. For all the math and dirty details of SMPS, read my nixie tube boost converter instructable:
(http://www.instructables.com/ex/i/B59D3AD4E2CE10288F99001143E7E506/?ALLSTEPS )
The firmware is written in MikroBasic, the compiler is free for programs up to 2K (http://www.mikroe.com/ ).
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 firmware 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.

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.

Changes:
The firmware gets a few updates from the nixie tube SMPS version.

1.The pin connections are changed. One LED is eliminated, a single led indicator is used. Pin out is shown in the image. Descriptions in red are default PIC pin assignments that cannot be changed.
2.The analog digital converter is now referenced to an external voltage on pin 6, rather than the supply voltage.
3.As the batteries drain the supply voltage will change. The new firmware takes a supply voltage measurement every few minutes and updates the pulse width modulator settings. This "recalibration" keeps the inductor operating efficiently as the batteries discharge.
4.Internal oscillator set to 4 MHz, a safe operating speed to about 2.5 volts.
5.Fixed logging so nothing needs to be set in EEPROM to start at position 1 on a fresh PIC. Easier to grasp for beginners.
6.Inductor discharge time (off-time) is now calculated in firmware. The previous multiplier (one-third on-time) is inadequate for such small boosts. The only way to maintain efficiency throughout the battery discharge was to extend the firmware to calculate the true off-time. The modifications are experimental, but have since been incorporated into the final firmware.

From TB053 we find the off-time equation:

0=((volts_in-volts_out)/coil_uH)*fall_time + coil_amps

Mangle this to:

fall_time= L_Ipeak/(Volts_out-Volts_in)

where: L_Ipeak=coil_uH*coil_amps

L_Ipeak is a constant already used in the firmware (see firmware section). Volts_in is already calculated to determine the inductor on-time. Volts_out is a known constant (5/USB or 12/Firewire). This should work for all positive values of V_out-V_in. If you get negative values, you have bigger troubles! All equations are calculated in the helper spreadsheet included with the NIXIE smps instructable.

The following line was added to the constants section of the firmware described in the CALIBRATION step:

const v_out as byte=5 'output voltage to determine off-time
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
128
Followers
30
Author:ian(DangerousPrototypes.com)