Skip to content

Expose PWM functions via analogWrite and friends #1

@maxgerhardt

Description

@maxgerhardt
Member

Currently calling analogWrite will attempt to write the value into the DAC peripheral, producing an exact analog voltage.

https://github.com/CommunityGD32Cores/GD32Core-New/blob/92bdf02a90e61e9a2b20ffc1adf81671175fbdc5/cores/arduino/wiring_analog.c#L127-L135

The regulard Arduino API analogWrite would start a PWM output with some default parameters (e.g., PWM frequency, PWM resolution etc.) on that pin.

The functionality should be changed so that analogWrite also starts a PWM wave and friend functions for setting resolution and frequency should be added.

Currently, PWM functionality is available via the PWM class

https://github.com/CommunityGD32Cores/GD32Core-New/blob/92bdf02a90e61e9a2b20ffc1adf81671175fbdc5/libraries/pwm/examples/pwmoutput/pwmoutput.ino#L1-L11

(and is partly not working, see #4)

The DAC functionality should still be accessible of course -- it has to be thought to which API it should be moved, or if an "auto-detection" between PWM and DAC should be made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @maxgerhardt

        Issue actions

          Expose PWM functions via `analogWrite` and friends · Issue #1 · CommunityGD32Cores/ArduinoCore-GD32