Friday 26 August 2016

A bit more on PWM IR and Arduino

We've had a few questions about our PWM IR data transfer idea. And most of them revolve around "why send an end of message marker at the start and the end of the data?"

Some people went so far as to suggest that only an end marker would be necessary, We disagree with this. Some people asked why we weren't using a start marker and an end of message marker. This makes some sense. But here's why we did it the way we did:

Firstly, we need a marker at the start AND end of the message. Otherwise while the IR receiver is exposed to sunlight, it might start creating extraneous bits and bytes (unlikely, since we have a defined PWM width we listen out for and ignore anything outside of these widths, but still possible).

At the start of a message, we clear down our byte value buffer so we know that what follows is being added to a "clean" variable, and not tacked onto the end of some random noise.

At the end of a message, we parse the contents of the bits and bytes received. We could have used a different start pulse, but our pulse widths are already getting quite wide. A bit value zero is up to 4ms long, a bit value of one is up to 12ms long, and our EOM marker is up to 20ms long. To make another, clearly definable pulse wdth, we'd probably have to go up to 40ms long. That's as long as it would take to send x10 zero values!

There's nothing wrong with creating a different start-of-message pulse width, but we just felt it was unnecessary. At the start of a message, if we sent an end-of-message width, we'll parse any random noise that's been received and expect it to fail (since all messages have a checksum byte at the end). After parsing a message we reset the internal buffers anyway. So there's no reason why we can't use the same pulse width at both the start and end of each message.

So that's what we did.
Hope that clears that up!

No comments:

Post a Comment