avinashnp007
Newbie level 3
i have to generate a pwm using ccp module from an analog signal varying between 0-5volt. i have combined adc and ccp programs... there is a problem wen i checked it in proteus... e.g if i give 2.5 volt, i will get 50%duty cycle, but after that if i change voltage to 1.25volt, i am not getting 25%duty cycle... if i reset , then i will get 25%. that means progrm is stuck in some loop... here is the program... plz help...
Code:
LIST P=PIC18F452, F=INHX32, N=0, ST=OFF, R=HEX
#include P18F452.INC
CONFIG OSC=HS, OSCS=OFF
CONFIG WDT=OFF
CONFIG BORV=45, PWRT=ON, BOR=ON
CONFIG DEBUG=OFF, LVP=OFF, STVR=OFF
COUNT EQU 25
ORG 00H
CLRF TRISC
CLRF TRISD
BSF TRISA,0
MOVLW 0X81 ;Fosc/64,channel 0,A/D on
MOVWF ADCON0
MOVLW 0X4E ;left justified,Fosc/64,AN0=analog
MOVWF ADCON1
OVER CALL DELAY
BSF ADCON0,GO
BACK BTFSC ADCON0,DONE
BRA BACK
MOVFF ADRESL,PORTC
MOVFF ADRESH,PORTD
CALL DELAY
BRA OVER
DELAY MOVLW 35
MOVWF COUNT
AGAIN DECFSZ COUNT
BRA AGAIN
RETURN
CLRF CCP1CON ;16Mhz xtal, 4Khz pwm
MOVLW D'249'
MOVWF PR2
MOVFF PORTD,CCPR1L ;digital output moved to ccpr1l
BCF TRISC,CCP1
MOVLW 0X01
MOVWF T2CON ;prescalar 4
MOVLW 0X0C
MOVWF CCP1CON ;decimal neglected,pwm option
CLRF TMR2
BSF T2CON,TMR2ON
REPEAT BCF PIR1,TMR2IF
LOOP BTFSS PIR1,TMR2IF
BRA LOOP
GOTO REPEAT
END
Last edited by a moderator: