The sequencer logic is directly supported by the Operating System. It
allows a sequence of timed or event-driven steps to occur, and loop back
upon completion of the last step. It was designed to automatically control
a water purification cell by monitoring water quality, starting and
stopping pumps, opening and closing valves, stepping through the cleaning
(e.g., backwash to filter media reseating) cycles, then resuming normal
filtering. To demonstrate the sequencer logic, an array of WS2812B
Start by creating a new file, "SeqTemplate.Asm", for example, then copy the entire block which follows into that new file.
/****************************************************************************** * * Assumes: These routines are being called as a FOREGROUND task, * PushAll() has already called and that all Registers may be used * At least 20 uVars.B[ # ] bytes available * In the 328P only, bSandD_Count has the number additional BYTEs * in the uVars.B[] array (range 0 to 244), so the BYTE total * in the uVars.B[] array will range from 32 to 256 * * Notes: In the 1284P and 2560, the uVars.B[] array always has 256 BYTEs. * The WS2812 configuration block (or structure) layout: * +---------+-----------+--------+-----------+--------+----+----+-/ * | Display | Bitmapped | Port's | Incr/Decr | Max |LED Count| * | Mode |GRB|Z| Port| Pin(s) | Amount | Bright |LSB | MSB| . . . * +---------+-3-+1+--4--+--------+-----------+--------+----+----+-/ * +0 +1 +2 +3 +4 +5 +6 * +7 +8 +9 +10, 11 +12, 13 +14 +15 * /-+----+----+----+----+-----+------+------+-----+-----+ * | Mode Specific| Update | Mode Change | Starting | * . . . | #1 | #2 | #3 | Interval | Interval | Address | * /-+----+----+----+----+-----+------+------+-----+-----+ * milliSec Seconds * * Note: The Starting Address (+15:+14) is compared with the amount of SRAM * and if larger, is disregarded. For a 328P, for example, that value * is 0x800; it's 0x4000 for a 1284P (allowing for a minimal stack size * of 256 bytes.) If the MSBit in the MSByte (+15) is set, it cannot * be a starting address. If that is the case, the remaining 7 bits * in the MSByte are used to selectively disable the Analog Inputs * influences on bMaxBright and bUpdateInterval (or more) and all 8 * bits of the LSByte may be used for any other purpose. * * +----+---+------+------+ Although 4 additional Registers are required * | Update | Mode Change | and used by the timer routine that usually * | Timer | Timer | calls this section, it is not strictly part * +----+---+------+------+ of the requirement here. The 16 BYTEs that * +16 +17 +18 +19 are shown above are the only ones REQUIRED. * ******************************************************************************/
The documentation block above explains how the sequence of 16 BYTEs is laid out in the structure read in from EEPROM. It is a good idea to keep it in each file created.
Append these constants to the documentation header file started above.
; Prefix "Ib" means "Index of a BYTE", "Iw" is "Index of a WORD", for example IbBitmapped = 1 IbColorSelectBits = 1 ; These apply to R11, the bColorSelectBits (from left to right): BIT_R11_GREEN = 7 BIT_R11_RED = 6 BIT_R11_BLUE = 5 BIT_R11_MODAL = 4 MASK_R11_GREEN = 1 << BIT_R11_GREEN MASK_R11_RED = 1 << BIT_R11_RED MASK_R11_BLUE = 1 << BIT_R11_BLUE MASK_R11_COLORS = B11100000 MASK_R11_PORT = B00001111 IbPortPins = 2 IbIncrDecr = 3 IbMaxBright = 4 IwLEDCount = 5 IbLo_LEDCount = 5 IbHi_LEDCount = 6 IbModeSpecific1 = 7 IbModeSpecific2 = 8 IbModeSpecific3 = 9 IwUpdateInterval = 10 IbLo_UpdateInterval = 10 IbHi_UpdateInterval = 11 IwModeChangeInterval = 12 IbLo_ModeChangeInterval = 12 IbHi_ModeChangeInterval = 13 IwStartingAddress = 14 IbLo_StartingAddress = 14 IbHi_StartingAddress = 15 IwUpdateLastTime = 16 IbLo_UpdateLastTime = 16 IbHi_UpdateLastTime = 17 IwModeChangeLastTime = 18 IbLo_ModeChangeLastTime = 18 IbHi_ModeChangeLastTime = 19
Finally, add this block to the same file. Change the first line to specify which Microcontroller is in the target device. Notice that these "pull in" the files named. Please take a few minutes to examine each file to see that is being included. Some constants which differ between MCUs are also defined in this block.
PROCESSOR = 328 ; Define which MCU will be used ; All INCLUDE files should be in the same directory as this .ASM source code (or) ; use the "-I" parameter to set the AVR-AS "Include" directory where they are located: .INCLUDE "CommonDefs.Def" ; TRUE, FALSE, YES, NO, BIT_PV_*, et.al. .INCLUDE "BinDefs.Def" ; The B0 to B11111111 definitions .INCLUDE "Indices.Def" ; All 128 indirectly-accessed system jump indices .IF PROCESSOR == 328 .INCLUDE "IOM328P.Def" ; Register definitions for the ATmega328P .INCLUDE "Addresses328.Def" ; All 128 328P system routines' Jump Table addresses .INCLUDE "SystemSRAM328.Def" ; Names and addresses of 328P system SRAM variables AHeapBegins = AHeapCanBegin ; This constant name differs from others BuVarsSize = 32 ; Smallest uVars.B[##] array size is 32 BYTEs RAMEND = 0x08FF ; Address of the last byte of SRAM in 328P .ENDIF .IF PROCESSOR == 1284 .INCLUDE "IOM1284P.Def" ; Register definitions for the ATmega1284P .INCLUDE "Addresses1284.Def" ; All 128 1284P system routines' Jump Table addresses .INCLUDE "SystemSRAM1284.Def" ; Names and addresses of 1284P system SRAM variables BuVarsSize = 256 ; The uVars.B[##] array always has 256 BYTEs RAMEND = 0x40FF ; Address of the last byte of SRAM in 1284P .ENDIF .IF PROCESSOR == 2560 .INCLUDE "IOM2560.Def" ; Register definitions for the ATmega2560 .INCLUDE "Addresses2560.Def" ; All 128 2560 system routines' Jump Table addresses .INCLUDE "SystemSRAM2560.Def" ; Names and addresses of 2560 system SRAM variables BuVarsSize = 256 ; The uVars.B[##] array always has 256 BYTEs RAMEND = 0x21FF ; Address of the last byte of SRAM in 2560 .ENDIF .IFNDEF APushAllRegisters .ERROR "Exiting: definition files not pulled in." .ENDIF .INCLUDE "SystemEEPROM.Def" ; Names and addresses of system EEPROM variables .INCLUDE "SystemFLASH.Def" ; Names and addresses of system FLASH constants
Save and close the file. This SeqTemplate.Asm file is the starting initialization template included in each of the shared setup and Sequencer Mode routines which follow.
Proceed to the next webpage for the next step.