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.

need code which generate ir 38khz pwm using pic 12f675

Status
Not open for further replies.

HARIS RASHID

Newbie level 4
Joined
Jul 19, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
hi
i need code which generate ir 38 khz pwm using pic12f675
 

hi
i need code which generate ir 38 khz pwm using pic12f675
You do not normally need PWM for 38KHz IR, just square waves.

This should do it:

Code:
;IRTX - use MPASM in relocatable mode

#include	p12f675.inc		;with analogue

	__CONFIG	0x0184
	errorlevel	-302		;prevent bank select warnings

#define	irout		GPIO,4	;pic pin 3 infra red output

;12f675 ram 20 to 5f hex
	udata_shr
timer1	res 1   	;shared by delay routines
timer2	res 1   	;shared by delay routines
timer3  res 1		;shared by delay routines
	
    code 	0		;reset vector

;initilisation starts here
start
	bcf		STATUS,RP0		;bank 0
	clrf	GPIO			;init GPIO
	movlw	0x0f			;set I/O bits
	movwf	CMCON			;digital I/O
	bsf		STATUS,RP0		;bank1
	clrf	ANSEL			;digital I/O (pic12f675 only)
	movlw	0x2a			;set I/O bits, 1=input
	movwf	TRISIO			;note GP3 pin4 can only be input
	movlw	0x28			;set weak pullup bits
	movwf	WPU
	bsf		OPTION_REG,7	;allow weak pullups

	bcf		STATUS,RP0		;bank 0
	bcf		irout			;be sure to turn off IR to prevent burnout

;tx test loop
tloop
	movlw	d'175'	;4.5ms mark
	call	pulse_ir_w
	movlw	d'163'	;4.5ms space
	call	wait_ir_w
    goto    tloop

; send w pulses of 38 Khz to IR LED
pulse_ir_w
	movwf	timer3		;save the value
	movwf	timer2
pulse_loop
	bsf		irout		;IR on
	movlw	0x02
	movwf	timer1
pulse1
	decfsz	timer1,F	;.2us of 26ms
	goto	pulse1		;.2us
	nop
	nop
	nop
	bcf		irout		;IR off
	movlw	0x04
	movwf	timer1
pulse2
	decfsz	timer1,F
	goto	pulse2
	decfsz	timer2,F
	goto	pulse_loop	;loop w times

	movfw	timer3		;restore the value
	return

;wait w times 38 KHz - no output, but same code as above to get same timing
wait_ir_w
	movwf	timer3		;save the value
	movwf	timer2
wait_loop
	bcf		irout		;IR off
	movlw	0x02
	movwf	timer1
wait1
	decfsz	timer1,F
	goto	wait1
	nop
	nop
	nop
	nop
	bcf		irout		;IR off
	movlw	0x04
	movwf	timer1
wait2
	decfsz	timer1,F
	goto	wait2
	decfsz	timer2,F
	goto	wait_loop	;loop w times

	movfw	timer3		;restore the value
	return


	end
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top