tm1637: set frequency to 50 kHz because of capacitance
This commit is contained in:
parent
183cacf730
commit
663491db61
|
@ -178,7 +178,7 @@ void led_tm1637_setup(void)
|
|||
timer_reset(TIM(LED_TM1637_TIMER)); // reset timer state
|
||||
timer_set_mode(TIM(LED_TM1637_TIMER), TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // set timer mode, use undivided timer clock, edge alignment (simple count), and count up
|
||||
timer_set_prescaler(TIM(LED_TM1637_TIMER), 0); // don't prescale to get most precise timing ( 1/(72E6/1/(2**16))=0.91 ms > 0.5 us )
|
||||
timer_set_period(TIM(LED_TM1637_TIMER), 500); // set the clock frequency (500 kHz is the maximum per datasheet, but also because of the bit banging implementation)
|
||||
timer_set_period(TIM(LED_TM1637_TIMER), rcc_ahb_frequency/50000/2); // set the clock frequency to 50 kHz (500 kHz is the maximum per datasheet, but 50 kHz is empirically more stable due to the line capacitance of the multiple displays)
|
||||
timer_clear_flag(TIM(LED_TM1637_TIMER), TIM_SR_UIF); // clear flag
|
||||
timer_update_on_overflow(TIM(LED_TM1637_TIMER)); // only use counter overflow as UEV source (use overflow as start time or timeout)
|
||||
}
|
||||
|
@ -205,12 +205,12 @@ static bool led_tm1637_write(const uint8_t* data, uint8_t length)
|
|||
}
|
||||
|
||||
// enable timer for signal generation
|
||||
gpio_set_mode(GPIO(LED_TM1637_DIO_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_TM1637_DIO_PIN)); // ensure we can output to sent start condition
|
||||
timer_set_counter(TIM(LED_TM1637_TIMER), 0); // reset timer counter
|
||||
timer_enable_counter(TIM(LED_TM1637_TIMER)); // enable timer to generate timing
|
||||
led_tm1637_tick(); // wait to enforce minimum time since last write
|
||||
|
||||
// send start condition (DIO then CLK low)
|
||||
gpio_set_mode(GPIO(LED_TM1637_DIO_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_TM1637_DIO_PIN)); // ensure we can output to sent start condition
|
||||
gpio_clear(GPIO(LED_TM1637_DIO_PORT), GPIO(LED_TM1637_DIO_PIN)); // put DIO low
|
||||
led_tm1637_tick(); // wait for next tick
|
||||
gpio_clear(GPIO(LED_TM1637_CLK_PORT), GPIO(LED_TM1637_CLK_PIN)); // put CLK low
|
||||
|
|
Loading…
Reference in New Issue