Flipklok
 
Loading...
Searching...
No Matches
timer.h File Reference
#include <msp430.h>
#include "stepperAdvance.h"
#include "adc.h"

Go to the source code of this file.

Macros

#define clockFreq   32768
 
#define capacityTimer   65536
 
#define timerDiv   1
 
#define timerLength_ms   (capacityTimer / timerLength_cycles * 1000)
 
#define pwmPeriod_cycles   32
 

Functions

void setupTimer0 ()
 
void setupTimer1 ()
 
void wakeUpTimer0 ()
 
void sleepTimer0 ()
 

Macro Definition Documentation

◆ capacityTimer

#define capacityTimer   65536

Definition at line 14 of file timer.h.

Referenced by calculateBitTransmitTime(), and setupTimer1().

◆ clockFreq

#define clockFreq   32768

Definition at line 13 of file timer.h.

◆ pwmPeriod_cycles

#define pwmPeriod_cycles   32

Definition at line 17 of file timer.h.

Referenced by ISR_TA0(), and setupTimer0().

◆ timerDiv

#define timerDiv   1

Definition at line 15 of file timer.h.

◆ timerLength_ms

#define timerLength_ms   (capacityTimer / timerLength_cycles * 1000)

Definition at line 16 of file timer.h.

Function Documentation

◆ setupTimer0()

void setupTimer0 ( )

Setup of timer0, uses the the ACLK (Auxiliary clock), counts up continuous. Capture control registers

  • CCR0
  • CCR1 triggers pwm LED
  • CCR2 triggers stepperAdvance()
  • TAIFG start reading ADC

Definition at line 26 of file timer.c.

27{
28 //Timer setup
29 TA0CTL = TASSEL_1 | MC_2| TACLR | TAIE | ID_0; // Set to counter to ACLK, Continuous clock, clear counter of clock, Enable TAIFG interrupt, Divider set to 1
30 TA0CCTL1 = CCIE; // TACCR1 interrupt enabled
31 TA0CCTL2 &= ~CCIE; // TACCR2 interrupt disable
32 TA0CCR2 = stepperTimeOffsetSlow; // compare at stepperOffset
33 TA0CCR1 = pwmPeriod_cycles;
34}
#define stepperTimeOffsetSlow
#define pwmPeriod_cycles
Definition timer.h:17

◆ setupTimer1()

void setupTimer1 ( )

Setup of timer1, uses the the ACLK (Auxiliary clock), counts up/down. Capture control registers

  • CCR0
  • CCR1
  • CCR2
  • TAIFG trigger counting timer1Count up

Definition at line 114 of file timer.c.

115{
116 //Timer setup
117 TA1CTL |= MC_0; // stop timer
118 TA1CTL |= TAIE; // setup end of cycle interrupt (up/down mode, so it get triggered when reaching 0)
119 TA1CTL |= TASSEL_1; // Set to counter to ACLK
120 TA1CTL |= TACLR; // Clear counter of clock
121 #warning "When using PCB divide by 1. When using MSP-EXP430G2ET devboard pins on devboard are not connected to LFXTAL internal clock should be used"
122 TA1CTL |= ID_0; // Divider set to 1
123
124 TA1CCR0 |= (capacityTimer - 1); // Every 4 seconds
125 TA1CCTL0 |= CCIE; // TACCR0 interrupt enabled
126// TA1CCTL1 = CCIE; // TACCR1 interrupt enabled
127// TA1CCTL2 = CCIE; // TACCR2 interrupt enabled
129 toggleTimer1Direction = 1; // Counting up
130 TA1CTL |= MC_3; // up/down
131
132}
uint32_t timeSinceLastCompleteDcfMessage
Definition timeKeeping.h:22
volatile bool toggleTimer1Direction
Definition timeKeeping.h:46
#define capacityTimer
Definition timer.h:14

References capacityTimer, timeSinceLastCompleteDcfMessage, and toggleTimer1Direction.

Referenced by main().

◆ sleepTimer0()

void sleepTimer0 ( )

Definition at line 36 of file timer.c.

37{
38 TA0CTL = TASSEL_1 | MC_2 | TAIE | ID_3; // Set to counter to ACLK, Continuous clock, Enable TAIFG interrupt, Divider set to 8
39 TA0CCTL1 &= ~CCIE; // TACCR1 interrupt disable
40 TA0CCTL2 &= ~CCIE; // TACCR2 interrupt disable
41}

Referenced by sleep().

◆ wakeUpTimer0()

void wakeUpTimer0 ( )

Definition at line 43 of file timer.c.

44{
45 TA0CTL = TASSEL_1 | MC_2 | TAIE | ID_0; // Set to counter to ACLK, Continuous clock, Enable TAIFG interrupt, Divider set to 1
46 TA0CCTL1 |= CCIE; // TACCR1 interrupt enable
47}

Referenced by wakeUp().