PDA

View Full Version : pulsin sample time



longpole001
- 9th July 2012, 05:32
Hi guys ,

Pulsin command returns time measured of the pulse width with the resolution dependent on the real OSC speed ,

but how long is the sample period before gives a result to variable , and how can that time frame be set within pulsin


cheers

Sheldon

Acetronics2
- 9th July 2012, 09:59
Hi, Sheldon

There's no sample period !

just some µs @the beginning of the command to preset the trigger conditions, and some µs after the end of measure to check end of signal and transfer the result to the variable you've chosen.

I must suppose your question was ... " which is the minimum period pulsin can measure " or " which is the maximum frequency for pulsin use "

please try to explain better what you try or intend to do ;)

Alain

longpole001
- 9th July 2012, 12:00
just notice it takes a long time to get a sample , doing a pulsin sample serial of 32 bits ,arranging it to make a byte value , write to eprom if the byte data changes only ( 4 bytes) then go do the lot again , i did a debug cycle test , and it takes about 1 sec a loop which seem really long to me doing a sample at 4mhz i am playing with increasing the osc to 8mhz , which should help . but a way to stream line the code would be a better approach , just not sure how to do it



GetIRcode:

TRISIO = %00111111 ' setup input=1,output=0 GPIO.0 = 1 to input
PULSIN GPIO.0,1,Leader ' get leader high pulse time value in on GPIO.0
IF Leader < 400 tHEN return ' look for 4500us high pulse below 4000us then its 2nd key area pulse or data/ address bits
IF Leader > 480 tHEN return ' above 4800us then it no sig

FOR X = 0 TO 31 ' grab 32 incoming pulses
PULSIN GPIO.0,1,BtnVal(X) ' now measuring high-going pulse widths
NEXT X

z = 0 ' Z points to start range of byte
S = 7 ' S points to end range of byte
X = 0 ' start X at 0 to line up with BtnVal array
for Y = 1 to 4 ' Get in Array and decode 4 bytes from 32 bit pulses
T = 7 ' Set T to 7 so that it puts BtnVal(0) in to D7 location
FOR X = Z TO S ' sort 8 pulses of byte

IF BtnVal[X] > 150 THEN ' > 150 x 10uS = > 1.5mS pulse period = 1
DByteTmp = DByte[Y] ' get into temp var

DByteTmp.0[T]=1 ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte
ELSE
DByteTmp.0[T]=0
ENDIF

DByte[Y] = DByteTmp ' get it back into DByte(y)
T = T - 1 ' T points to next MSB on loop
NEXT X

Z = x ' Z = X (0,8,16,24) points to start of next byte
S = 7 + X ' S (7,15,23,31) points to End of next DByte BtnVal offset to X
next Y ' loop for 4 bytes


' only save code if it differnat to stored IR code

for x = 1 to 4
if DByte[x] <> STDByte[x] then
wrITE x,DByte[x]
endif
next x

Return

longpole001
- 9th July 2012, 12:22
this be easier to read





GetIRcode:

TRISIO = %00111111 ' setup input=1,output=0 GPIO.0 = 1 to input
PULSIN GPIO.0,1,Leader ' get leader high pulse time value in on GPIO.0
IF Leader < 400 tHEN return ' look for 4500us high pulse below 4000us then its 2nd key area pulse or data/ address bits
IF Leader > 480 tHEN return ' above 4800us then it no sig

FOR X = 0 TO 31 ' grab 32 incoming pulses
PULSIN GPIO.0,1,BtnVal(X) ' now measuring high-going pulse widths
NEXT X

z = 0 ' Z points to start range of byte
S = 7 ' S points to end range of byte
X = 0 ' start X at 0 to line up with BtnVal array
for Y = 1 to 4 ' Get in Array and decode 4 bytes from 32 bit pulses
T = 7 ' Set T to 7 so that it puts BtnVal(0) in to D7 location
FOR X = Z TO S ' sort 8 pulses of byte

IF BtnVal[X] > 150 THEN ' > 150 x 10uS = > 1.5mS pulse period = 1
DByteTmp = DByte[Y] ' get into temp var

DByteTmp.0[T]=1 ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte
ELSE
DByteTmp.0[T]=0
ENDIF

DByte[Y] = DByteTmp ' get it back into DByte(y)
T = T - 1 ' T points to next MSB on loop
NEXT X

Z = x ' Z = X (0,8,16,24) points to start of next byte
S = 7 + X ' S (7,15,23,31) points to End of next DByte BtnVal offset to X
next Y ' loop for 4 bytes


' only save code if it differnat to stored IR code

for x = 1 to 4
if DByte[x] <> STDByte[x] then
wrITE x,DByte[x]
endif
next x

Return

longpole001
- 11th July 2012, 00:24
i think the biggest time waist of this sub routine is waiting for a pulsin to see an input transition ,there is no time out on the command.

As it happens because the input is connected to IR receiver , and some transient spikes do occur it gets to check the pulse and then return from the routine , generally with a sec

I think ill add a timeout value so that it not waiting for input to occur , see if that improves it

longpole001
- 11th July 2012, 08:59
is there a way to time out the pulsin command , so in the event i dont get an input , it times out.

Tried setting timers , but as soon as it hit the pulsin command it sits there untill it gets a pulse and wont read any flags after that till it completes

any code examples that get around this

longpole001
- 11th July 2012, 09:13
found this after some searching the help

DEFINE PULSIN_MAX 1000 'Maximum counts allowed before pulsin times out

the value of 1000 looks like it clock cycles , but it not stated ?

longpole001
- 11th July 2012, 10:32
well Pulsin_Max is ok when the pulse is measured , but if it stays at 100% or 0 , then there is no time out ,

can someone advise some code that can get passed this

longpole001
- 11th July 2012, 12:57
solved , i think , cheers

mackrackit
- 11th July 2012, 14:53
After talking to myself for several hours I realized that no one was listening... :)

What was the final solution?

longpole001
- 11th July 2012, 15:30
lol, it seems that way some times , in some ways you tend to solve problems as you post

well since this little pic is doing about 4 diff things at about the same time , as it it talking to currently 16 other RF devices , in sync within a started mesh network, its getting harder to get enough time for each process from a 4Mhz clock , so first of all i had to up the speed to 8Mhz , with all the timming changes to specific routines that was based on 4mhz.

After reading more and doing searches found that pulsin_Max set to the min count time + 5% margin extra of my expected time of the pulsin , allowed it to get to the next command scientifically, when i did not get a valid signal input .

Now to deal with error rates in TX / RX over RF and try and improve on the current poor performance.

more fun to come

Cheers