MSPM0_ValvanoWare  1.0
ECE445L starter code
Files | Macros | Functions
Timer

Hardware timers. More...

Files

file  InputCapture.h
 Software driver functions for input capture.
 
file  Timer.h
 Initialize Periodic interrupt timers.
 

Macros

#define INPUTCAPTUREUSELFCLK   2
 use INPUTCAPTUREUSELFCLK to select 32768 Hz LFCLK
 
#define INPUTCAPTUREUSEMFCLK   4
 use INPUTCAPTUREUSEMFCLK to select MFCLK (not tested)
 
#define INPUTCAPTUREUSEBUSCLK   8
 use INPUTCAPTUREUSEBUSCLK to select BUSCLK
 

Functions

void InputCapture_Init (uint32_t timerClkSrc, uint32_t timerClkPrescale, uint32_t priority)
 Initialize input capture. More...
 
void InputCapture_InitDual (uint32_t timerClkSrc, uint32_t timerClkPrescale, uint32_t priority)
 
void TimerG0_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer G0 interrupt. More...
 
void TimerG8_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer G8 interrupt. More...
 
void TimerA0_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer A0 interrupt. More...
 
void TimerA1_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer A1 interrupt. More...
 
void TimerG7_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer G7 interrupt. More...
 
void TimerG6_IntArm (uint16_t period, uint32_t prescale, uint32_t priority)
 Initialize Timer G6 interrupt. More...
 
void TimerG12_IntArm (uint32_t period, uint32_t priority)
 Initialize Timer G12 interrupt. More...
 
void TimerG12_Init (void)
 Initialize Timer G12. More...
 

Detailed Description

Hardware timers.

Input capture pins
Pin TimerDescription
PA12TIMG0interrupts on rising edge of PA12

Function Documentation

◆ InputCapture_Init()

void InputCapture_Init ( uint32_t  timerClkSrc,
uint32_t  timerClkPrescale,
uint32_t  priority 
)

Initialize input capture.

Arm interrupts on rising edge of PA12
Let P be the period of the selected clock
resolution = P*(timerClkPrescale+1)
precision = 16 bits
range = 65535*resolution (max)
timerClkDivRatio = 1
timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
resolution = (timerClkDivRatio * (timerClkPrescale + 1)))/timerClkSrc
User defines their own ISR like the following

uint32_t Data[20];
uint32_t Index=0;
uint32_t Time,Last,Period;
uint32_t iidx,count=0;
void TIMG0_IRQHandler(void){
count++;
iidx = TIMG0->CPU_INT.IIDX;// this will acknowledge
if((iidx) == 5){ // 5 means capture CCD0
Time = TIMG0->COUNTERREGS.CC_01[0]; // time now
Period = (Last-Time)&0xFFFF; // elapsed time since last
Last = Time;
if(Index < 20){
Data[Index] = Period;
Index++;
}
}
}
  • timerClkSrc
    • 2 for 32768 Hz LFCLK
    • 4 for MFCLK (not tested)
    • 8 for BUSCLK
  • For example
    • source=LFCLK, prescale=255, resolution = 7.8125ms
    • source=BUSCLK, prescale=47, resolution = 1us
Parameters
timerClkSrccould be LFCLK, MFCLK, or BUSCLK
timerClkPrescaleis prescale divide clock by timerClkPrescale+1, 0 to 255
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
Will invoke LaunchPad_Init

◆ TimerA0_IntArm()

void TimerA0_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer A0 interrupt.

Arm 16-bit periodic interrupts on Timer A0. TimerA0 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMA0_IRQHandler(void){
if((TIMA0->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}
#define GREEN
GREEN is a constant to select green LED2 on Port B, PB27.
Definition: LaunchPad.h:138

◆ TimerA1_IntArm()

void TimerA1_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer A1 interrupt.

Arm 16-bit periodic interrupts on Timer A1. TimerA1 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMA1_IRQHandler(void){
if((TIMA1->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}

◆ TimerG0_IntArm()

void TimerG0_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer G0 interrupt.

Arm 16-bit periodic interrupts on Timer G0. TimerG0 is on power Domain PD0

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 20MHz
  • 80MHz bus clock, Timer clock is ULPCLK 40MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMG0_IRQHandler(void){
if((TIMG0->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}

◆ TimerG12_Init()

void TimerG12_Init ( void  )

Initialize Timer G12.

initialize G12 for continuous counting. No prescale
simply read TIMG12->COUNTERREGS.CTR for 32 bit time

  • resolution is bus clock, for 80 MHz clock, 12.5ns
  • precision is 32 bits,

TimerG12 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz
Parameters
none
Returns
none
Note
Example use to measure execution time of myfunction
uint32_t elapsed,start,end;
TimerG12_Init(); // start timer G12
start = TIMG12->COUNTERREGS.CTR;
myfunction();
end = TIMG12->COUNTERREGS.CTR;
elapsed = start-end; // 12.5ns resolution
void TimerG12_Init(void)
Initialize Timer G12.

◆ TimerG12_IntArm()

void TimerG12_IntArm ( uint32_t  period,
uint32_t  priority 
)

Initialize Timer G12 interrupt.

Arm 32-bit periodic interrupts on Timer G12. No prescale TimerG12 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz

frequency = TimerClock/period

Parameters
period32-bit sets the interrupt period
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMG12_IRQHandler(void){
if((TIMG12->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}

◆ TimerG6_IntArm()

void TimerG6_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer G6 interrupt.

Arm 16-bit periodic interrupts on Timer G6. TimerG6 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMG6_IRQHandler(void){
if((TIMG6->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}

◆ TimerG7_IntArm()

void TimerG7_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer G7 interrupt.

Arm 16-bit periodic interrupts on Timer G7. TimerG7 is on power Domain PD1

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 40MHz
  • 80MHz bus clock, Timer clock is ULPCLK 80MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMG7_IRQHandler(void){
if((TIMG7->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}

◆ TimerG8_IntArm()

void TimerG8_IntArm ( uint16_t  period,
uint32_t  prescale,
uint32_t  priority 
)

Initialize Timer G8 interrupt.

Arm 16-bit periodic interrupts on Timer G8. TimerG8 is on power Domain PD0

  • 32MHz bus clock, Timer clock is 32MHz
  • 40MHz bus clock, Timer clock is ULPCLK 20MHz
  • 80MHz bus clock, Timer clock is ULPCLK 40MHz

frequency = TimerClock/prescale/period

Parameters
periodsets the interrupt 16-bit period
prescalesets the timer prescale
priorityis 0(highest),1,2 or 3(lowest)
Returns
none
Note
interrupts will be enabled in main after all initialization User defines their own ISR like the following
uint32_t count;
void TIMG8_IRQHandler(void){
if((TIMG8->CPU_INT.IIDX) == 1){ // this will acknowledge
GPIOB->DOUTTGL31_0 = GREEN; // toggle PB27
count++;
}
}