PER Firmware
Loading...
Searching...
No Matches
pwm.c File Reference

Public PWM driver interface for STM32G4. More...

#include <stddef.h>
#include "common/phal_G4/pwm/pwm.h"
#include "common/phal_G4/pwm/pwm_priv.h"
Include dependency graph for pwm.c:

Functions

bool PHAL_PWM_init (TIM_TypeDef *tim, uint32_t frequency_hz, uint8_t channels_en)
 Initialize consecutive PWM channels beginning at channel 1.
 
bool PHAL_PWM_setPercent (TIM_TypeDef *tim, uint8_t channel, uint8_t percent)
 Set a PWM channel's duty cycle.
 

Detailed Description

Public PWM driver interface for STM32G4.

Author
Natasha Pandit (npand.nosp@m.it@p.nosp@m.urdue.nosp@m..edu)

Function Documentation

◆ PHAL_PWM_init()

bool PHAL_PWM_init ( TIM_TypeDef * tim,
uint32_t frequency_hz,
uint8_t channels_en )

Initialize consecutive PWM channels beginning at channel 1.

Configures the selected timer to generate PWM at the requested frequency and enables channels 1 through channels_en.

Parameters
timTimer peripheral.
frequency_hzRequested PWM frequency.
channels_enChannels to enable.
Returns
true if initialized properly; false if tim is NULL, frequency_hz is 0, or initialization fails.

Auto-reload value providing 100 duty-cycle steps.

Number of timer counts in one PWM period.

Divisor needed to produce the requested PWM frequency.

Required timer clock divider.

Prescalar register value corresponding to the clock divider.

Here is the call graph for this function:

◆ PHAL_PWM_setPercent()

bool PHAL_PWM_setPercent ( TIM_TypeDef * tim,
uint8_t channel,
uint8_t percent )

Set a PWM channel's duty cycle.

Parameters
timTimer peripheral.
channelSpecific channel to set duty cycle of.
percentDuty cycle percentage to set, 0-100.
Returns
true if duty cycle is set properly; false if tim is NULL or setting cycle fails.

Configured timer auto-reload value.

Capture/compare value corresponding to requested duty cycle.

Here is the call graph for this function: