Firmware                                                                        Latest change 2023-12-24
In brief:
Some notes about the Arduino firmwares.
See remarks about the  Development Environments  I used. You also may Download the firmware.

Bob Control.
Most of the work is done in an interrupt routine ISR (TIMER1_COMPA_vect) called at a 10 kHz rate.
In successive calls the 6 AD-channels are converted, so we have effectively a 1.6 kHz sample frequency. I use 8 bit A/D conversions here.
The values from the Hall sensors are not further processed, they go into the message as is.

Most of the work is done in the state-machine  switch (State) { ....... }
The Center signal is at half-scale when the Bob is far away. When the Bob approaches, the signal rises at first and goes down through the midscale level when the Bob is exactly over the Center Coil. While waiting for this to happen the peak value is tracked and frozen until the message can be sent.
After the Center Pass has been detected the first message will contain the time of passing derived from the PositionCounter, which just counts 10 kHz ticks. Also the PositionCounter is set to zero to start a new sequence for timing the Drive pulse.

The Rim-1 signal also rises when the Bob approaches, but it is at its peak value when the Bob is just over the Rim Coil. So we track the signal while it rises and when it is going down again we freeze the Rim-1 Pass time and signal amplitude.
The Rim-2 works the same, but the signal is now negative because the bob approaches the rim coil from the outside.

Waiting for certain events is hold during certain times, in particular when the drive pulse is to be expected. This pulse will disturb the Center- and Rim sense signals.
We also have Time-Out criteria to decide that bob passes are much to late. This may lead to a ForceResync, where the statemachine is kicked to the state where evrything has to start again.

The loop() function calls Update_Messages() which looks for incoming data from the GUI.
Every message is responded to, by sending all relevant information to the GUI.
Some features like Battery management are not yet used.