Building the Service Status Monitor display prototype

Update 2012/11/08: Fixed some mistakes in the code example. The second division should have been a modulo and instead of the dynamically determined offset, the static one was used. Both errors are now corrected.

OK, enough talking – time to actually do something: let’s build the display prototype for the Service Status Monitor. The final version will have a variable amount of indicators (up to 16 with the current design), but to test the functionality and prototype the project, 4 indicators are enough to start with.

Confusing vocabulary

Alright, I got into a little labeling problem. In the first post, I called each combination of three LEDs a segment. Since the IC we’re going to use also uses the word segment but with a different meaning, I’m having trouble to name things without confusion. What was previously called segment will now be called indicator. This should help to keep things seperated from each other.

Hardware choices

In order to minimize the number of parts needed and to make the software design less complex, the display uses one of the modern marvels of integrated circuits, the MAX7219, a LED display driver IC with serial interface. To save power, the circuit will use the POV (persistence-of-vision) effect to display the status indicators (more on that further down) and the MAX7219 has this mechanism built-in. The IC can control up to eight seven-segment digits or up to 64 LEDs arranged in a matrix. It also provides a current control mechanism, making current limiting resistors (and another source of power loss) unnecessary. I admit, the MAX7219 may not be the cheapest IC to use (5-10 US dollars a piece), but you save a lot of time that you’d normally spend on creating „boiler plate code„, as software engineers like to call it. For a cheaper alternative, you could check out my LED-Matrix-Controller over at github. It uses a decade count/shift register/darlington array combination to achieve the same purpose.

Welcome to the matrix

The MAX7219 requires the arrangement of all the LEDs in a matrix, with a maximum of 8 columns and 8 rows. Please note: when talking of a matrix, this always means the electrical connections. This has absolutely nothing to do with the physical placement of the LEDs later on. When the MAX7219 displays something using a matrix, it only shows one row at a time. This row is configured by switching on or off the segments of this row. The IC then switches to the next configured row and to the next and the next and so on. It does this with up to 800 MHz which is way too fast for the human eye to acutally see and thus it looks like all the rows are lit together. This is called the persistence-of-vision effect and is the foundation of modern display technology.

To form a matrix, we need to form rows and columns. Internally, the IC has eight registers, one for each row. Each register holds the binary state of each segment, an 8 bit number. We want a low complexity in the software so we will arrange the indicators in rows. That way, we only need to write the value for one row to update an indicator. Actually, we will have two indicators per row because we would be wasting pins on the IC. The cathodes of the two indicators in a row are connected together, as are the anodes of the corresponding LEDs of each indicator across the rows. The cathodes form the digit lines, the anodes are the segment lines. An individual LED can be addressed by selecting its digit and its column. This picture does some explanation:

Status monitor indicators arranged as LED matrixAs shown in the picture, segment D and segment H (or DP) are not used. They may later be used to connect a fourth LED to each indicator.

Pics, or it doesn’t exist

Whats describes above in theory can be seen on these pictures in reality. The first shows the schematic done in Fritzing, the other one my real world prototype on a breadboard.

Dude, where’s my LED?

The arrangment of the LEDs as a matrix also comes in handy when writing the software and adressing each indicator. The state of all indicators will be held as several 8-bit numbers, one for each row (and thus for each two indicators). We change the state of an indicator by bit manipulation in either the lower or the upper 4 bits of that number. Example: B00010001 means that the two indicators both show green. If the second one were to switch to red, we would need to put a zero at bit 4 and a one at bit 6 (note: the rightmost bit is bit 0 or the least significant bit).

First, we would need to determine the row in which to find the specified indicator. When the first indicator is assigned the number zero, we can find the row by dividing the indicator index by two (integer division). For indicators 0 & 1 this yields 0, for indicator 2 & 3 this yields 1, and so on. Next step is to find the offset of the indicator within the row. We do this by calculating the modulo of (the index + 1) and 2. When the modulo (which is a remainder division) comes up with the result 0, we know that the second indicator in the row is addressed, when the result is 1, the first indicator is addressed. The LED states of the first indicator start at bit zero, so no offset is required, for the second indicator an offset of 4 is required. Here is the code on how to do this:

The above example introduces some required constants (so that you don’t have to remember if yellow was a 1 or a 4 or something else), then updates the displayState for indicator number 3 (second indicator in second row). The function changeIndicator(which, color)  works exactly as described in the paragraph above. It also contains one additional mechanism not mentioned: it would be too complicated to find out which LED is currently lit in the indicator and switch it off. Instead, the complete indicator is switched off and the desired color switched on. Don’t get confused with the uint8_t type. This is the type same as  byte , but I think it is a little easier to understand because all its properties (8-bit unsigned integer) are contained in the name.

As usual, the files used or mentioned in this post can be obtained from the projects github site: https://github.com/hmbusch/ICMI-ServiceStatusMonitor. The Arduino code is not yet complete and will be made available for the next post.

Alright, enough for this post. Up next: writing a small library to control the MAX7219 and implementing a complete Arduino sketch.

Verwandte Artikel

Tags: , , , , , , , , , , ,

Bisher keine Kommentare.

Hinterlassen Sie einen Kommentar