Better understanding PULSIN
I would better understand how work PULSIN statement.
I'm using PULSIN of PICBASIC PRO rel 4.47 on a 16F877 at 20 Mhz for decode IR from remote, using Sony format.
In order to better understand, I would track the timing of PULSIN using one free output pin to view with a scope the beging/end of the PULSIN duration with the following statement:
for BitCount= 1 to 12
High SData: pauseus 1: low SData ' Before pulsin, generate a pulse wiewable with an oscilloscope.
pulsin IR_Sensor,0,IRpuls_len(BitCount)
High SData: pauseus 1: low SData ' Before pulsin, generate a pulse wiewable with an oscilloscope.
if IRpuls_len(BitCount) < 580 then
Packet.0[BitCount-1]=0
Else
Packet.0[BitCount-1]=1
endif
next BitCount
In my mind, I immagine that first there are an ON pulse as a witness of the PULSIN begin, then after 2,4 or 1,2 or 0,6 mS I should see the second ON pulse.
Running it, never I see the ON pulse in continuos phase, with begin/end of PULSIN, but in a random position. Take note that the "IRpuls_len(x)" contain the correct value of the pulse lenght, 2,4 mS, 1,2 mS and 0,6 mS.
Also working with DEFINE PULSIN_MAX with different value do not help to view the second pulse in timing with the end of PULSIN duration.
Any comment or consideration is welcome.
Ciao
Leo
A Solution to measure following levels ...
Hi, Wirecut
Pulsin is a command that MUST wait for the leading edge ...
so, if you want to measure, say a PWM signal, you're tempted to Write :
PULSIN Input, 1, Hilev1
PULSIN Input, 0, Lolev1
...
... Am I right ???
But using Pulsin twice will do the Following :
READ correctly the High level ...
RESET it's detection mechanism ( some µs necessary !!! )
WAIT for an incoming falling edge
READ the Low level pulse
RESET it's detection mechanism ( some µs necessary !!! )
WAIT for an incoming rising edge
READ the High level pulse
then it doesn't see the falling edge for the 1st following Low level ( has happend some µs ago !!! )
THEN it will wait for the NEXT falling edge ... wich is the SECOND low level state ...
so, let's resume ...
you read hi state 1, lo state 2, hi state 3, lo state 4
INSTEAD of : hi state 1 , lo state 1, hi state 2, lo state 2 .... etc, etc
TURNAROUND ...
PULSIN Input, 1, Hilev1
RCTIME Input, 0, Lolev1
RCTIME Input, 1, Hilev2
RCTIME Input, 0, Lolev2
...
if using a 4Mhz clock, add 1 unit correction to RCTIME measured values
if using a 20 Mhz clock, add 4 units to RCTIME Measured values
And now, you'll get your values right !!! ... or very, very, very, very close, to be honest !!!
Alain
1 Attachment(s)
... little more help needed
Hello Alain,
This is an example of a 13-bit IR pattern I measure on a TSOP4838 receiver module.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2701&stc=1&d=121464754 0">
At the start, my prog captures the incoming pattern sent continiously until it determines the starting-bit (first one after the pause between two patterns) and the number of bits (Bit-Count) in the pattern.
I try with this code:
Code:
for Ctr_A = 0 to bit_count
rctime p_in, 0, h_Bit[Ctr_A]
rctime p_in, 1, l_Bit[Ctr_A]
next Ctr_A
' Results are:
Bit 00 Low :13795
00 High :350
Bit 01 Low :244
01 High :1253
Bit 02 Low :244
02 High :349
Bit 03 Low :243
03 High :350
Bit 04 Low :244
04 High :350
Bit 05 Low :244
05 High :349
Bit 06 Low :244
06 High :349
Bit 07 Low :243
07 High :350
Bit 08 Low :75
08 High :1
Bit 09 Low :244
09 High :650
Bit 10 Low :243
10 High :350
Bit 11 Low :244
11 High :350
Bit 12 Low :244
12 High :349
This is the code (works fine) I use currently use @ 20MHz and the data I get with PULSIN is:
Code:
for Ctr_A = 0 to bit_count
pulsin p_in, 0, L_Bit[Ctr_A]
next Ctr_A
for Ctr_A = 0 to bit_count
pulsin p_in, 1, H_Bit[Ctr_A]
next Ctr_A
' Resuts are:
Bit 00 Low :1258 'to be multiplied by 2µs (PULSIN res @ 20MHz)
00 High :247
Bit 01 Low :354
01 High :247
Bit 02 Low :354
02 High :247
Bit 03 Low :355
03 High :247
Bit 04 Low :354
04 High :247
Bit 05 Low :354
05 High :247
Bit 06 Low :354
06 High :247
Bit 07 Low :354
07 High :247
Bit 08 Low :655
08 High :247
Bit 09 Low :354
09 High :247
Bit 10 Low :355
10 High :247
Bit 11 Low :355
11 High :247
Bit 12 Low :354
12 High :13797
According to your previous message, I might raise the timings accuracy with RCTIME instead of using PULSIN. Unfortunately, I can't get it to work using RCTIME.
What am I doing wrong, please?