I've got a very unique problem and not sure how to approach it. I've been writing code for a while, but new to the PIC.
I'm watching for a very spurratic pulse of data from an existing product which must be relayed in near real time over a radio link. Sounds easy enough - my circuit will be clipped into an existing product to watch for the short pulse (will last about 3 microseconds, plenty long enough to register on I/O pin of the PIC). The PIC will then drive a pin on a radio transmitter, and a reciever on the other end will feed the pin transition into a second PIC and do something.
Easy.
Trouble is, in order to maintain the fast response I need on the other end, the radio transmitter must transition every couple milliseconds - I can't just let the receiver flat-line for minutes at a time waiting for this pulse to come over the radio. I have to drive the signal up or down every few milliseconds. Suffice to say it's a requirement of the radio modules I'm using.
So I plan to put out a squre wave with a 4 millisecond period, and just toggle it on the Tx side when the input event happens. Again, easy.
On the Rx side it gets more complicated.
My best solution:
Time the incoming "carrier squre wave" on the Rx which is expected to transition every 4 ms, and ignore that transition when it happens, as it is "expecting" the event, no action is taken. But if it transitions before the 4ms times out - it must be because the Tx has gotten the signal and toggled the output early, thus I can take action.
That's beautiful except - there is some chance the "data" transition will occur at the exact same time as the planned transition and will be missed by the Rx.
But actually in practice it wouldn't "mask" the data, what would actually happen (assuming a near exact time match) - is the "carrier" will toggle, then a few uS (much shorter to be broadcast by the radio) the data event will toggle again - so the Rx in effect *won't* see the expected transition which in itself would mark the data event has occured.
Question 1:
I go though all of that to ask: How accurate are these timers? How accurately can I predict this transiton event? As it's a radio signal and takes some time to transition, the radio wave itself may introduce 2 to 3 uS of "slop" into the transition time, even if the Tx PIC hits it right on the nose of a perfect 4mS for each time. So the logic of the Rx needs to accept the transition happening a bit before or after the actual expected instant (again +/- maybe 4 uS).
Question 2:
If I understand the PIC correctly, I can kick off a Pulse-Width-Modulate PWM in my code to drive a pin's pulse and transition at a specific interval then leave it - go and run the rest of my code and the PIC won't pause to check or count or anything - it'll just use one of it's internal timers and "multi-task" the pulse up and down in the background - so I can just turn it on, and walk away from it.
And it's further my understanding that if I "toggle" the same pin that the PWM is using, the PWM will continue without skipping a beat, it will just reverse early but keep it's original timing... so for example I could set the PWM to transition every 1000 uS, and from the start of that pulse, my code could in effect toggle that pin 35 times during that 1000 uS, walk away and do something else, and it would still transition again from whatever state to the opposite state still exactly 1000 uS from the time the PWM started driving it.
Question 3:
Am I going about this all wrong? This is the most logical solution I've come up with. Point is, I've got to transtion the output every so often - it could be much shorter than the 4mS I propose, I just figure stretching it longer makes for less change of a "pulse overlap" of the planned transition - and however I work it, I need a very high chance of picking up the data event, and reacting to it as fast as possible.
Thanks so much in advance - I know this is a broad quesiton. Not asking anyone to write me any code or anything, just consider my approach and clairify how accurate the timers are and the whole PWM in the background question.
I've been reading the forum for a few weeks and it's awesome - you guys are very helpful to eachother - I've learned a lot in that time.
Thanks!!!
Bookmarks