BEGIN CLRF PORTB
WAITHI BTFSS PORTA,0
GOTO WAITHI
CLRF TMR0 ;START TMR0
TESTST BTFSC PORTA,0
GOTO TESTST
MOVF TMR0,W ;READ TMR0 INTO W SUBLW .148
BTFSC STATUS,CARRY
GOTO WAITHI
i'm using a 4Mhz cystal and the prescaler is 1:1
do anyone know how to calculate the value for .148
the answer should approximate to 7ms ?
can anyone provide me the formula and calculation??
thxs
actually i'm doing an infrared program, the coding above is the receiver part whic has to decode the data which transmited from the transmitter side
they is a start bit = 7.5ms , logic 1 = 5ms and logic 0 = 2.5ms
the coding above will measure the pulse width and subtract the SUBLW .148 value
while for differentiate 1 and 0 , i put a SUBLW .90, the value is between 5ms and 2.5ms , so that i can find out whether is logic 1 or zero to store
i'm using a pulse width signal for the infrared transmisssion
mayb u will feel weird that y i don know how to calculate and can get the value of 148 and 90, this is because i directly testing use hardware by different value
so that i suppose to get the answer after testing for 30times ++ , but i duno how how to use the 148 and 90 to calculate ??
148 value should between 7.5ms and 5ms, while 90 should between 5ms and 2.5ms.
thxs for helping!!
OK first, are you sure your logic is correct? Your initial logic seems to be waiting for a high, then timing a high pulse. Most modules output low, so a start bit is a low pulse not high.. Of course you could have an inverter or different module, but it's the first thing to check. Light carrier = Low on almost all modules, so if you have a module hooked straight to a pin this is likely it. Also check, some modules need an external pullup resistor too, but most have at least a weak one inside..
Secondly instead of a double lock like that I've generally found it's more successful to simply have a running count and only look for end transitions. Once you get an end of bit, do multiple subtracts for length to see if it was a 1, 0, or start, or overrange (ignore as bit and reset the decode) width, then add to the current decode and clear your running count for the next bit. This could be a bit more difficult as a running count in straight code, but as an interrupt routine it makes it easy. The time between interrupts makes for a divide, so if you do it right and just add one to your own counter on each interrupt, your valid pulse measurements will easily stay within one byte.
Timing variations on real remotes are crazy too, you want to get at least 2 or 3 of the same valid code before deciding it's real, 1 of even with checksum etc could easily get a false code now and then.