Skip to content

[FEATURE] Performance of setting the PWM duty cycles #356

Open
@Candas1

Description

@Candas1

Hi,

A topic has been on my mind last few days, thought I would socialize it to see if it's worth exploring it.

A few months back I measured it takes 48us on STM32F1 to run the setpwm function for 6PWM.
Which is more than the inverse clarke/park and svpwm combined in my case.

I think we are converting to too many different value domains:

  1. we calculate Ua Ub and Uc voltages (float)
  2. Dc_a Dc_b and Dc_c are calculated here as percentages of the power supply [0,1] (float)
  3. duty cycles are multiplied here by pwm_range to scale it to the timer resolution [0,4095] (uint32_t)
  4. duty cycles are scaled to the Auto reload register value here which is for example 72Mhz/16Khz/2 so [0,2250] in my case (uint32_t)

Few ideas:

  • a non breaking change could be to scale from [0,1] to [0,ARR+1] directly, skipping [0,4095] in point (3). This math could be adapted
  • a more complicated change would be to directly scale to [0,ARR+1] in _setPwm but we would need a way to get ARR+1 in a consistent way for all drivers (check getOverflow )
  • the arduino bloat could be skipped by directly using the Low level code in _setPwm (e.g. this is calculated each loop but is not used in our case, this also seems unnecessary).

[UPDATE]

  • commenting the arduino bloat reduced by 4us only
  • SetPhaseState seems to take 8us for 3 executions, this could be used to check if channel is running before stopping/resuming
  • converting from [0,4095] to [0,2250] is integer math so it might not be taking a lot of time

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions