pwm generator with a variable duty cycle pic16f877

Status
Not open for further replies.

wewee

New Member
hello , can u give me the source code in assembly language for a pwm genrator using pic 16f877 ??
it should be with a variable duty cycle , the duty cycle can be changed with a potentiometer at the input (analog to digital converter)
the frequency of the pwm is 10Khz
thanks
 
You can use the Capture/Compare/PWM module. The duty cycle is proportional to CCPR1L.
 
You can use the Capture/Compare/PWM module. The duty cycle is proportional to CCPR1L.


i have managed to write this , it's a simple pwm generator
however it's not working , i have tried it on ISIS


i have set the prescaler of timer 2 on 1
oscillator on 4 MHz
pr2 = 99 (so the frequency would be 10Khz)
CCPR1L:CCP1CON<5,4> = 0011001000 (for the duty cycle to be 50%)

____________________________________________________________________

; oscillator : 4 mHZ



#include <p16f877A.inc>
;***declare registeraion

__config 3fC4
ORG 0X00
GOTO MAIN
ORG 0X04
RETFIE
code
MAIN

BCF STATUS,RP0
CLRF PORTA ;clear content of port A
CLRF PORTB ;clear content of port B
CLRF PORTC ;clear content of port C
BSF STATUS,RP0 ;change to bank 1
MOVLW B'11111111'
MOVWF TRISA ;set port A as input
CLRF TRISB ;set port B as output
CLRF TRISC

movlw B'01100011' ; period = 0.0001 seconds
movwf PR2
bcf STATUS,RP0
movlw B'00110010' ; setting the duty cycle time to 50% or 0.00005 seconds
movwf CCPR1L
bcf CCP1CON,5
bcf CCP1CON,4
bsf STATUS,RP0
bcf TRISC,2 ; pin 2 of port c is an output
bcf STATUS,RP0
movlw B'00000100'
movwf T2CON ; prescale =1 , timer2 is on
bsf CCP1CON,3 ;configuring CCP1 module for PWM operation
bsf CCP1CON,2


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