Timing
WS2812B Neopixel
T0H |
0code, high voltage time |
0.4us ±150ns |
T1H |
1code, high voltage time |
0.8us ±150ns |
T0L |
0code, low voltage time |
0.85us ±150ns |
T1L |
1code, low voltage time |
0.45us ±150ns |
RES |
low voltage time |
Above 50μs |
- 1 bit takes 1.25 us, 24 bit take 30 us
- Timer resolution 0.25 us
- MSB first
- GRB
lsls r3, r3, #1 // set carry bit
ittee cs
movwcs r5, #T1H
movtcs r5, #T1L
movwcc r5, #T0H
movtcc r5, #T0L
6 cycles.
HTML Color 0xRRGGBB
F405
Cycle = 1 / 168 MHz = 6 ns
0.4 us / 6 ns = 66.7 -> max. 66 cycles
Timer Resolution = 1 / 42 MHz = 23.8 ns
#define T0H 15 // 0.4 us, 0.4 us / 23.8 ns = 16.8
#define T1H 32 // 0.8 us, 33.6
#define T0L 34 // 0.85 us, 35.7
#define T1L 17 // 0.45 us, 18.9
#define TRES 420 // 10 us, 420
max. deviation = timer_resolution + 2 cycles = 23.8 ns + 2 * 6 ns = 35.8 ns
WB55
Cycle = 1 / 32 MHz = 31.25 ns
0.4 us / 31.25 ns = 12.8 -> max 12 cycles
Timer Resolution = 1 / 32 MHz = 31.25 ns
#define T0H 11 // 0.4 us, 0.4 us / 31.25 ns = 12.8
#define T1H 24 // 0.8 us, 25.6
#define T0L 26 // 0.85 us, 27.4
#define T1L 13 // 0.45 us, 14.5
#define TRES 323 // 10 us, 323
max. deviation = timer_resolution + 2 cycles = 31.25 ns ns + 2 * 31.25 ns = 93.75 ns
Set/Reset Portpin
GPIO port bit set/reset register GPIOx_BSRR
- Address offset: 0x18, x = A..K, D8 = PC0
- bit0 .. bit15 bit set
- bit16 .. bit31 bit reset
#define GPIOC_BASE (AHB1PERIPH_BASE + 0x0800UL)
#define AHB1PERIPH_BASE (PERIPH_BASE + 0x00020000UL)
#define PERIPH_BASE 0x40000000UL /*!< Peripheral base address in the alias region */
GPIOC->BSRR
Timer
TIM6
Set Counter
TIM6->CNT;
Set Time Period
TIM6->ARR; // autoreload
Clear Update Flag
TIM6->SR; // UIF update interrupt flag
Enable/Disable Timer Interrupt
TIM6->DIER; // UIE update interrupt enable
Start/Stop Timer
TIM6->CR1; // UDIS update disable, CEN counter enable