Contiki-NG
Loading...
Searching...
No Matches

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.
 

Detailed Description

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+.

Function Documentation

◆ pwm_disable()

int8_t pwm_disable ( uint8_t timer,
uint8_t ab,
uint8_t port,
uint8_t pin )

Disables a previously PWM configured GPTn.

Parameters
timerGeneral purpose timer to disable [0-3]
abSelect which timer to disable (Timer A or B)
portPort number used as PWM to disable (set as input GPIO)
pinPin number used as PWM to disable (set as input GPIO)
Returns
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().

◆ pwm_enable()

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.

Parameters
freqPWM frequency (in Hz)
dutyPWM duty cycle (percentage in integers)
countPWM duty cycle (count number)
timerGeneral purpose timer to use [0-3]
abSelect which timer to use (Timer A or B)
Returns
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().

◆ pwm_set_direction()

int8_t pwm_set_direction ( uint8_t timer,
uint8_t ab,
uint8_t dir )

Sets the PWM duty cycle signal direction (high/low)

Parameters
timerGeneral purpose timer [0-3]
abSelect which timer to use (Timer A or B)
dirDirection of the PWM signal, PWM_SIGNAL_INVERTED or PWM_SIGNAL_STRAIGHT
Returns
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.

◆ pwm_start()

int8_t pwm_start ( uint8_t timer,
uint8_t ab,
uint8_t port,
uint8_t pin )

Once configured, starts the PWM.

Parameters
timerGeneral purpose timer to start [0-3]
abSelect which timer to start (Timer A or B)
portPort number to use as PWM
pinPin number to use as PWM
Returns
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().

◆ pwm_stop()

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.

Parameters
timerGeneral purpose timer to stop [0-3]
abSelect which timer to stop (Timer A or B)
portPort of the gpio port mapped to the PWM to stop
pinPin of the gpio port mapped to the PWM to stop
stateState to leave the pin once stopped, on (1) or off (0)
Returns
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().

◆ pwm_toggle_direction()

int8_t pwm_toggle_direction ( uint8_t timer,
uint8_t ab )

Toggle the PWM signal direction (inverts the current duty cycle)

Parameters
timerGeneral purpose timer to use [0-3]
abSelect which timer to use (Timer A or B)
Returns
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.