File tree Expand file tree Collapse file tree 3 files changed +3
-3
lines changed
hardware_adc/include/hardware
hardware_pio/include/hardware
hardware_pwm/include/hardware Expand file tree Collapse file tree 3 files changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ static inline void adc_run(bool run) {
204204static inline void adc_set_clkdiv (float clkdiv ) {
205205 invalid_params_if (HARDWARE_ADC , clkdiv >= 1 << (ADC_DIV_INT_MSB - ADC_DIV_INT_LSB + 1 ));
206206#if PICO_ADC_CLKDIV_ROUND_NEAREST
207- clkdiv += 0.5f / (1 << ADC_DIV_INT_LSB ); // round to the nearest fraction
207+ clkdiv += 0.5f / (1 << ( ADC_DIV_FRAC_MSB + 1 - ADC_DIV_FRAC_LSB ) ); // round to the nearest fraction
208208#endif
209209 adc_hw -> div = (uint32_t )(clkdiv * (float ) (1 << ADC_DIV_INT_LSB ));
210210}
Original file line number Diff line number Diff line change @@ -495,7 +495,7 @@ static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_
495495static inline void pio_calculate_clkdiv8_from_float (float div , uint32_t * div_int , uint8_t * div_frac8 ) {
496496 valid_params_if (HARDWARE_PIO , div >= 1 && div <= 65536 );
497497#if PICO_PIO_CLKDIV_ROUND_NEAREST
498- div += 0.5f / 256 ; // round to the nearest 1/256
498+ div += 0.5f / ( 1 << ( PIO_SM0_CLKDIV_FRAC_MSB + 1 - PIO_SM0_CLKDIV_FRAC_LSB )) ; // round to the nearest 1/256
499499#endif
500500 * div_int = (uint16_t )div ;
501501 // not a strictly necessary check, but if this changes, then this method should
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ static inline void pwm_config_set_phase_correct(pwm_config *c, bool phase_correc
161161static inline void pwm_config_set_clkdiv (pwm_config * c , float div ) {
162162 valid_params_if (HARDWARE_PWM , div >= 1.f && div < 256.f );
163163#if PICO_PWM_CLKDIV_ROUND_NEAREST
164- div += 0.5f / (1 << PWM_CH0_DIV_INT_LSB ); // round to the nearest fraction
164+ div += 0.5f / (1 << ( PWM_CH0_DIV_FRAC_MSB + 1 - PWM_CH0_DIV_FRAC_LSB ) ); // round to the nearest fraction
165165#endif
166166 c -> div = (uint32_t )(div * (float )(1u << PWM_CH0_DIV_INT_LSB ));
167167}
You can’t perform that action at this time.
0 commit comments