Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pwm generation depending on analog input

Status
Not open for further replies.

avinashnp007

Newbie level 3
Newbie level 3
Joined
Aug 20, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
27
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:

Don't understand your programming language, BUT you have a repeat. ...... then a goto repeat, so it repeats the generator but not looking for a new input, point the goto (urh!) to a point before the analogue is read.
Frank (FORTRAN 77)
 

yes i had returned control to the start of the program where analog input can b fetched... here it is
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
	

	    	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
 		BCF PIR1,TMR2IF
LOOP    	BTFSS PIR1,TMR2IF
		BRA LOOP
				  

DELAY   
		MOVLW 35
	   	MOVWF COUNT
AGAIN		DECFSZ COUNT
	    	BRA AGAIN	
	    	RETURN	
	    	CALL DELAY
		BRA OVER

			  END
- - - Updated - - -

still the pulses go more distorted...
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top