From 539b6f2a04b6f1e5d972b74b1d4ca4d00bb65387 Mon Sep 17 00:00:00 2001 From: board707 <50185434+board707@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:44:26 +0300 Subject: [PATCH] Fix issue #115 - add clock settings for overclocked RP2040 --- DMD_STM32a.cpp | 15 +++++++++------ DMD_STM32a.h | 8 +++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/DMD_STM32a.cpp b/DMD_STM32a.cpp index f0156e2..2b317c7 100644 --- a/DMD_STM32a.cpp +++ b/DMD_STM32a.cpp @@ -143,15 +143,18 @@ void DMD::initialize_timers(voidFuncPtr handler) { /*--------------------------------------------------------------------------------------*/ void DMD::initialize_timers(voidFuncPtr handler) { - + // test PWM WRAP for overflow + if ((this->scan_cycle_len * 4 / this->pwm_clk_div) > TIM_MAX_RELOAD) { + this->pwm_clk_div = 1 + (this->scan_cycle_len * 4 / TIM_MAX_RELOAD); + } this->scan_cycle_len = this->scan_cycle_len / this->pwm_clk_div; - - - - + // Adjust pio clk divider to not overflow panel CLK > 15 MHz + if (CYCLES_PER_MICROSECOND/ (4* this->pio_clkdiv) > MAX_PANEL_CLK) { + this->pio_clkdiv = 1+ CYCLES_PER_MICROSECOND/ (4* MAX_PANEL_CLK); + } - //pio configs + //pio configs sm_data = pio_claim_unused_sm(pio, true); //data_prog_offs = pio_add_program(pio, &dmd_out_program); data_prog_offs = pio_add_dmd_out_program(pio, this->data_pins_cnt); diff --git a/DMD_STM32a.h b/DMD_STM32a.h index 574099b..091f445 100644 --- a/DMD_STM32a.h +++ b/DMD_STM32a.h @@ -3,7 +3,7 @@ /*-------------------------------------------------------------------------------------- DMD_STM32a.h - advansed version of DMD_STM32.h - ****** VERSION 1.1.3 ****** + ****** VERSION 1.1.0 ****** DMD_STM32.h - STM32 port of DMD.h library @@ -63,6 +63,8 @@ typedef uint32 PortType; #define TIM_MAX_RELOAD ((1 << 16) - 1) enum OE_PWM_Polarity{ OE_PWM_POSITIVE = TIMER_OC_MODE_PWM_1, OE_PWM_NEGATIVE = TIMER_OC_MODE_PWM_2 }; #elif (defined(ARDUINO_ARCH_RP2040)) +#define TIM_MAX_RELOAD ((1 << 16) - 1) +#define MAX_PANEL_CLK 15 enum OE_PWM_Polarity { OE_PWM_POSITIVE = false, OE_PWM_NEGATIVE = true }; typedef uint16_t PortType; #endif @@ -466,10 +468,10 @@ class DMD : public Adafruit_GFX PIO pio = pio0; uint8_t sm_data = 0; uint8_t sm_mux = 1; - const uint8_t pwm_clk_div = 10; + uint8_t pwm_clk_div = 10; uint16_t data_prog_offs = 0; pio_sm_config pio_config; - const uint8_t pio_clkdiv = 3; + uint8_t pio_clkdiv = 3; #endif