
Originally Posted by
madxice
Hello everybody,
I am trying to make buck converter and control it with 16f877. The logic is simple. If the output voltage of the buck is higher than reference voltage the pwm duty cycle will decrease, if the output voltage is lower than the reference the duty cycle will increase. It seems very simple, but I couldn't be able to write the program

I write but i doesn't work. I am new at pic programming. Help me please!!!
My crystal is 20MHz.
And it gives an error " ADC conversion clock period (1e-7) is possible invalid for device clock frequency" in proteus simulation.
Code:
DEFINE OSC 20
DEFINE ADC_BITS 8
DEFINE ADC_SAMPLES 50
TRISA=%00000011
TRISB=00
TRISC=00
TRISD=00
TRISE=00
Reference var byte
Voltage var byte
CCP1CON=%000011100
CCP2CON=%000011100
T2CON=%00000101 'timer 2 on, 1:1 postscale, 1:4 prescale
PR2= 49
CCPR1L=%00011001
get_reference:
ADCON1=%00000000
' Set LEFT Justification
' Enable ALL ADC's (using PIC16F87x as example)
ADCON0=%11000001
' Set ADC Channel 0 (RA0/AN0)
' Enable ADC Module
PauseUS 50
' 50uS Pause to allow sampling Capacitor to charge
ADCON0.1=1
' Start Conversion
While ADCON0.1=1:Wend
' Wait for conversion to complete
Reference=ADRESH
' Read 8-bit Result
return
get_voltage:
ADCON0=%11001001
' Set Fosc/32
' Set ADC Channel 1 (RA1/AN1)
' Enable ADC Module
PauseUS 50
ADCON0.1=1
While ADCON0.1=1:Wend
Voltage=ADRESH
return
azalt:
CCPR1L=CCPR1L-1
return
arttir:
CCPR1L=CCPR1L+1
return
sabit:
CCPR1L=CCPR1L
return
main_loop:
Gosub get_Reference ' Get reference value
Gosub get_voltage ' Get voltage value
if Reference>Voltage then azalt
if Reference< Voltage then arttir
IF Reference=Voltage then sabit
goto main_loop ' Do it forever
end
I do not know how or if it will affect your code, but I did notice your CCP1CON and CCP2CON register settings have 9 bits.
Last edited by Archangel; - 24th December 2008 at 06:59.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks