Panteltje's power_pic page

Panteltje's power_pic page


A Microchip 16F690 PIC as universal PWM controller for power supply applications

Current version is 0.3

Here you find the source code for a Microchip 16F690 PIC assembler program that makes that chip behave like an universal switchmode controller with LCD display.
The LCD displays time, output voltage setpoint, output voltage, output current, and output Watts.
The output voltage can be controlled via a 19200 baud, 8 data bits, 1 stop bit, serial link.
Via the same link a number of basic parameters can be set depending on the application, these parameters are stored on chip in EEPROM.
Among these are: maximum PWM cycle, soft-start speed, local (potentiometer) - or remote voltage control, clock speed.
So the serial link is no longer essential once those parameters are set, but can be used to set the output voltage and time.
It is the responsibility of the user to set the correct parameters before using the PIC to drive any power electronics.

Very few external components are needed to make a working switchmode supply, and the chip uses the internal oscillator elimination the need for a crystal.

Theory of operation:
The PIC hardware PWM generator is used to create a pulse with controlled positive duration and a fixed frequency.
The PIC hardware comparator1 is used to compare the voltage from a current transformer to a preset DC reference.
The PIC hardware comparator2 is used to compare the voltage of the output to either an on chip reference (controlled via the serial ink) or an external reference set by for example a potentiometer.
Both PIC comparators control the PWM pulse in real time, and wil stop the positive pulse if the comparators see a level higher then their reference.

For this reason the current and voltage control is in real time, and not software dependent, other then the initialisation of the chip

No interrupts or routines in the main code are involved in the control of the output voltage or current.
The only thing used is a clock tick that slowly increments the PWM at start up (speed selectable via the serial ink).
The 3 ADC channels are read in the main routine and _only_ used for the LCD display, that display simply functions as a volt and current meter.

Here is a example diagram that uses power_pic to make a SEPIC converter that makes 0-24V DC voltage from a 12V input voltage,
it has cycle by cycle current limit, and uses a hysteretic type voltage control, resulting in a short circuit - and overload protected design with good stability.

Here the power_pic drives a 2 x 16 line LCD character display, showing output voltage and output current, as well as output Watts, time, and input voltage.
The LCD display is not needed to use power PIC as an universal replacement for a PWM power regulator chip.
The output power in this example is now close to 60 W in 12 V (car headlight as load).
This works at 19 kHz, as well as 77 kHz, with the components I use.
I also tried an IRFZ44A MOSFET with a discrete gate driver circuit running from 12 V DC, with about the same result, that one can do a bit more power.

Some notes to the diagram:

The current setting in the asm file is for 76.92 kHz PWM frequency, if you want a higher or lower frequency look for 'PWM frequency' in the asm source, and select one.
The series resistor in the gate of the MOSFET is now 0 Ohm, it was 22 Ohm, it reduced HF oscillations.
The HF oscillation can be strongly decreased by keeping the wire to the gate close to the drain wire, 'neutrodisation'.
As this is version 0.3, and things are constantly changing, I thought it was better to release the code then to sit on it until it was perfect.
For this reason the current measurement for the LCD is connected to ground, have not decided yet to either use a shunt and an opamp, or use a Hall effect based module to sense current.
The above setup did > 55 W output into a car headlight, at that level the MOSFET gets hot.
The MOSFET drive could be improved.
One can use a 1:1 transformer in place of the toroids, if it has sufficient current handling capability.

Current trip (limit):
The voltage divider on pin 19 sets the reference for the PIC hardware comparator1 that sees the output of the current transformer on the other input (pin 15).
You can make a variable current limit by using a potentiometer here.
Please check the polarity of the sawtooth coming from the current transformer, it must be positive.
Failure to do so will lead to destruction of the circuit, as the most important thing in the whole circuit as far as protection is concerned, is the cycle by cycle current limit.

Output voltage:
You can set the output voltage via RS232 with command 'U' in this version, it uses the internal on chip reference divider, with the correct resistor values 0-15 will result in about 0-15 volt.
Typing 'L' will transfer voltage control back to local, then the voltage reference is set by either a resistor divider or potentiometer on pin 16.
The resistor network on pin 14 is on the other input of the PIC hardware comparator2.

All this will then give manual control of voltage and current limit, and also allow you to select one of 15 output voltages via the serial link.
Sending command 'L' via the serial link will switch voltage control to manual, the potentiometer.
Use your imagination to add features.
Work in progress, some commands are bound to change, maybe even the functions on some pin.
The diagram needs updating, for pin connections see the asm source.

The asm file for a PIC 16F690, plus wiring instructions for the PIC are included in the asm source:
Click here to download pwr-0.3.asm.

Here is a simple terminal program (Linux) that by default will work with power_pic, and also can be called from a script:
Click here to download ptlrc-0.3.tgz.

I have build the circuit in a box now, modified it a bit, added a shunt to measure current, and a LM324 to amplify the voltage over the shunt:
click here for power_box_diagram (big)

The PCB top:

The PCB bottom:

The box:

The asm source for this: pwr-box.asm

Click here for other available programs released under the GPL license.