Close

Reading the plugboard with a state machine

A project log for (AT) Mega Enigma, a 2560 Pro Mini Enigma Simulator

A minimalist 139x171x50mm Enigma Machine Simulator with working plugboard using an ATmega 2560 Pro Mini and a custom PCB.

arduino-enigmaArduino Enigma 05/27/2019 at 17:300 Comments

Using a genuine Arduino MEGA  to test the plugboard logic:

All the plugboard pins are set to input with the pullup resistor activated. One at a time, each plug is set to output and low. The other plugs are read one at a time, a 0 is returned if the other end of the plug is installed, otherwise a 1  is returned.

The code is implemented as a state machine and only one I/O operation is done each time it is called. This routine needs to be called once or twice in between changing the display from one digit to the next.

Thie state machine takes 24us to run.

Here a list of the installed plugs is shown:

The code stores any plugs detected in an array. The scanning process is shown below.

Notice that column 23 changes to 6 as the plug is discovered. Column 6 was already changed to 23 as one side of the plug was discovered.

Detecting when a plug is removed is equally important. and a different logic is needed. If all the plugs are read and neither returns 0, reset the plugboard entry to itself. Notice the last row changes from 1 to 26 once the A-Z plug is removed;

https://gitlab.com/arduinoenigma/megaenigma/blob/master/DisplayAndKeys.ino

Discussions