Header 1

 

In this post, I will be talking about my switches which are done with an interrupt on Arduino Mega's pin#2, and just of keeping my head on straight the interrupt service routines 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.

SectionABC
1abe
2cdf
3efg
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!01234A2A1A0EOGS
LXLHXLLHHHL
LXXXLHHLLHL
LXXLHHHLHHL
LXLHHHHHLHL
LLHHHHHHHHL