|
STC15W408AS library 0.17.0
|
Implementation of timer to milliseconds conversion using lookup tables. More...

Functions | |
| void | timer0_1ms_delay_init () |
| Initializes Timer0 for 1 millisecond delay using precalculated ticks. | |
| void | timer0_1ms_delay () |
| Executes a 1 millisecond delay using Timer0. | |
Variables | |
| uint16_t | precalc_1t_ticks [8] |
| Precalculated timer ticks for 1ms delay in 1T mode. | |
| uint16_t | precalc_12t_ticks [8] |
| Precalculated timer ticks for 1ms delay in 12T mode. | |
Implementation of timer to milliseconds conversion using lookup tables.
This file provides the implementation for fast millisecond to tick conversion using precalculated lookup tables. The tables contain precomputed values for 1 millisecond delays at various system clock frequencies and divider settings.
Lookup table organization:
Each array has 8 elements, with the index corresponding to the frequency scale divider (from CLK_DIV register bits [0..2]). The frequency scale ranges from 0 to 7, corresponding to clock dividers of 1, 2, 4, 8, 16, 32, 64, and 128.
The precalculated values are derived from the formula: ticks = (SYSclk / divider) * 0.001
Where SYSclk = MAIN_Fosc / (2^divider_scale)
Example calculations for 11,059,200 Hz crystal:
| void timer0_1ms_delay | ( | ) |
Executes a 1 millisecond delay using Timer0.
Starts Timer0 and waits for the overflow flag (TF0) to be set, indicating that the configured 1ms time interval has elapsed. The timer is configured by timer0_1ms_delay_init() with the appropriate reload values for the system clock frequency.
| void timer0_1ms_delay_init | ( | ) |
Initializes Timer0 for 1 millisecond delay using precalculated ticks.
| uint16_t precalc_12t_ticks[8] |
Precalculated timer ticks for 1ms delay in 12T mode.
Array index corresponds to frequency scale divider (CLK_DIV bits [0..2])
These values represent the number of timer ticks required for a 1 millisecond delay when the timer is configured in 12T mode (twelve clock cycles per tick). The array index is determined by the system clock frequency scale setting.
Index mapping:
| uint16_t precalc_1t_ticks[8] |
Precalculated timer ticks for 1ms delay in 1T mode.
Array index corresponds to frequency scale divider (CLK_DIV bits [0..2])
These values represent the number of timer ticks required for a 1 millisecond delay when the timer is configured in 1T mode (one clock cycle per tick). The array index is determined by the system clock frequency scale setting.
Index mapping: