masthead
 
 

Cribbage Board #10: The Wedding Board

WEDDING BOARD FLOWCHARTS

If you want to learn a little bit more about the firmware that went into the Wedding Board, this is a good place to start. These flowcharts were made using OmniGraffle (much better than microsloth's Visio).

This high level view of the peg firmware is just that. High level, not much detail.

Upon power-on reset, the peg begins implementing the EEPROM Check routine. This is essentially the peg finding the break in the first circular buffer, indexing into the second buffer and then handling the power cycle count (are we being programmed?). This section is complicated simply because of the value checking that has to occur and the need to prevent the peg from looping infinitely.

This section had to handle numerous special cases in determining when the "cliff" of the pointer buffer was discovered. Initial versions of the code would end up in infinite loops or find false peaks or overrun the buffer. This latest version is stable and can handle cases where the EEPROM is loaded with the same number throughout.

To see an example of a dual bufferr EEPROM dump click here.

The Check For Data routine evaulates the count value in the second buffer and set appropriate flags (are we being programmed). It also handles calculating the desired mode (based on the number of power cycles) and places the parsed mode value in the Mode Register.

The Get Colors routine illustrates the mode register parsing and setup for the Color Wash subroutine. Initially, overlay modes are dealt with and then the getcolors routine is run a second time on the basic modes. The interrupts are only enabled just prior to entering the wash routine AND only if overlay modes are enabled.

The actual Color Wash routine is the infinite loop that generates all of the colors. It is basically a series of sub-loops that increment counters as they progress. When one end of the counting spectrum has been reached, a state change is enabled and the two alternating colors are rotated. A colorwash simply rotates the three primary colors (sure, there could be more "points" added) through this alternating PWM cycle. Steady color is simply a color wash between the same colors (keeps the code simple).

The Timer 0 Overflow Interrupt routine is another complicated routine. It begins by determining if it is handling a flash (simple on/off at a set time) or a pulse (think of pulses as colorwashing black by varying the length of the black sequence.

This section is only intended to interrupt the wash subroutine to introduce "black" into the color wheel. The Timer0 overflow interrupt is used to handle the pulse or flash modes. Sure, with a little more register combination and reclamation, it might have been possible to use a second interrupt scheme to enable *both* pulse and flash overlays simultaneously.....but this thing was already a late Wedding Present. NOTE: It's the pulse side of things (with it's varying interrupt cycle) that presents the most complexity. The flash interrupt routine is fairly straightforward. The most difficult portion of the overlays was making sure not to destroy needed registers. This took some discipline.

This is the flowchart for the entire Programmer code. Note, the programmer code figures out it's reset source (was it the "Push to Program Button" or was it just the "Fridge Door Switch" allowing the Tiny12 to power up). The programming count and the optional noise immunity sections are well documented in the actual code itself. It is important that both the Programmer and the Peg agree on the number of power cycles for various modes.

Back to the top