Contiki-NG
|
Files | |
file | pwm.c |
Driver for the CC2538 PWM. | |
file | pwm.h |
Header file for the CC2538 PWM driver. | |
PWM functions | |
int8_t | pwm_enable (uint32_t freq, uint8_t duty, uint32_t count, uint8_t timer, uint8_t ab) |
Configures the general purpose timer in PWM mode. | |
int8_t | pwm_stop (uint8_t timer, uint8_t ab, uint8_t port, uint8_t pin, uint8_t state) |
Halts the PWM in a given GPT/timer. | |
int8_t | pwm_start (uint8_t timer, uint8_t ab, uint8_t port, uint8_t pin) |
Once configured, starts the PWM. | |
int8_t | pwm_set_direction (uint8_t timer, uint8_t ab, uint8_t dir) |
Sets the PWM duty cycle signal direction (high/low) | |
int8_t | pwm_toggle_direction (uint8_t timer, uint8_t ab) |
Toggle the PWM signal direction (inverts the current duty cycle) | |
int8_t | pwm_disable (uint8_t timer, uint8_t ab, uint8_t port, uint8_t pin) |
Disables a previously PWM configured GPTn. | |
Driver for the CC2538 PWM on GPTIMER
The driver uses the timers A and B of the general purpose timers to create a PWM signal, allowing to set a duty cycle value from 1-100%. This implementation relies on having a peripheral clock of 16MHz, but it can be easily changed (see PWM_FREQ_MIN and PWM_FREQ_MAX values). The reason it is fixed to these frequencies is to have a consistent duty cycle implementation.
Depending on the specific needs these limits can be changed to meet a given duty cycle and lower frequencies by using the prescaler (GPTIMER_TnPR).
Running a PWM timer prevents the LPM driver from dropping to PM1+.
int8_t pwm_disable | ( | uint8_t | timer, |
uint8_t | ab, | ||
uint8_t | port, | ||
uint8_t | pin ) |
Disables a previously PWM configured GPTn.
timer | General purpose timer to disable [0-3] |
ab | Select which timer to disable (Timer A or B) |
port | Port number used as PWM to disable (set as input GPIO) |
pin | Pin number used as PWM to disable (set as input GPIO) |
PWM_SUCCESS
if successful, else PWM_ERROR
This function disables a specific timer (A or B) and reset related registers to default values. The user must explicitely pass the port/pin number of the pin to disable as PWM and to be configured as input GPIO. The module clock is not disabled with this function
Definition at line 330 of file pwm.c.
References GPIO_D_NUM, GPIO_PIN_MASK, GPIO_PORT_TO_BASE, GPIO_SET_INPUT, GPIO_SOFTWARE_CONTROL, GPTIMER_TAILR, GPTIMER_TAMATCHR, GPTIMER_TAMR, IOC_OVERRIDE_DIS, ioc_set_over(), and pwm_stop().
Referenced by servo_stop().
int8_t pwm_enable | ( | uint32_t | freq, |
uint8_t | duty, | ||
uint32_t | count, | ||
uint8_t | timer, | ||
uint8_t | ab ) |
Configures the general purpose timer in PWM mode.
freq | PWM frequency (in Hz) |
duty | PWM duty cycle (percentage in integers) |
count | PWM duty cycle (count number) |
timer | General purpose timer to use [0-3] |
ab | Select which timer to use (Timer A or B) |
PWM_SUCCESS
if successful, else PWM_ERROR
Definition at line 93 of file pwm.c.
References count, GPTIMER_CFG, GPTIMER_CTL, GPTIMER_CTL_TAEN, GPTIMER_CTL_TAPWML, GPTIMER_CTL_TBEN, GPTIMER_CTL_TBPWML, GPTIMER_TAILR, GPTIMER_TAMATCHR, GPTIMER_TAMR, GPTIMER_TAMR_TAAMS, GPTIMER_TAPMR, GPTIMER_TAPR, SYS_CTRL_DCGCGPT, SYS_CTRL_DCGCGPT_GPT0, sys_ctrl_get_sys_clock(), SYS_CTRL_RCGCGPT, SYS_CTRL_RCGCGPT_GPT0, SYS_CTRL_SCGCGPT, and SYS_CTRL_SCGCGPT_GPT0.
Referenced by servo_position().
int8_t pwm_set_direction | ( | uint8_t | timer, |
uint8_t | ab, | ||
uint8_t | dir ) |
Sets the PWM duty cycle signal direction (high/low)
timer | General purpose timer [0-3] |
ab | Select which timer to use (Timer A or B) |
dir | Direction of the PWM signal, PWM_SIGNAL_INVERTED or PWM_SIGNAL_STRAIGHT |
PWM_SUCCESS
if successful, else PWM_ERROR
Definition at line 274 of file pwm.c.
References GPTIMER_CTL, GPTIMER_CTL_TAPWML, and GPTIMER_CTL_TBPWML.
int8_t pwm_start | ( | uint8_t | timer, |
uint8_t | ab, | ||
uint8_t | port, | ||
uint8_t | pin ) |
Once configured, starts the PWM.
timer | General purpose timer to start [0-3] |
ab | Select which timer to start (Timer A or B) |
port | Port number to use as PWM |
pin | Pin number to use as PWM |
PWM_SUCCESS
if successful, else PWM_ERROR
Definition at line 235 of file pwm.c.
References GPIO_D_NUM, GPIO_PERIPHERAL_CONTROL, GPIO_PIN_MASK, GPIO_PORT_TO_BASE, GPTIMER_CTL, GPTIMER_CTL_TAEN, GPTIMER_CTL_TBEN, IOC_OVERRIDE_OE, ioc_set_over(), and ioc_set_sel().
Referenced by servo_position().
int8_t pwm_stop | ( | uint8_t | timer, |
uint8_t | ab, | ||
uint8_t | port, | ||
uint8_t | pin, | ||
uint8_t | state ) |
Halts the PWM in a given GPT/timer.
timer | General purpose timer to stop [0-3] |
ab | Select which timer to stop (Timer A or B) |
port | Port of the gpio port mapped to the PWM to stop |
pin | Pin of the gpio port mapped to the PWM to stop |
state | State to leave the pin once stopped, on (1) or off (0) |
PWM_SUCCESS
if successful, else PWM_ERROR
Definition at line 190 of file pwm.c.
References GPIO_CLR_PIN, GPIO_D_NUM, GPIO_PIN_MASK, GPIO_PORT_TO_BASE, GPIO_SET_OUTPUT, GPIO_SET_PIN, GPIO_SOFTWARE_CONTROL, GPTIMER_CTL, GPTIMER_CTL_TAEN, GPTIMER_CTL_TBEN, IOC_OVERRIDE_DIS, and ioc_set_over().
Referenced by pwm_disable().
int8_t pwm_toggle_direction | ( | uint8_t | timer, |
uint8_t | ab ) |
Toggle the PWM signal direction (inverts the current duty cycle)
timer | General purpose timer to use [0-3] |
ab | Select which timer to use (Timer A or B) |
PWM_SUCCESS
if successful, else PWM_ERROR
Definition at line 302 of file pwm.c.
References GPTIMER_CTL, GPTIMER_CTL_TAPWML, and GPTIMER_CTL_TBPWML.