Here is the simple PIC12f508 code.
;INTERNAL OSC, INTERNAL MCLR, POWER UP TIMER ON
LIST R=DEC
LIST P=PIC12F508
;INCLUDE REGISTER DEFINITIONS
INCLUDE P12F508.INC
;_MCLRE_ON EQU H'0FFF'
;_MCLRE_OFF EQU H'0FEF'
;_CP_ON EQU H'0FF7'
;_CP_OFF EQU H'0FFF'
;_WDT_ON EQU H'0FFF'
;_WDT_OFF EQU H'0FFB'
;_LP_OSC EQU H'0FFC'
;_XT_OSC EQU H'0FFD'
;_IntRC_OSC EQU H'0FFE'
;_ExtRC_OSC EQU H'0FFF'
__CONFIG _MCLRE_OFF & _WDT_ON & _CP_OFF & _IntRC_OSC
INCLUDE MACRO.ASM
;ACCESSES REGISTER BANK BIT
#DEFINE RB0 STATUS,5
;
#DEFINE FEEDBACK GPIO,0 ;12 VOLT FEEDBACL
#DEFINE MOSFET GPIO,1 ;MOSFET 1=ON
STATEA EQU 1
FIRSTA EQU 0
FIRSTB EQU 0
;***********************
FIRSTRAM EQU 7 ;JUST POINTER TO FIRST RAM LOCATION
DEL1 EQU 7
DEL2 EQU 8
DEL3 EQU 9
COUNTL EQU 10
COUNTH EQU 11
TEMP EQU 12
LASTRAM EQU 1FH
;;;;;;;;;;;;;;;;;;;;;
ORG 0
;SETUP PICI/O AND OPTIONS
MOVLW FIRSTA
MOVWF GPIO
CLRWDT
MOVLW STATEA
TRIS GPIO
MOVLW 0C0H ;WEAK PULL UPS OFF & WAKE UP ON PIN CHANGE OFF
OPTION
;;;;;;;;;;;
;POWER UP DELAY
CALL WAIT1MS
MLOOP CLRWDT
BTFSC FEEDBACK
GOTO MLOOP ;DO NOWT OF OVER 12 VOLTS.
BSF MOSFET ;MOSFET ON
MOVLW 33 ;WAIT 100US
MOVWF TEMP
TIME CLRWDT
DECFSZ TEMP,F
GOTO TIME
BCF MOSFET ;MOSFET OFF
;MUST HAVE MOSFET OFF TIME FOR INDUCTOR TO RECOVER.
MOVLW 33
MOVWF TEMP
TIME2 CLRWDT
DECFSZ TEMP,F
GOTO TIME2
GOTO MLOOP
;********************
WAIT1MS MOVLW 1
GOTO MSS
MS250 MOVLW 250
MSS MOVWF DEL1
MS MOVLW 249
MOVWF DEL2
DD CLRWDT
DECFSZ DEL2,F
GOTO DD
DECFSZ DEL1,F
GOTO MS
RETLW 0
;***********************
;INTERNAL OSC, INTERNAL MCLR, POWER UP TIMER ON
LIST R=DEC
LIST P=PIC12F508
;INCLUDE REGISTER DEFINITIONS
INCLUDE P12F508.INC
;_MCLRE_ON EQU H'0FFF'
;_MCLRE_OFF EQU H'0FEF'
;_CP_ON EQU H'0FF7'
;_CP_OFF EQU H'0FFF'
;_WDT_ON EQU H'0FFF'
;_WDT_OFF EQU H'0FFB'
;_LP_OSC EQU H'0FFC'
;_XT_OSC EQU H'0FFD'
;_IntRC_OSC EQU H'0FFE'
;_ExtRC_OSC EQU H'0FFF'
__CONFIG _MCLRE_OFF & _WDT_ON & _CP_OFF & _IntRC_OSC
INCLUDE MACRO.ASM
;ACCESSES REGISTER BANK BIT
#DEFINE RB0 STATUS,5
;
#DEFINE FEEDBACK GPIO,0 ;12 VOLT FEEDBACL
#DEFINE MOSFET GPIO,1 ;MOSFET 1=ON
STATEA EQU 1
FIRSTA EQU 0
FIRSTB EQU 0
;***********************
FIRSTRAM EQU 7 ;JUST POINTER TO FIRST RAM LOCATION
DEL1 EQU 7
DEL2 EQU 8
DEL3 EQU 9
COUNTL EQU 10
COUNTH EQU 11
TEMP EQU 12
LASTRAM EQU 1FH
;;;;;;;;;;;;;;;;;;;;;
ORG 0
;SETUP PICI/O AND OPTIONS
MOVLW FIRSTA
MOVWF GPIO
CLRWDT
MOVLW STATEA
TRIS GPIO
MOVLW 0C0H ;WEAK PULL UPS OFF & WAKE UP ON PIN CHANGE OFF
OPTION
;;;;;;;;;;;
;POWER UP DELAY
CALL WAIT1MS
MLOOP CLRWDT
BTFSC FEEDBACK
GOTO MLOOP ;DO NOWT OF OVER 12 VOLTS.
BSF MOSFET ;MOSFET ON
MOVLW 33 ;WAIT 100US
MOVWF TEMP
TIME CLRWDT
DECFSZ TEMP,F
GOTO TIME
BCF MOSFET ;MOSFET OFF
;MUST HAVE MOSFET OFF TIME FOR INDUCTOR TO RECOVER.
MOVLW 33
MOVWF TEMP
TIME2 CLRWDT
DECFSZ TEMP,F
GOTO TIME2
GOTO MLOOP
;********************
WAIT1MS MOVLW 1
GOTO MSS
MS250 MOVLW 250
MSS MOVWF DEL1
MS MOVLW 249
MOVWF DEL2
DD CLRWDT
DECFSZ DEL2,F
GOTO DD
DECFSZ DEL1,F
GOTO MS
RETLW 0
;***********************
Any reason not to use a switchmode IC such as UC3843 or similar?
I recommend running faster than 20 kHz. Otherwise, you'll hear your magnetic components whine quite clearly. I also recommend using a buck or buck/boost topology. It looks like you're running very high peak currents through the mosfet and zener diode. I don't think that's good for the reliability of those components.
Or better yet... Leave the design effort to the pros and go with one of National Semiconductors' SimpleSwitchers. On some ICs all you need is a resistor network and a couple of caps. On others, you have to supply an inductor and a diode as well. It's not rocket science, but it is slightly more cumbersome than the average linear regulator design.
If you don't need a high output power, something like the cheapo flyback supply described by Dwaine Reid in Electronic Design April 8, 2010. "Build Your Own Ultra-Low-Cost Isolated DC-DC Converter" would work. You should be able to get to the article through a google search (or go to Electronic Design directly).
~Tom
I recommend running faster than 20 kHz. Otherwise, you'll hear your magnetic components whine quite clearly. I also recommend using a buck or buck/boost topology. It looks like you're running very high peak currents through the mosfet and zener diode. I don't think that's good for the reliability of those components.
Or better yet... Leave the design effort to the pros and go with one of National Semiconductors' SimpleSwitchers. On some ICs all you need is a resistor network and a couple of caps. On others, you have to supply an inductor and a diode as well. It's not rocket science, but it is slightly more cumbersome than the average linear regulator design.
If you don't need a high output power, something like the cheapo flyback supply described by Dwaine Reid in Electronic Design April 8, 2010. "Build Your Own Ultra-Low-Cost Isolated DC-DC Converter" would work. You should be able to get to the article through a google search (or go to Electronic Design directly).
~Tom
Any reason not to use a switchmode IC such as UC3843 or similar?
~Tom
The main problem seems to be the amount of extra components needed.
I can use an 8 pin PIC that is around 60p.
The zener is just a fast diode, used wrong part from library.
The inductor is 70p.
The P channel MOSFET can be a cheap part.
The circuit relies on a PIC input threshold of 2 volts, so all I have to do is scale the feedback voltage for the PIC.
I have used the watchdog on the PIC in case of failure sending 35 volts to the 12 volt supply.
Both this and the Electronic Design article are dead simple. but I can see "possibilities" where such a low-cost design could have a lit more features.
But yeah, two loops to make a fixed width rectangular wave is awfully basic - the PIC might as well be a 555 timer chip.
First off, I'd go to C rather than assembly - embedded C compilers are pretty darn good thesedays, and they're available for every microcontoller, usually from at least three sources - the manufacturer, third parties such as IAR, and freeware/GCC versions. Even "pay" versions have free eval code-limited versions with the limitation way above the code needed for this. If you don't know C, it's worth learning.
Dunno what 60p is in USD, but TI has microcontrollers starting at USD $0.25:
MSP430 Value Line - TI.com
and projecting from the 1k cost, one with a 10-bit A/D is less than twice that. That's what I'd use to read the output voltage for feedback.
I've wondered why switching regulator chips seem to be relatively expensive (several US dollars each) when the parts for something like this are so cheap, but I recall using a LT1072 many years ago, and such chips have features that would take a good deal of design, coding and fine-tuning time to build into a microcontroller-controlled SMPS.
OTOH, there does seem to be a bit of info out there:
microcontroller SMPS - Google Search
But yeah, two loops to make a fixed width rectangular wave is awfully basic - the PIC might as well be a 555 timer chip.
First off, I'd go to C rather than assembly - embedded C compilers are pretty darn good thesedays, and they're available for every microcontoller, usually from at least three sources - the manufacturer, third parties such as IAR, and freeware/GCC versions. Even "pay" versions have free eval code-limited versions with the limitation way above the code needed for this. If you don't know C, it's worth learning.
Dunno what 60p is in USD, but TI has microcontrollers starting at USD $0.25:
MSP430 Value Line - TI.com
and projecting from the 1k cost, one with a 10-bit A/D is less than twice that. That's what I'd use to read the output voltage for feedback.
I've wondered why switching regulator chips seem to be relatively expensive (several US dollars each) when the parts for something like this are so cheap, but I recall using a LT1072 many years ago, and such chips have features that would take a good deal of design, coding and fine-tuning time to build into a microcontroller-controlled SMPS.
OTOH, there does seem to be a bit of info out there:
microcontroller SMPS - Google Search
Cool project, had plan to do one myself with PIC
you made the code?
But I have to say I DO NOT like assembler 🙁
you made the code?
But I have to say I DO NOT like assembler 🙁
It's a bit hard to read the schematic. I've redrawn it to make it a bit more comprehensible. Is this what you've got?
View attachment 193762
w
That looks correct.
It is just a first fraft.
I used to use a PWM controller in my previous job :
Microchip dsPIC33FJ12MC201
IT's a motor control PIC with several PWM channels and ADC/DACs...It does what you want - and only $1.80, IIRC! You can write to it in C, and the free IDEs are great. MPLAB!
Microchip dsPIC33FJ12MC201
IT's a motor control PIC with several PWM channels and ADC/DACs...It does what you want - and only $1.80, IIRC! You can write to it in C, and the free IDEs are great. MPLAB!
It's a bit hard to read the schematic. I've redrawn it to make it a bit more comprehensible. Is this what you've got?
View attachment 193762
w
THANK YOU!!! Now that the resistors are drawn as resistors and not transmission lines, the inductors as inductors and not resistors, I do recognize that it is indeed a buck regulator. Fantastic.
The main problem seems to be the amount of extra components needed.
What extra components? A UC184x-series controller would require 3~4 $0.03 passive components in addition to what you have. In return, you get a power supply with load regulation, line regulation, and low temperature coefficient. You don't have to use the current mode control. Just ground the current sense input and you have regular voltage mode control.
There are less expensive options out there. SG3524 comes to mind.
The circuit relies on a PIC input threshold of 2 volts, so all I have to do is scale the feedback voltage for the PIC.
So your reference voltage is purely the threshold voltage of a logic gate?! First of all, that voltage is not guaranteed by the manufacturer. Sure, they may have min/max limits, but they're typically fairly loose. Secondly, the threshold voltage will vary with process (i.e. lot-to-lot variation), temperature, power supply voltage, loading, and a whole slew of other things. In addition, operating a logic gate at the threshold voltage will cause the gate to chatter and draw high supply current. Think of an inverter where both the NMOS and PMOS are on at the same time. That's what you have going on.
You may be able to get it to work on one prototype. But try building two of them and measure the difference. I'm also curious to see your Vout vs Iload and Vout vs Vin plots... 🙂 Especially over temperature...
If you insist on using the PIC, I strongly strongly suggest that you use one with an A/D converter. Write the code to drive the switch with a pulse width modulator (remember to use double-buffering). Make a real control system where the PWM pulse width is inversely proportional to the ADC value. This could lead to some learnings about how control systems work. Mess with the gain - i.e. the constant of proportionality between the PWM pulse width and ADC code.
Just remember to limit the PWM pulse width to something less than 100 %.
Yes, I learned about the double buffering and pulse width limit the hard way doing a project much similar to yours. Except mine used a 555 to generate a ramp and a dual opamp as comparator and error amplifier. It worked well. That was back in the day when uC's with built-in ADCs were $15 and came in 64-pin PLCC packages... 🙂
~Tom
But yeah, two loops to make a fixed width rectangular wave is awfully basic - the PIC might as well be a 555 timer chip.
The PIC does a bit more than supply a 10KHz pulse.
It only supplies the pulse if the output is less than 12 volts.
A PIC input threshold is 2 volts and this is used for a comparator to measure the output volts.
Finally got around to building the PIC SMPS.
There is a problem with the PIC input pins as they have hysteresis on them.
This causes a step in the output voltage.
I have ordered a PIC12F510 which has an A2D on board, this should fix the problem.
There is a problem with the PIC input pins as they have hysteresis on them.
This causes a step in the output voltage.
I have ordered a PIC12F510 which has an A2D on board, this should fix the problem.
I wondered if you got this going.
Why not just put in a comparator (opamp), which you probably have lying around?
w
Why not just put in a comparator (opamp), which you probably have lying around?
w
I strongly suggest using proportional control rather than on/off control for controlling the pulse width of the switch drive. A comparator has way too much gain at the switching transition. This high gain in your control loop will make the system unstable and you'll end up with huge voltage ripple (best case) or complete lack of control of the output voltage (worst case).
~Tom
~Tom
I wondered if you got this going.
Why not just put in a comparator (opamp), which you probably have lying around?
w
You can buy PIC's with comparators in anyway. I just chose to use an ADC as it doesnt cost any more.
I strongly suggest using proportional control rather than on/off control for controlling the pulse width of the switch drive. A comparator has way too much gain at the switching transition. This high gain in your control loop will make the system unstable and you'll end up with huge voltage ripple (best case) or complete lack of control of the output voltage (worst case).
~Tom
The PIC only outputs a single pulse if the voltage is below 12 volts.
This is a tiny amount of charge. The gain is very low but it still reacts very quickly to change.
The pulses are very short, 50KHz.
I had considered a PID technique but this involves so many calculations the PIC would never keep up.
Last edited:
I strongly suggest using proportional control rather than on/off control for controlling the pulse width of the switch drive. A comparator has way too much gain at the switching transition. This high gain in your control loop will make the system unstable and you'll end up with huge voltage ripple (best case) or complete lack of control of the output voltage (worst case).
~Tom
You can buy PIC's with comparators in anyway. I just chose to use an ADC as it doesnt cost any more.
I didn't suggest it on the basis of cost, or that it was ideal. I suggested it on the basis of probable availability for for a solution to the hysteresis for a bit of messing around at midnight on a Sunday evening.
You may be able to get it to work on one prototype. But try building two of them and measure the difference. I'm also curious to see your Vout vs Iload and Vout vs Vin plots... 🙂 Especially over temperature...
w
The PIC only outputs a single pulse if the voltage is below 12 volts.
This is a tiny amount of charge. The gain is very low but it still reacts very quickly to change.
The pulses are very short, 50KHz.
I had considered a PID technique but this involves so many calculations the PIC would never keep up.
What are you writing in, QBasic?! PID is the second simplest control method in all of digital design.
Tim
- Status
- Not open for further replies.
- Home
- Amplifiers
- Power Supplies
- Simple SMPS using 8 pin PIC microcontroller.