IR decoding

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

IR decoding

Post by FFMan »

I'm writing some code to look for a particular 3 pulse IR stream from a track side beacon. The precursor to this project based on a BX24 is described here along with the pulse timing.

http://javalins.wordpress.com/projects/ir-beacon/

For that project we used a Parallax sx processor to front end the decode, but now I am trying to do it on the zx24 using code and lessons learned from AN-204. A friend did the FEP work so this is my first view of it.

My capture code is simply

Call InputCapture (pulses, pulseStreamLength, 0)

with a 50 element array and then I parse the array looking for my sequence. If I see 65535 I know a large value has been captured.

From what I can work out from my timings (taken with a scope) I don't beleive i should see any 65535 value as the beacon output is constant once on.

Should I consider adjusting the Register.TimerSpeed1 value ?

thanks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: IR decoding

Post by dkinzer »

FFMan wrote:Should I consider adjusting the Register.TimerSpeed1 value ?
With the default timer speed, InputCapture() can handle high and low segments as long as 4.44mS. If the specifications of the IR signal allow for a longer pulse width than that, you'll need to use a different prescaler value.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: IR decoding

Post by dlh »

FFMan wrote:From what I can work out from my timings (taken with a scope) I don't beleive i should see any 65535 value as the beacon output is constant once on.
The time between each 3-pulse burst (in the center of your included screen capture) is about 6mS which is nearly 50% greater than the 4.4mS max.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: IR decoding

Post by dkinzer »

dlh wrote:The time between each 3-pulse burst is about 6mS [...]
The values for Register.TimerSpeed1 are the timer prescaler selector values. In general, you'll need to consult the datasheet for the AVR upon which the particular ZX device you're using is based to find the mapping from selector values to prescaler values. For most ZX devices, the value of 2 for Register.TimerSpeed1 selects a divide-by-8 prescaler, giving you eight times the range at one eighth the resolution. Each unit of the input capture value will represent about 542nS and the maximum value of 65533 will thus represent 35.5mS (with the CPU frequency of 14.7456MHz).

Be aware, however, that setting Register.TimerSpeed1 affects other time-based routines, too. See the table in the System Library Reference Manual.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks for your help

if i set the prescaler 2 i get much better results and no unexpected timeouts.

what is the overhead of inputcapture when not receiving pulses ? is it an ISR and therefore negligible ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:what is the overhead of inputcapture when not receiving pulses ?
The core functionality of InputCapture() is implemented in an ISR. Once it is set up, the only CPU burden is the execution of the ISR on each edge of the input signal and/or on overflow of the counter.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

If I port this code to a 328l, should i half the value of the timer prescaler to realign the timer with the clock speed ?

My current value on 14mhz is 2, should i put this to the default of 1 using compiler directives for the 328l ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:My current value on 14mhz is 2, should i put this to the default of 1 using compiler directives for the 328l ?
The answer depends on the largest time you need to capture. Using a prescaler of 1, InputCapture() on the ZX-328L can log high and low times up to 8.8mS in length. If the maximum you need is the 6.6mS discussed recently then the default prescaler would work fine. As always, it's a trade-off between range and resolution.
- Don Kinzer
Post Reply