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 programI 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 write but i doesn't work. I am new at pic programming. Help me please!!!


Bookmarks