Page 1 of 1
IR decoding
Posted: 09 February 2010, 14:37 PM
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
Re: IR decoding
Posted: 09 February 2010, 15:43 PM
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.
Re: IR decoding
Posted: 09 February 2010, 16:16 PM
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.
Re: IR decoding
Posted: 09 February 2010, 16:42 PM
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.
Posted: 10 February 2010, 7:03 AM
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 ?
Posted: 10 February 2010, 8:38 AM
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.
Posted: 16 February 2010, 7:36 AM
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 ?
Posted: 16 February 2010, 9:20 AM
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.