LED and Switch Add-On Circuit
The Dragon Rider printed circuit board includes an area for six LED indicators and five push-button switches. 10-pin headers allow the LEDs and switches to be linked to target microcontroller ports with 10-way ribbon cables of the type supplied with the Atmel STK500. LEDs are numbered 2 to 7, corresponding to the port bits that control them. Switches are arranged in a diamond, labeled UP, DOWN, LEFT and RIGHT, with a fifth ENTER switch, for convenient use with menu-driven user interfaces. LEDs and switches can be controlled from the same port if desired.
Typical Parts Required
The table below lists the parts that are provided in the ECROS Technology add-on parts kit for the LEDs and switches. Most of the parts are not critical and are the sort of thing you may have in your spares drawer. The comments column should help you find substitutes; refer also to the Technical Information section, below.
Qty. | Description | Ref. Des. | Comments |
---|---|---|---|
2 | 10-pin headers (2 by 5) | J29, J30 | Common 0.1 in. pin spacing |
6 | 33 kohm resistors | R10-20, even | Set transistor bias current |
6 | 470 ohm resistors | R11-21, odd | Set LED current (6 mA at 5 V) |
6 | 3mm (T1) LEDs | LED2 to LED7 | Just about any small LED will do |
6 | 2N3904 transistors | Q2 to Q7 | General purpose NPN |
5 | Push-button switch | SW3 to SW7 | Common 6 mm tactile type |
5 | 3.3 kohm resistor | R22-30, even | Set port current limit |
5 | 10 kohm resistor | R23-31, odd | Set switch on current |
Technical Information
Both the LED and push-button circuits are independent of all other circuitry on the Dragon Rider, including each other, having only the ground connection in common. Power is taken from pin 10 of header J29 for the LEDs and pin 10 of header J30 for the switches. Therefore, each can be connected to and used with other systems, for example the Atmel STK500. This is possible whether or not the Dragon Rider is powered or in use with the Dragon.
The figure at right is the circuit diagram of an LED channel (channel 7 shown).
There are six channels, numbered 2 to 7 on the PCB silk-screen and connected
to pins 3 to 8, respectively, of J29. As a result, if J29 is connected,
pin-for-pin, to one of the port headers of the Dragon Rider (for example, J4
for Port D), LED 2 will be controlled by bit 2, LED 3 by bit 3, etc.
All LEDs will pick up power from pin 10 of the port header. Pin 9 is
connected to ground. Bits 0 and 1 of the port will not be connected and
can be used for something else.
LED current is set to about 6 mA (for yellow or green LEDs) by the 470 ohm resistor (R11), assuming a 5 volt supply. The 33 kohm base resistor (R10) provides a bias of 120 µA to the transistor (again, assuming a 5 volt supply). This is enough to turn it fully on if the current gain is 50 or more. The specified 2N3904 transistor has sufficient gain. If you substitute a lower gain transistor, or use smaller collector resistors to get more current in the LEDs, you should re-calculate the necessary base resistors. The fairly high values in the parts kit were chosen so that the LED circuit can be connected to a port being used for something else without drawing much current and disturbing the logic levels.
The figure at right is the circuit diagram of a switch channel (LEFT channel shown).
There are five channels, marked LEFT, RIGHT, UP, DOWN and ENTER on the PCB
silk-screen and connected to pins 8, 5, 7, 6 and 4, respectively, of J30.
As a result, if J30 is connected, pin-for-pin, to one of the port headers of
the Dragon Rider (for example, J4 for Port D), then pressing the LEFT, RIGHT,
UP, DOWN and ENTER switches will change the input level at bits 7, 4, 6, 5 and
3, respectively. Switch numbers are also shown on the silk-screen (for
example, LEFT is SW7), and these numbers correspond directly with the port
bits (LEFT; SW7; bit 7). All switches will pick up power from pin 10 of
the port header. Pin 9 is connected to ground.
Bits 0, 1 and 2 of the port will not be connected and
can be used for something else.
Switch current (when closed) is set to about 0.5 mA by the 10 kohm pull-up resistor (R31), assuming a 5 volt supply. The 3.3 kohm resistor (R30) provides current limiting to about 1.5 mA in the event that the connected port bit is driving high and the switch is closed. Thus, it is not only safe to allow this, the port will also be able to drive a valid logic level. If you use different resistor values here, take into account whether you want to allow the port bits used to read the switches to be also used as outputs to drive something else.
Connecting LEDs and Switches to the Same Port
With the resistor values shown and supplied in the parts kit, it is perfectly OK to connect the LEDs and switches (J29 and J30) to the same port, for example Port D at J4. Your software should normally configure the port bits in use (bits 2 to 7 if you're using all six LEDs) as outputs and set their states to high for the LED to be ON or low for the LED to be OFF. Periodically, perhaps every 5 to 20 ms, your software should change the configurations of the port bits used with switches (bits 3 to 7 for them all) to make them inputs, read the input values and then restore the configuration to outputs. The blink in the LEDs will not be noticeable, but now you have a snapshot of the states of the switches. This should be de-bounced in the normal way before recognizing a change of state.
If you like this idea a lot, you might want to make a permanent connection between J29 and J30 so that you only need to run a ribbon cable to one of them (J30 is near the front edge of the board). One way to do this would be to solder wires underneath the board to the ends of the header pins that poke out from the bottom. Otherwise, you will probably need a ribbon cable with several sockets to "daisy-chain" the headers together and some careful folding will be needed to keep it out of the way.
Connecting the LCD to the Same Port As Well
In the same way that your software can take a break from holding the LEDs ON or OFF to sample the switches, it can also take time out to write something to the LCD without any noticeable flicker. So, the LCD (J31) can also be connected to the same microcontroller port. To write to the LCD, your software needs to put a pulse on the enable (E) line, which is connected to pin 3 (bit 2). So, you will have to give up the independent use of LED2 to make this work. Note that there is no switch on bit 2 of the port, so you won't be accidentally writing things to the LCD by pressing a switch.