Thursday, 21 February 2013
The Right Tools
Visit Tagbits to see the full range of tagger products described in this blog.
I'm trying to develop my own software to implement the Milestag protocol, as I wish to add my own enhancements to the system. I am trying to avoid the open source BASIC software that is available as I don't have access to the compiler, so I'm developing mine in Hi-Tech C, which is available to me.
The IR protocol is based upon pulse lengths, best described here. Basically, a data packet has a 2400uS header, followed by zeros of 600uS in length, and 1s of 1200uS in length. There is an inter bit delay of 600uS.
The problem I have with current open source software is that there is an interrupt generated when the header starts, but the rest of the packet is received in the same interrupt session, regardless of the packet length.
I try to conserving CPU cycles when I can, and locking the receive routine in loop whilst it times bits is wasteful. This is not a problem for the current software, but I'd like to implement a timer driven fat16 routine to pull sample data of an SD card in the future, so I can get rid of the ISD1790 that is used to play back samples in the current design.
To get me there, I've written a routine which interrupts when the IR signal changes state. When the receive pin changes state, the interrupt routine resets the PIC TIMER0, and re-configures the interrupt to fire on the opposite edge. Using this method, only 10s of uS are spent in the interrupt routine, and TIMER0 is used to accurately time the period between each transition.
So, to test this properly I plugged my pulse generator into my Milestag UMT clone, whilst doing in circuit debugging using a Microchip ICD2 debugger, with a AC162055 debug header.
The pulse generator allows me to time pulses to within 20nS, so I fired off pulses of 2400uS, 1200uS and 600uS as used by the Milestag protocol.
I got TIMER0 values of 0x95, 0x4A and 0x25 respectively, which compare favourably with a 50% ratio between each value. I modified my code to allow a +/- 15% deviation from these values, as the PICs use internal RC oscillators that may have some variation.
With this in place, and my Milestag gun set to transmit a shot packet of player ID 'Sheik' which has a value of 0x2E and a shot power value byte of 5.
And here's the data as received by the PIC. 0x2e 0x05 as expected.
With this in place, I have the infrastructure to receive all Milestag packets.