Closed BlakeFreer closed 1 week ago
Do we want to use Clamper to limit the voltage between 0-5V in the Set method?
Yes there should be some clamping and it will happen at the platform level. You do not need to clamp on the cli
but will need to clamp when settings the duty cycle in the stm32
peripheral. The stm runs at 3.3, not 5V
closed by #231
PWM Output
Timeline: End of October
Background Reading
Description
PWM is a microcontroller peripheral for outputting an Analog voltage level, but it can also be used when digital signal of a specific frequency and duty cycle is required. These are fundamentally different purposes, but the
PWMOutput
peripheral inracecar/
is responsible for both roles. In this issue, you will separate the functionality into 2 classes.Current State
See
firmware/shared/periph/pwm.h
There are 4 methods on the PWM class:
Start
andStop
control whether the output is active, whileSetDutyCycle
changes the duty cycle andGetDutyCycle
returns it. This should be broken into 2 different classesClass 1:
PWMOutput
This should be identical to the current PWMOutput but with an added
SetFrequency
andGetFrequency
method which operates on floating-point frequencies measured in Hertz.Class 2:
AnalogOutput
This class is much different from the existing PWMOutput class. It has only 1 method called
Set
which takes a floating point voltage argument.Task
Stage 1: Prototype
firmware/shared/periph/analog_output.h
to define the AnalogOutput abstract class.shared/.../pwm.h
class as described aboutStage 2: Implementation
After discussing your implementation, we will apply it to the other platforms and update our existing projects.
For the stm32f767 platform, both AnalogOutput and PWMOutput will use a PWM peripheral under-the-hood. This is fine: the App-Level doesn't care how the peripherals are implemented, only that they have a specific form.