diff options
| author | David Hoelscher <infinityis@users.noreply.github.com> | 2024-10-28 01:29:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-27 23:29:43 -0700 |
| commit | 7630a80791f0518e33145df52242f95184d16023 (patch) | |
| tree | c340a3914f1acb06799d9d783e0d754520b471bb /platforms | |
| parent | 2c0cdcf7b2f57caf2ab842e44b8bc58a52251fcb (diff) | |
Change default ARM hardware PWM WS2812 tick frequency to 800kHz (#24508)
Diffstat (limited to 'platforms')
| -rw-r--r-- | platforms/chibios/drivers/ws2812_pwm.c | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c index dc0e309163..c46e9171ab 100644 --- a/platforms/chibios/drivers/ws2812_pwm.c +++ b/platforms/chibios/drivers/ws2812_pwm.c | |||
| @@ -79,15 +79,15 @@ | |||
| 79 | # endif | 79 | # endif |
| 80 | #endif | 80 | #endif |
| 81 | 81 | ||
| 82 | #ifndef WS2812_PWM_TARGET_PERIOD | 82 | // Default is 800000Hz, which has a period of 1.25us |
| 83 | //# define WS2812_PWM_TARGET_PERIOD 800000 // Original code is 800k...? | 83 | #ifndef WS2812_PWM_FREQUENCY |
| 84 | # define WS2812_PWM_TARGET_PERIOD 80000 // TODO: work out why 10x less on f303/f4x1 | 84 | # define WS2812_PWM_FREQUENCY (1000000000 / WS2812_TIMING) |
| 85 | #endif | 85 | #endif |
| 86 | 86 | ||
| 87 | /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ | 87 | /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ |
| 88 | 88 | ||
| 89 | #define WS2812_PWM_FREQUENCY (CPU_CLOCK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */ | 89 | #define WS2812_PWM_TICK_FREQUENCY (CPU_CLOCK / 2) /**< Clock frequency of PWM ticks, must be valid with respect to system clock! */ |
| 90 | #define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */ | 90 | #define WS2812_PWM_PERIOD (WS2812_PWM_TICK_FREQUENCY / WS2812_PWM_FREQUENCY) /**< Clock period in PWM ticks. */ |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| 93 | * @brief Number of bit-periods to hold the data line low at the end of a frame | 93 | * @brief Number of bit-periods to hold the data line low at the end of a frame |
| @@ -102,37 +102,16 @@ | |||
| 102 | 102 | ||
| 103 | /** | 103 | /** |
| 104 | * @brief High period for a zero, in ticks | 104 | * @brief High period for a zero, in ticks |
| 105 | * | ||
| 106 | * Per the datasheet: | ||
| 107 | * WS2812: | ||
| 108 | * - T0H: 200 nS to 500 nS, inclusive | ||
| 109 | * - T0L: 650 nS to 950 nS, inclusive | ||
| 110 | * WS2812B: | ||
| 111 | * - T0H: 200 nS to 500 nS, inclusive | ||
| 112 | * - T0L: 750 nS to 1050 nS, inclusive | ||
| 113 | * | ||
| 114 | * The duty cycle is calculated for a high period of 350 nS. | ||
| 115 | */ | 105 | */ |
| 116 | #define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY / (1000000000 / 350)) | 106 | #define WS2812_DUTYCYCLE_0 (WS2812_PWM_TICK_FREQUENCY / (1000000000 / WS2812_T0H)) |
| 117 | #if (WS2812_DUTYCYCLE_0 > 255) | 107 | #if (WS2812_DUTYCYCLE_0 > 255) |
| 118 | # error WS2812 PWM driver: High period for a 0 is more than a byte | 108 | # error WS2812 PWM driver: High period for a 0 is more than a byte |
| 119 | #endif | 109 | #endif |
| 120 | 110 | ||
| 121 | /** | 111 | /** |
| 122 | * @brief High period for a one, in ticks | 112 | * @brief High period for a one, in ticks |
| 123 | * | ||
| 124 | * Per the datasheet: | ||
| 125 | * WS2812: | ||
| 126 | * - T1H: 550 nS to 850 nS, inclusive | ||
| 127 | * - T1L: 450 nS to 750 nS, inclusive | ||
| 128 | * WS2812B: | ||
| 129 | * - T1H: 750 nS to 1050 nS, inclusive | ||
| 130 | * - T1L: 200 nS to 500 nS, inclusive | ||
| 131 | * | ||
| 132 | * The duty cycle is calculated for a high period of 800 nS. | ||
| 133 | * This is in the middle of the specifications of the WS2812 and WS2812B. | ||
| 134 | */ | 113 | */ |
| 135 | #define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY / (1000000000 / 800)) | 114 | #define WS2812_DUTYCYCLE_1 (WS2812_PWM_TICK_FREQUENCY / (1000000000 / WS2812_T1H)) |
| 136 | #if (WS2812_DUTYCYCLE_1 > 255) | 115 | #if (WS2812_DUTYCYCLE_1 > 255) |
| 137 | # error WS2812 PWM driver: High period for a 1 is more than a byte | 116 | # error WS2812 PWM driver: High period for a 1 is more than a byte |
| 138 | #endif | 117 | #endif |
| @@ -322,7 +301,7 @@ void ws2812_init(void) { | |||
| 322 | // PWM Configuration | 301 | // PWM Configuration |
| 323 | //#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config | 302 | //#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config |
| 324 | static const PWMConfig ws2812_pwm_config = { | 303 | static const PWMConfig ws2812_pwm_config = { |
| 325 | .frequency = WS2812_PWM_FREQUENCY, | 304 | .frequency = WS2812_PWM_TICK_FREQUENCY, |
| 326 | .period = WS2812_PWM_PERIOD, // Mit dieser Periode wird UDE-Event erzeugt und ein neuer Wert (Länge WS2812_BIT_N) vom DMA ins CCR geschrieben | 305 | .period = WS2812_PWM_PERIOD, // Mit dieser Periode wird UDE-Event erzeugt und ein neuer Wert (Länge WS2812_BIT_N) vom DMA ins CCR geschrieben |
| 327 | .callback = NULL, | 306 | .callback = NULL, |
| 328 | .channels = | 307 | .channels = |
