Class Pwm

Class Documentation

class Pwm

PWM input pins are pins S, T, U, and V (board pins PAO, PA1, PA2, PA3) To write a PWM frequency to a pin call write and pass the function a value (W - Z) from the analog outPin enum and a PWM duty from 0.0-1.0 (where 1 is all HIGH and 0 is all LOW). To set the duty for all pins call the writeAll function with only the duty.

Public Types

enum Pin

Values:

enumerator C1
enumerator C2
enumerator C3
enumerator C4
enumerator C5
enumerator C6
enumerator C7
enumerator Buzzer
enumerator ImuHeater
enum Timer

Values:

enumerator TIMER1
enumerator TIMER8
enumerator TIMER4
enumerator TIMER10

Public Functions

Pwm() = default
mockable ~Pwm() = default
mockable void init ()
mockable void writeAllZeros ()

Sets all configured timer channels to 0% duty cycle.

mockable void write (float duty, Pwm::Pin pin)

Sets the PWM duty for a specified pin.

Parameters:
  • duty[in] the duty cycle to be set. If the duty is outside of the range of [0, 1] the duty is limited to within the range.

  • pin[in] the PWM pin to be set.

mockable void setTimerFrequency (Timer timer, uint32_t frequency)

Set the frequency of the timer, in Hz. Does nothing if frequency == 0

mockable void pause (Timer timer)
mockable void start (Timer timer)

Public Static Attributes

static constexpr uint32_t DEFAULT_TIMER1_FREQUENCY = 2000
static constexpr uint32_t DEFAULT_TIMER8_FREQUENCY = 2000
static constexpr uint32_t DEFAULT_TIMER4_FREQUENCY = 2000
static constexpr uint32_t DEFAULT_TIMER10_FREQUENCY = 2000