Skip to content

[embassy-nrf]: Unexpected behavior of SimplePwm set_duty: Higher values result in lower duty cycle #4645

@jmjoy

Description

@jmjoy

When testing embassy-nrf on nrf52840, I found that the set_duty method of SimplePwm seems to behave unexpectedly. Specifically, the higher the value set by set_duty, the lower the actual PWM duty cycle output. Here is a minimal example:

let mut pwm = SimplePwm::new_1ch(p.PWM1, p.P0_13);
pwm.set_prescaler(embassy_nrf::pwm::Prescaler::Div1);
pwm.set_max_duty(32767);
pwm.set_duty(0, 10000);
pwm.enable();

I connected an LED with its anode to P0_13 and cathode to GND. When I increase the value of set_duty, the LED becomes dimmer (i.e., the output duty cycle actually decreases).

I am unsure if this is a misunderstanding on my part, or if it is specific to my board or setup. My expectation is that increasing the value passed to set_duty should increase the duty cycle (i.e., the output should be "on" for a longer portion of each cycle). Is this the intended behavior, or is there something I am missing?

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