Skip to content

Limitations to PWM frequency? #32

Open
@radwouters

Description

I don't know if the following is an issue specific to the implementation in this HAL, or that it is a limitation in the chip, so please let me know if this issue is in the wrong place.

For a project in which I am sending 38 kHz NEC messages on a CH32V003F4P6 dev board, I am using SimplePWM to generate a 38 kHz PWM signal and then modulate this by calling pwm.enable and pwm.disable, as follows:

    let mut pwm = SimplePwm::new(
        p.TIM1,
        None,
        None,
        None,
        Some(pin),
        Hertz::khz(38),
        CountingMode::default(),
    );
    let ch = hal::timer::Channel::Ch4;

    // Futher, in the loop to send bits:
    pwm.enable(ch);
    Delay.delay_us(563);
    pwm.disable(ch);
    if bit == 0 {
        Delay.delay_us(563);
    } else {
        Delay.delay_us(1688);
    }

When looking at an oscilloscope connected to the output pin, it looks as follows:
pic_49_1
pic_49_2

Is this a limitation of the CH32V003? That seems unlikely to me, given that the clock of a CH32V003 is about 1000 times higher than the signal frequency? Did I configure the PWM wrong?

I see that in the WS2811 example the signal is bitbanged in code as well, was that done for the same reason?

If any additional information is needed, please let me know :) And thanks for the great work on this project!

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