Skip to content

Commit

Permalink
Fix issue #115 - add clock settings for overclocked RP2040
Browse files Browse the repository at this point in the history
  • Loading branch information
board707 committed Aug 23, 2024
1 parent 2251ca3 commit 539b6f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 9 additions & 6 deletions DMD_STM32a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions DMD_STM32a.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 539b6f2

Please sign in to comment.