|
| ( 01 Jun 2011 ) |
| By Abel Raynus, Armatron International, Malden, Massachusetts |
|
Most microcontroller-based devices have several states of operation. Pushbutton switches often control these states. To minimize costs, many designs use only one switch; the number of presses sets the microcontroller’s state. In the circuit in this Design Idea, lighting an LED indicates the chosen state.
A large selection of bicolor LEDs is on the market in various shapes and colors from Kingbright, Optosupply, and other suppliers. These LEDs provide new opportunities to use just one LED to indicate 10 states. You set the states by pressing a pushbutton switch that connects to a microcontroller’s external interrupt pin (Figure 1). After each push, the interrupt subroutine sets the device to the next state (Figure 2).
State 0 is standby mode with the LED off. The device waits for you to press a switch. The LED’s color indicates the next three states. For example, a Kingbright WP5A9EGW12.3SF LED yields red, green, and orange. Add blinking to indicate the remaining states. You can independently control the red and the green LEDs, yielding six more combinations of indication (Table 1).
Using the microcontroller’s internal oscillator as a clock source simplifies the circuit because the oscillator needs no external components and its 5 percent tolerance is sufficient for this application. Firmware sets the built-in pullup resistor for external interrupt input.
The clock speed and the values of the prescaler and time-counter-modulo registers determine the rate of LED blinking. The internal oscillator generates a 12.8MHz clock, resulting in a 3.2MHz bus frequency, with one cycle equal to 0.3125μs. By choosing a prescaler value of 64, a time-counter-modulo register can calculate a cycle of 50 times the timer period in milliseconds. For example, for 1s of blinking, you should set the time-counter modulo to 50,000, or $C350 in hexadecimal.
Using tables rather than polling in programming allows you to significantly reduce the size of firmware (Reference 1).You can download firmware assembly code here. This method is applicable to any microcontroller. You can even increase the number of indicated states by using different blinking rates.
|
| |
|
|
|
|
| |
|
|
Average Rate:
No rating yet |
| |
| |
|
|
|
|
| |
|
|
| |
|
|
| 25/4/2012 |
|
| 25/4/2012 |
|
| 24/4/2012 |
|
| |
|
|
|
|
|
|
|
| |
|
| |
|
| 30/3/2012 |
|
| 22/3/2012 |
|
| 1/3/2012 |
|
| |
|
|
|
|
|