MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
Timer (TMR)

Modules

 TMR_Registers
 Registers, Bit Masks and Bit Positions for the TMR Peripheral Module.
 
 Timer Utility Functions
 

Data Structures

struct  tmr_cfg_t
 Timer Configuration. More...
 
struct  tmr_pwm_cfg_t
 Timer PWM Configuration. More...
 

Enumerations

enum  tmr_pres_t {
  TMR_PRES_1 = MXC_S_TMR_CN_PRES_DIV1,
  TMR_PRES_2 = MXC_S_TMR_CN_PRES_DIV2,
  TMR_PRES_4 = MXC_S_TMR_CN_PRES_DIV4,
  TMR_PRES_8 = MXC_S_TMR_CN_PRES_DIV8,
  TMR_PRES_16 = MXC_S_TMR_CN_PRES_DIV16,
  TMR_PRES_32 = MXC_S_TMR_CN_PRES_DIV32,
  TMR_PRES_64 = MXC_S_TMR_CN_PRES_DIV64,
  TMR_PRES_128 = MXC_S_TMR_CN_PRES_DIV128,
  TMR_PRES_256 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV1,
  TMR_PRES_512 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV2,
  TMR_PRES_1024 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV4,
  TMR_PRES_2048 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV8,
  TMR_PRES_4096 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV16
}
 Timer prescaler values. More...
 
enum  tmr_mode_t {
  TMR_MODE_ONESHOT = MXC_V_TMR_CN_TMODE_ONESHOT,
  TMR_MODE_CONTINUOUS = MXC_V_TMR_CN_TMODE_CONTINUOUS,
  TMR_MODE_COUNTER = MXC_V_TMR_CN_TMODE_COUNTER,
  TMR_MODE_PWM = MXC_V_TMR_CN_TMODE_PWM,
  TMR_MODE_CAPTURE = MXC_V_TMR_CN_TMODE_CAPTURE,
  TMR_MODE_COMPARE = MXC_V_TMR_CN_TMODE_COMPARE,
  TMR_MODE_GATED = MXC_V_TMR_CN_TMODE_GATED,
  TMR_MODE_CAPTURE_COMPARE = MXC_V_TMR_CN_TMODE_CAPTURECOMPARE
}
 Timer modes. More...
 
enum  tmr_unit_t {
  TMR_UNIT_NANOSEC = 0,
  TMR_UNIT_MICROSEC,
  TMR_UNIT_MILLISEC,
  TMR_UNIT_SEC
}
 Timer units of time enumeration. More...
 

Functions

void TMR_Init (mxc_tmr_regs_t *tmr, tmr_pres_t pres, const sys_cfg_tmr_t *sys_cfg)
 Initialize timer module clock. More...
 
void TMR_Shutdown (mxc_tmr_regs_t *tmr)
 Shutdown timer module clock. More...
 
void TMR_Enable (mxc_tmr_regs_t *tmr)
 Enable the timer. More...
 
void TMR_Disable (mxc_tmr_regs_t *tmr)
 Disable the timer. More...
 
void TMR_Config (mxc_tmr_regs_t *tmr, const tmr_cfg_t *cfg)
 Configure the timer. More...
 
int TMR_PWMConfig (mxc_tmr_regs_t *tmr, const tmr_pwm_cfg_t *cfg)
 Configure the timer for PWM operation. More...
 
int TMR_PWMSetDuty (mxc_tmr_regs_t *tmr, uint32_t duty)
 Set the timer duty cycle. More...
 
int TMR_PWMSetPeriod (mxc_tmr_regs_t *tmr, uint32_t per)
 Set the timer period. More...
 
uint32_t TMR_GetCompare (mxc_tmr_regs_t *tmr)
 Get the timer compare count. More...
 
uint32_t TMR_GetCapture (mxc_tmr_regs_t *tmr)
 Get the timer capture count. More...
 
uint32_t TMR_GetCount (mxc_tmr_regs_t *tmr)
 Get the timer count. More...
 
void TMR_IntClear (mxc_tmr_regs_t *tmr)
 Clear the timer interrupt. More...
 
uint32_t TMR_IntStatus (mxc_tmr_regs_t *tmr)
 Get the timer interrupt status. More...
 
void TMR_SetCompare (mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
 Set the timer compare count. More...
 
void TMR_SetCount (mxc_tmr_regs_t *tmr, uint32_t cnt)
 Set the timer count. More...
 
int TMR_GetTicks (mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks)
 Convert real time to timer ticks. More...
 
int TMR_GetTime (mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units)
 Convert timer ticks to real time. More...
 

Detailed Description

Enumeration Type Documentation

◆ tmr_pres_t

enum tmr_pres_t
Enumerator
TMR_PRES_2 

Divide input clock by 1.

TMR_PRES_4 

Divide input clock by 2.

TMR_PRES_8 

Divide input clock by 4.

TMR_PRES_16 

Divide input clock by 8.

TMR_PRES_32 

Divide input clock by 16.

TMR_PRES_64 

Divide input clock by 32.

TMR_PRES_128 

Divide input clock by 64.

TMR_PRES_256 

Divide input clock by 128.

TMR_PRES_512 

Divide input clock by 256.

TMR_PRES_1024 

Divide input clock by 512.

TMR_PRES_2048 

Divide input clock by 1024.

TMR_PRES_4096 

Divide input clock by 2048.

◆ tmr_mode_t

enum tmr_mode_t
Enumerator
TMR_MODE_CONTINUOUS 

Timer Mode ONESHOT.

TMR_MODE_COUNTER 

Timer Mode CONTINUOUS.

TMR_MODE_PWM 

Timer Mode COUNTER.

TMR_MODE_CAPTURE 

Timer Mode PWM.

TMR_MODE_COMPARE 

Timer Mode CAPTURE.

TMR_MODE_GATED 

Timer Mode COMPARE.

TMR_MODE_CAPTURE_COMPARE 

Timer Mode GATED.

◆ tmr_unit_t

enum tmr_unit_t
Enumerator
TMR_UNIT_NANOSEC 

Nanosecond Unit Indicator.

TMR_UNIT_MICROSEC 

Microsecond Unit Indicator.

TMR_UNIT_MILLISEC 

Millisecond Unit Indicator.

TMR_UNIT_SEC 

Second Unit Indicator.

Function Documentation

◆ TMR_Init()

void TMR_Init ( mxc_tmr_regs_t tmr,
tmr_pres_t  pres,
const sys_cfg_tmr_t *  sys_cfg 
)
Parameters
tmrPointer to timer module to initialize.
presPrescaler value.
sys_cfgSystem configuration object

◆ TMR_Shutdown()

void TMR_Shutdown ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.

◆ TMR_Enable()

void TMR_Enable ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.

◆ TMR_Disable()

void TMR_Disable ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.

◆ TMR_Config()

void TMR_Config ( mxc_tmr_regs_t tmr,
const tmr_cfg_t cfg 
)
Parameters
tmrPointer to timer module to initialize.
cfgPointer to timer configuration struct.

◆ TMR_PWMConfig()

int TMR_PWMConfig ( mxc_tmr_regs_t tmr,
const tmr_pwm_cfg_t cfg 
)
Parameters
tmrPointer to timer module to initialize.
cfgPointer to timer PWM configuration struct.
Note
Can cause a glitch if the Timer is currently running.
Returns
E_BAD_PARAM if duty_cnt > per_cnt.

◆ TMR_PWMSetDuty()

int TMR_PWMSetDuty ( mxc_tmr_regs_t tmr,
uint32_t  duty 
)
Parameters
tmrPointer to timer module to initialize
dutyNew duty cycle count
Note
Will block until safe to change the duty count.
Returns
E_BAD_PARAM if duty_cnt > per_cnt.

◆ TMR_PWMSetPeriod()

int TMR_PWMSetPeriod ( mxc_tmr_regs_t tmr,
uint32_t  per 
)
Parameters
tmrPointer to timer module to initialize.
perNew period count.
Note
Will block until safe to change the period count.
Returns
E_BAD_PARAM if duty_cnt > per_cnt.

◆ TMR_GetCompare()

uint32_t TMR_GetCompare ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.
Returns
Returns the current compare count.

◆ TMR_GetCapture()

uint32_t TMR_GetCapture ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.
Returns
Returns the most recent capture count.

◆ TMR_GetCount()

uint32_t TMR_GetCount ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.
Returns
Returns the current count.

◆ TMR_IntClear()

void TMR_IntClear ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.

◆ TMR_IntStatus()

uint32_t TMR_IntStatus ( mxc_tmr_regs_t tmr)
Parameters
tmrPointer to timer module to initialize.
Returns
Returns the interrupt status. 1 if interrupt has occurred.

◆ TMR_SetCompare()

void TMR_SetCompare ( mxc_tmr_regs_t tmr,
uint32_t  cmp_cnt 
)
Parameters
tmrPointer to timer module to initialize.
cmp_cntNew compare count.
Note
This function does not protect against output glitches in PWM mode. Use TMR_PWMSetPeriod when in PWM mode.

◆ TMR_SetCount()

void TMR_SetCount ( mxc_tmr_regs_t tmr,
uint32_t  cnt 
)
Parameters
tmrPointer to timer module to initialize.
cntNew count.

◆ TMR_GetTicks()

int TMR_GetTicks ( mxc_tmr_regs_t tmr,
uint32_t  time,
tmr_unit_t  units,
uint32_t *  ticks 
)
Parameters
tmrPointer to timer module to initialize.
timeNumber of units of time.
unitsWhich units of time you want to convert.
ticksPointer to store the number of ticks calculated.
Returns
E_NO_ERROR If everything is successful.
Error Codes If function is unsuccessful.

◆ TMR_GetTime()

int TMR_GetTime ( mxc_tmr_regs_t tmr,
uint32_t  ticks,
uint32_t *  time,
tmr_unit_t units 
)
Parameters
tmrPointer to timer module to initialize.
ticksNumber of ticks.
timePointer to store number of units of time.
unitsPointer to store the units that time represents.
Returns
E_NO_ERROR If everything is successful.
Error Codes If function is unsuccessful.