Skip to content

How to safely change PWM frequency(or arr) after finalize()? #530

@Joker2770

Description

@Joker2770

It seems that there is no relevant function about changing PWM frequency after the finalize() be called.
I use the unsafe way at present. I don't know if it is logical as follow.

    let pwm_t4_c3_builder = dp.TIM4.pwm_advanced(...);
    let (_, mut pwm_t4_c3_ctrl) = pwm_t4_c3_builder
        .prescaler(...)
        .period(...)
        .finalize();
    pwm_t4_c3_ctrl.set_duty(...);
    pwm_t4_c3_ctrl.enable();

    // change arr
    let tim_4 = unsafe { &*<pac::TIM4>::ptr() };
    let _ = tim_4.arr.write(|w| w.arr().bits(...));

Somehow the duty and cycle need to be change continuously at runtime. Is there a safe and efficient way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions