If the frequency needs to be accurate you would be much better off using a timer interrupt.
If the frequency needs to be accurate you would be much better off using a timer interrupt.
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Hi,
as the Holy Manual states ...
min PAUSEUS @ 4 Mhz is ... 19µs ...
soooo .... toobad !
Now, for this " universal IR Tx " ...the use of a Xtal looks compulsory !
Alain
PS: an assembler stubb would be useful here ...
Code:;------------------------------------------------------------- ; Code generated by PDEL ver 1.0 on 23/04/2010 at 09:01:45 ; Description: Waits 13 cycles ;------------------------------------------------------------- PDelay movlw .2 ; 1 set number of repetitions movwf PDel0 ; 1 | PLoop0 clrwdt ; 1 clear watchdog decfsz PDel0, 1 ; 1 + (1) is the time over? goto PLoop0 ; 2 no, loop return ; 2+2 Done ;------------------------------------------------------------- Code requirements ----------------- - Declaration of PDel0 (register) - 1 stack level Example of use -------------- call PDelay ; Delay 13 cycles (including call+return)
Last edited by Acetronics2; - 23rd April 2010 at 08:02.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
http://www.rentron.com/Infrared_Communication.htm
Code:PROCESSOR 12c508 #include "p12c508.inc" __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC #DEFINE PORT B'11111101' MOVF OSCCAL MOVLW PORT TRIS GPIO BEGIN BCF GPIO, 1 ;1uS NOP ;2uS each nop is 1uS long NOP ;3uS NOP ;4uS NOP ;5uS NOP ;6uS NOP ;7uS NOP ;8uS NOP ;9uS NOP ;10uS NOP ;11uS NOP ;12uS NOP ;13uS NOP ;14uS NOP ;15uS NOP ;16uS NOP ;17uS NOP ;18uS NOP ;19uS BSF GPIO, 1 ;1uS Begin HIGH duty cycle NOP ;2uS NOP ;3uS NOP ;4uS NOP ;5uS GOTO BEGIN ;2uS (26uS total for 38KHz) END
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Something like this is easier with PBP.
This is in an include file;
Create one for whatever IR carrier freq you need, and just call them like this with PBP;Code:' IR carrier generator routines. Freq.inc. Cycles VAR BYTE ' Number of carrier cycles GOTO OverFreq ' jump over pulse routines ' Generate "Cycles" number of 40kHz pulses ASM _Pulse40 bcf IRTX,PIN ; 1uS, LED=on goto $+1 ; + 2uS = 3uS goto $+1 ; + 2uS = 5uS goto $+1 ; + 2uS = 7uS goto $+1 ; + 2uS = 9uS goto $+1 ; + 2uS = 11uS goto $+1 ; + 2uS = 13uS bsf IRTX,PIN ; 1uS, LED=on goto $+1 ; + 2uS = 3uS goto $+1 ; + 2uS = 5uS goto $+1 ; + 2uS = 7uS goto $+1 ; + 2uS = 9uS decfsz _Cycles,f ; + 1uS = 10S goto _Pulse40 ; + 2uS = 12uS return ; Return to caller ENDASM ' Generate "Cycles" number of ~38.4kHz pulses ASM _Pulse38 bcf IRTX,PIN ; 1uS, LED=on goto $+1 ; + 2uS = 3uS goto $+1 ; + 2uS = 5uS goto $+1 ; + 2uS = 7uS goto $+1 ; + 2uS = 9uS goto $+1 ; + 2uS = 11uS goto $+1 ; + 2uS = 13uS bsf IRTX,PIN ; 1uS, LED=on goto $+1 ; + 2uS = 3uS goto $+1 ; + 2uS = 5uS goto $+1 ; + 2uS = 7uS goto $+1 ; + 2uS = 9uS nop ; + 1uS = 10uS decfsz _Cycles,f ; + 1uS = 11S goto _Pulse38 ; + 2uS = 13uS return ; Return to caller ENDASM OverFreq:
At 4MHz you won't be spot-on for every carrier frequency, but it will be close enough to work with pretty much any off-the-shelf IR receiver.Code:@ #define IRTX GPIO ; Define port to use for IR out @ #define PIN 2 ; Define port pin to use for IR out INCLUDE "Freq.inc" ' GPIO.2 = 1 ' IR LED off -----|<|----/\/\/\----+5 TRISIO.2 = 0 ' Output for IR signal CMCON = 7 ' Comparators disabled ANSEL = 0 ' A/D disabled Main: Cycles = 60 ' min 1, max 255 CALL Pulse38 GOTO Main END
Have you considered using an 8-pin 12F683 and generating a 38-KHz PWM signal output in the background? Use a interval counter and turn the PWM output on or off at the correct intervals by setting the CCPR1L duty cycle register to 50% or 0%.
Regards, Mike
Last edited by Mike, K8LH; - 23rd April 2010 at 18:12.
Bookmarks