Skip to content

Commit b9b4460

Browse files
committed
Clamp timer resolution to not be greater than timer group resolution
1 parent bcea5c1 commit b9b4460

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/mcpwm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,15 @@ where
870870
esp!(ESP_ERR_INVALID_ARG)?;
871871
}
872872

873-
if config.lowest_frequency > mcpwm_module.borrow().operator_source_frequency.Hz() {
873+
let operator_source_frequency = mcpwm_module.borrow().operator_source_frequency;
874+
if config.lowest_frequency > operator_source_frequency.Hz() {
874875
// Can not specify a lowest_frequency larger than the corresponding value for
875876
// the parent MCPWM module. Use `Mcpwm::lowest_frequency` to enable higher frequencies
876877
esp!(ESP_ERR_INVALID_ARG)?;
877878
}
878879

879880
let resolution = u32::from(config.lowest_frequency) * MAX_PWM_TIMER_PERIOD;
881+
let resolution = resolution.min(operator_source_frequency);
880882
unsafe {
881883
esp_idf_sys::mcpwm_timer_set_resolution(U::unit(), O::timer(), resolution);
882884
}

0 commit comments

Comments
 (0)