PDA

View Full Version : pulsin is not getting the next part of wave



longpole001
- 29th March 2012, 03:43
Hi guys , well this one has got me thinking , and i am not sure how i may get around it , so a bit of advise on the code would be good

IR data train is as follows

seq is normally high , low for 9ms ,high for 4.5ms, low for 560us , high for data etc ,etc then at end it goes low for 9ms , high for 2.5ms, low for 560us , high for etc etc for 2nd key data block seq , and then repeats entire IR train

the problem is i need to measure duration of low of 9ms , then the high duration of 4.5ms

the high duration length ( 4.5ms or 2.5ms ) after the low 9ms determined if its the 1st or 2nd key within the same pulse also if its blank repeat of key 1

the first Pulsin command gets the pulse length of 9ms ok , but the 2nd pulsin command will not measure the high duration until the next high going pulse.

any suggestions on how to get the length of both the 9ms low and then the high 4.5ms pulse

The 2nd pulsin command as shown below is not working as required

cheers

Sheldon




leader var word
leader1 var word


Main:

PULSIN GPIO.0,0,Leader ' leader pulse is ~9mS low-going on port 0
IF Leader < 850 tHEN main

pulsin GPIO.0,1,Leader1 ' check for 1stkey seq only no repeat headers

if leader1 < 300 then Main ' if high for < 300 (2.4ms then its the 2nkey)

HenrikOlsson
- 29th March 2012, 06:28
Hi,
The second Pulsin misses the high portion of the pulse because it "trigs" on a low to high to transition - in this case the same transition that ends the first Pulsin - so by the time the second Pulsin starts looking for a transition the transition have already occured.

Here's a more "manual" aproach which may work:

HighCount VAR WORD
LowCount VAR WORD

HighCount = 0
LowCount = 0

While GPIO.0 = 1 : WEND ' Wait for falling edge

While GPIO.0 = 0 ' Increment count while input is low
LowCount = LowCount + 1
WEND

While GPIO.0 = 1 ' Increment count while input is high
HighCount = HighCount + 1
Wend
The actual resolution obviosuly depends on the oscialltor speed etc but it shouldn't be hard to figure out how many "counts" equals one ms.

/Henrik.

longpole001
- 29th March 2012, 08:06
i have gone around the problem by just looking for correct value of the high pause duration as i know if signal is valid and correct should always work



Main:

' PULSIN GPIO.0,1,Leader ' leader pulse is high going on port 0
' IF Leader < 400 tHEN main ' look for 4,5ms high pulse below 400ms then its 2nd key area pulse or data/ address bits
' if leader > 480 then main ' above 480 then its no sig

longpole001
- 30th March 2012, 07:35
I know from what i can see here that there is no easy way to both measure a pulse and then it next immediate rising or falling going pulse , am i correct in this ???

c_moore
- 30th March 2012, 10:19
know from what i can see here that there is no easy way to both measure a pulse and then it next immediate rising or falling going pulse , am i correct in this ???


Maybe not using pulsin,but you could always use hardware capture if the pic has it.

Ioannis
- 30th March 2012, 11:07
With Pulsin the short answer is no.

Using the Timer 1 Gate will be much more easier ifyour PIC supports it.

Also controlling the Interrupt Edge on PB0 in combination with a timer (0 or 1) will also help you on this.

The edge is set in the Option Register, bit 6 on most PICs.

Ioannis

HenrikOlsson
- 30th March 2012, 16:15
Did you try the snippet I posted in the first reply? I think it's pretty straight forward and I think it's pretty much the way that pulsin works "behind the scenes" except that doing this way "trigs" on level and not on transition.

If it doesn't work for whatever reason there are several other ways, some of which other members have outlined here but in order to be able to give you a good advice things like which chip you're using and at what frequency you're running it would be good to know. Not to mention what kind of resolution you actually NEED.

/Henrik.

Acetronics2
- 30th March 2012, 16:51
Hi,

Solution is pretty simple:





leader var word
leader1 var word

Main:
PULSIN GPIO.0,0,Leader ' leader pulse is ~9mS low-going on port 0

IF Leader < 850 tHEN main

RCTIME GPIO.0,1,Leader1 ' check for 1stkey seq only no repeat headers

if leader1 < 300 then Main ' if high for < 300 (2.4ms then its the 2nkey)


may be you could consider the IF condition takes few µs ... to be verified, because your time unit is 10µs !

That's all !

Alain

longpole001
- 31st March 2012, 09:25
it does have PWM , but not tried it as yet , still not sure it would pickup and measure the low to high to low to high cycle and give a measurement for both duration

if only a pulsin "Mark 2" would do this

longpole001
- 31st March 2012, 13:54
Thanks guys ,

Both the RCTIME and counter solutions work , as well as my temp get around.

I was not aware of the RCTIME command ,thanks for that

because the times being measured are so long at this point in the signal (IR input) , is not a big timing issue for how it is checked using the if command etc

cheers

Sheldon