Charlieplexed LEDs Setup

The update frequency must be above 50 Hz to avoid visible flickering of the LEDs. This means that the CPU needs to prioritize this task before all other tasks to get a systematic and stable LED update frequency. To achieve this the TCB0 timer is set up to use the clock from TCA0 and configured to give periodic interrupt with a frequency of 60 Hz. In addition, the TCB0 interrupt is set up to be priority level 1 interrupt to make sure that nothing can disturb the update.

Only one interrupt can be configured to level 1 at one time so the other interrupts have level 0. This means that this interrupt is always executed before other interrupts and if the device is busy servicing a different interrupt. When level 1 interrupt is triggered, the ongoing interrupt is halted, and the level 1 interrupt is executed. When this interrupt is done the core will resume the halted interrupt.

Each LED has an assigned byte in a char table in the code. Every time the priority level 1 interrupt is triggered, the CPU runs through this table. Each byte will have a value that represents the time the corresponding LED should be ON. If the value is 0, it means that this LED is not turned ON. Every module will update this table when it is necessary, to reflect the current status of the module.