Electronic – PWM generation PIC16F628A

microcontrollerpicpwm

I have followed the instructions in the data sheet and tried to generate PWM signal using PIC16F628A. However it seems to be not generating any output. My code is shown below. Any help appreciated regarding finding the what is wrong in my code.

Thank you.

PROCESSOR '16F628A'
INCLUDE <P16F628A.INC>
org 0x00
bcf STATUS,RP1
bsf STATUS,RP0 ; go to bank1

movlw 0xff ;255 dec
movwf PR2 ; writing to PR2 register
bcf TRISB,3 ; set RB3 as output


bcf STATUS,RP0 ; go to bank0
bcf CCP1CON,5 ; clearing bits 5 and 4
bcf CCP1CON,4

movlw 0x00
movwf CCPR1L ; set duty cycle

bcf T2CON,1
bcf T2CON,0 ; set pre-scaler to 1
bsf T2CON,2 ; enable Timer2
bsf CCP1CON,3 
bsf CCP1CON,2 ; enable pwm mode
return
end

Best Answer

movlw 0x00
movwf CCPR1L ; set duty cycle

Are you always just setting the duty cycle to 0? Is the output pin always low? Everything else looks good. Just try changing this number and see if you get any results.

Related Topic