PWM Out

PWM Out driver for Zero-Pilot 3.5.

Class PWM_Channel

Constructor:

PWMChannel(TIM_HandleTypeDef* timer, uint16_t timerChannel);
  • Arguments as a pointer to the timer channel, and the timer channel pin

  • Example usage below. Names the class instance as ‘pwmchannel’ and starts it on timer 2, channel 1.

PWMChannel pwmchannel(&htim2, TIM_CHANNEL_1);
  • The constructor will automatically set a pre-scaler based on the micro-controller system clock frequency. To do this, it takes the existing counter period set in the IOC file

 

Set Percent Member Function

void set(uint8_t percent);

Classes

  • Header file, constants

    • constexpr pwm period:20000

      • This is the microsecond period, our pwm cycle will only count up to 20000 MICROSECONDS

      • You should probably change your timer counts in the STM32 ioc file to be like 20000, I need to do the math for the prescaler if there is any

    • constexpr min signal: 950

      • Counts required for a 5% duty cycle (more so actually 4.75, but we want a margin of error)

    • contexpr max signal:2050

      • counts for a 10% duty cycle(9.75, same reason we dont do exactly 10)

    • Ticks is user defined

      • Corresponds to the total ticks per period

        • Alternatively, the source file converts this to the active ticks in the used cycle

  • This gives us a margin of 100 microseconds, which is essentially a couple heartz, idk rn