Here are some first thoughts on coding these routines:
In order to support moderate data rates I need to be able to set and read pins at time intervals that are in the tens of microseconds. My current Arduino platform is the Uno, and this definitely seems doable with a little care. Also, to leave open the possibility of multiple satellite boards sending data back to a single mothership board I need to be able to receive on multiple pins but only need to send from one pin. In order to make this possible, I plan to use the following programming libraries/functions:
PinChangeInt is used for getting input (reading the incoming data stream). PinChangeInt allows hardware (external) interrupts to be used on all pins, and can be triggered by a state CHANGE. Because of the differential nature of the encoded signal, an interrupt on CHANGE is necessary for proper receive operation.
The time when when the pin change occurs must be determined with precision of single microseconds. The PinChangeInt library can only interrupt every 30-40us, so knowing the number of elapsed microseconds to a couple of microseconds should be sufficient.Paul Stoffregen's EllapsedMicros function
can be used to test when the data stream has timed out and avoids the overflow problem of micros(). Once data is flowing, if there is no longer a transition at the half clock period the transmission has ended. EllapsedMicros can be called in the main loop to test for stream stop. During each call of the function called by the PinChangeInt interrupt the elapsed time counter used by EllapsedMicros is reset.
Timing of generator pin changes - for transmission, a timer or polled function call that can execute a pin state change on intervals of 30us or more is needed. If the main loop() is fast then ElapsedMicros can be used to test whether the pin change should be performed. If there are other things going on in loop() then a timer driven pin change would be better.TimerOne library
- available on at least two pins for a variety of Arduino boards. These pins are pin 9 and 10 for the Uno. See:https://www.pjrc.com/teensy/td_libs_TimerOne.html
It seems that I can implement the functionality for both the generator and receiver of the differential Manchester signal using the code elements listed above.
Are there any inherent problems with this approach? Suggestions for changes/improvements?