2

I am working on communicating 4 switch states across multiple Arduinos using only one pin. It must be as fast as conceivably possible.

Currently I have a master Arduino reading all 4 switches (multiplexing) and encoding them as 4-bit values: 0001 = 0, 0010 = 1, 0011 = 2 and so on up to 1111 = 15. I am thinking of assigning the low and high pulse duration/width, (+1) to produce a PWM square wave. So 1+0=1, 1+1=2, 1+2=3 ... 1+15=16. The high width (or low width) will hold the muxed value (+1.) Each slave would read this muxed value and demux it to get the state of all 4 switches.

Now to my concern: Is this approach safe and reliable? Or should I triple up the values: 1=3, 2=6, 3=9 ... to build in some tolerance and prevent some time misread due to some miss-interpolations? My switches control motors and a misread could have some unpleasant consequences.

I am using the Arduino's internal crystal, nothing external.

As a side note: I am actuality using Seeeduinos XIAO and not an Arduino. I started working on the timer based PWM writing and reading aspect, but it turns out to be quite complicated as there is not a lot of exaples to be found.

MeSo2
  • 177
  • 10

0 Answers0