-
Notifications
You must be signed in to change notification settings - Fork 2
PwmService
Daniel Johnson edited this page Jul 9, 2021
·
7 revisions
The PwmService is a basic hardware abstraction to Read and Write to PWM pins. All functions are passed down to the underlying abstraction.
Initializes a pin in the selected direction, either In or Out. Configuring the pin as In will set the pin as a high impedance input. minFrequency is the minimum frequency expected to either be output, or read in. That is used to setup the timer appropriately.
Returns the period and the pulse width of the pin.
Writes the period and pulse width to be output on the pin.
IPwmService *_pwmService;
// Initialize LED pin
_pwmService->InitPin(45, PinDirection::Out, 100); //PC13 as Output 100 hz PWM pin
// Initialize input pin
_pwmService->InitPin(0, PinDirection::In, 100); //PA0 as Input 10 hz PWM pin
// Read pwm pin
PwmValue inputPwm = _pwmService->ReadPin(0);
// Set PWM duty cycle to the input pulsewidth ranging between 0.01 and 0.09
_pwmService->WritePin(45, { 0.01, 0.1 * inputPwm.PulseWidth });