many thanks.
I will read it. I'm so busy right now because I'm testing the system based on the TIMER1.
It seems to get the bits length right (although there is a significant variation compared to the expected value).
Now I have to check what time it takes to execute my routine.
I failed programming an auxiliary pic to read the pulse duration.Code:T1CON = %00011100 '1:2 prescale for 1US increments, timer 1 is stopped TMR1H = 0 'reset timer high byte TMR1L = 0 'reset timer low byte databyte = 0 'word var 'the 2400US header that triggered the int when porta.0 went HIGH->LOW is in progress (LOW going pulse because TSOP4840 pulls the pin low when getting 40KHz mod pulse) while (porta.0(pin) == 0) : WEND 'while pin is low because of the incoming header LOW pulse '0->1 (2400US header pulse ended) 'here the signal goes high and will stay high for 600us (spacer between header and first bit) while (porta.0(pin) == 1) : WEND '1->0 (600US spacer between header and first bit ended because first bit is starting) 'memo: 'recorded ranges for a 600 us pulse: 608-741 'recorded ranges for a 1200 us pulse: 1217-1346 T1CON.0 = 1 'start TMR1 with prescaler = 1:2, we will have 1US increments 'Get length for 16 bits (1200 or 600 us followed by 600 us spacer) FOR i = 0 to 13 'Bit has started its LOW going pulse, either 1200 or 600 us long WHILE (porta.0(pin) == 0): WEND 'wait for bit pulse to end (while TMR2 is incremented every us) '0->1 (spacer) T1CON.0 = 0 'stop TMR2 'we have 600us (the bit spacer length) to manage de received bit pulse_length.highbyte = TMR1H pulse_length.lowbyte = TMR1L ' bit_pulse[i] = pulse_length IF ((pulse_length > 600) && (pulse_length < 750)) THEN 'about 600 us, it is a '0' databyte.0(15-i) = 0 GOTO next_bit ENDIF IF ((pulse_length > 1200) && (pulse_length < 1350)) THEN 'about 1200 us, it is a '1' databyte.0(15-i) = 1 GOTO next_bit ENDIF 'GOTO bad_bit next_bit: IF (i == 13) then exit_loop 'after the 14th bit, we are finished here TMR1H = 0 TMR1L = 0 WHILE (porta.0(pin) = 1) : WEND 'we don't measure length of the spacer '1->0 the falling edge for the next byte T1CON.0 = 1 'start TMR1 with prescaler = 1:2, we will have 1US increments NEXT i exit_loop: 'bypass label after 14th bit has been received 'at this step the bit lengths are fine valid = 1 'now let's see if the bytes have a valid value 'TEST block LCDOUT $fe,1,#databyte.highbyte," ",#databyte.lowbyte PAUSE 2000 killer_id = databyte.byte1 'get opponent ID byte2 = databyte.byte0 bad_bit: 'jump here if one of the bit length is invalid (valid flag/bit is set to 0) RETURN 'after signal has been processed return from subroutine
I raise a pin (connected to the auxiliary pic input) at the begining of a code chunk and lower it at the end of the chunk so the auxiliary pic can record the duration of the pulse so it gives me the duration of the chunk execution... I got abdnormal values so I have no real way of knowing how long it takes to execute my code chunk...




Bookmarks