PWM on PIC16F876A

Status
Not open for further replies.

sololf21

New Member
hi guys, i reali hope someone would help me with my code... my idea is to create a frequency with the specified duty cycle so as to show tat my boost dc-dc is switching to the correct output voltage. i tried to build the code but it shows some error... could someone shed some light pls... thanks in advance...

my specifications as below
input voltage - 18V
output voltage - 24V
switching frequency - 50kHz
duty cycle - 25%

my code:
*****************************************
#INCLUDE "P16F876A.INC"

ORG 0x00


BCF STATUS,5
bcf status,6
; clrf portc
; movlw h'02',portc ; sets RC2 to output
MOVLW h'04' ;LOAD THE PR2 VALUE, switching freq set to 50kHz, PR2 set to 4
MOVWF PR2 ;TO THE PR2 REGISTER
;BCF STATUS,5

MOVF h'10',W ; setup DC for bit 8-9
MOVWF CCP1CON ; put 10h to CCP1CON REGISTER

MOVF h'01',W ; setup DC for bit 0-7
MOVWF CCPR1L ; put 01h to THE CCPR1L register

bsf status,5 ; switch to bank 1
bcf TRISC,2 ; make the CCP1 pin an output by clearing the TRISC<2> bit

bcf status,5 ; switch back to bank 1
MOVLW 01h ; LOAD THE PRESCALER with 4
MOVWF T2CON ; OF TMR2
BSF T2CON,2 ; TURN ON TIMER2

end
******************************************

zenia
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…