In this post, I will be talking about my switches which are done with an interrupt on Arduino Mega's pin#2, and just to keep my head on straight the interrupt service routine's name is isr2. First, let me digress. The Fuel Load Indicator has two (2) switches and each has two (2) positions for a total of four (4) switch selections. So how do I generate the interrupt?
One way is to connect the four wires (a, b, c, d) to the Arduino and then use a quad 2-input or-gate, SN74LS32. As shown in the table below. And then you have to guess which switch was used.
Section | A | B | C |
---|---|---|---|
1 | a | b | e |
2 | c | d | f |
3 | e | f | g |
4 |
The second way is to use a priority encoder SN74LS148. The encoder has 7 inputs and 3-Bit BCD code for the output. Below is a table of its states, and I will not be using the zero state, which is the bottom row in the table.
Basically, the priority encoder just gives us the BCD number of the switch, plus a positive or negative signal EO/GS when a switch is thrown. which is connected to the interrupt pin, and in this case is pin 2 hence the name isr2. Depending on what my oscilloscope says I might need to use a Schmitt Trigger on each of the inputs, and most likely another Schmitt Trigger on ether the EO or GS line.
Interrupt code |
---|
// pins 30, 31, 32 are A, B, C respectively volatile retval; // This value is used in another function;
void isr2{ A = digitalRead (30); B = digitalRead (31); C = digitalRead (32); A << 1; A =+ B; A << 1; retval = A; } |
E! | 0 | 1 | 2 | 3 | 4 | A2 | A1 | A0 | EO | GS |
---|---|---|---|---|---|---|---|---|---|---|
L | X | L | H | X | L | L | H | H | H | L |
L | X | X | X | L | H | H | L | L | H | L |
L | X | X | L | H | H | H | L | H | H | L |
L | X | L | H | H | H | H | H | L | H | L |
L | L | H | H | H | H | H | H | H | H | L |