Skip to content

ESP32 mcpwm_get_frequency: division by zero #76

@jkirsons

Description

@jkirsons

Problem
This line causes a division by zero when running the code on an ESP32:

mcpwm_init(mcpwm_unit, MCPWM_TIMER_0, &pwm_config); //Configure PWM0A & PWM0B with above settings

Cause
The ESP32 Arduino Release 1.0.6 uses ESP-IDF 3.3.5
In ESP-IDF 3.3 in mcpwm.c, function mcpwm_set_frequency() called by mcpwm_init() does a division by frequency:
https://github.com/espressif/esp-idf/blob/7c86027531ebffe937c9d9d1080cd433eb993f35/components/driver/mcpwm.c#L143

Possible Resolution
To correct this, can we set pwm_config.frequency before calling mcpwm_init() ? Eg add this immediately before:
pwm_config.frequency = pwm_frequency;

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