forked from seniorDesignMAY1607/MSP430F2274_Final
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.c
80 lines (61 loc) · 1.49 KB
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* timer.c
*
* Created on: Apr 7, 2016
* Author: nbergman
*/
#include "timer.h"
#define MAX_TIMERA_PERIOD 65536 //# of microsecond for 1MHz clock 65535 / 1000000000
volatile uint32_t ms_tick_count = 0; //global count for ms
volatile uint16_t timerA_overflows = 0; //Count Overflows
//Used for waitMillis -- Increment global millisecond count
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMERA0_ISR(void)
{
TA0CCTL0 &= ~CCIE;
//P3OUT ^= BIT5; //Debug
ms_tick_count++;
TA0CCTL0 |= CCIE;
}
/*
#pragma vector = TIMERA1_VECTOR;
__interrupt void TIMERA1_ISR(void)
{
TA0CCTL0 &= ~CCIE;
P3OUT ^= BIT4;
timerA_overflows++; //Not used at the moment//Not used at the moment
TA0CCTL0 |= CCIE;
}
*/
//Initialize timer
void timer_initA0()
{
TACTL |= TASSEL_2;
//TACTL |= TASSEL_2 | MC0;//Always running
TACCTL0 |= CCIE; //Interupt enable for timer A0
TACCR0 = 1000;
__bis_SR_register(GIE); //Global Interrupt Enable
}
//Blocks for a number of milliseconds
void timer_waitMilli(uint16_t theTime)
{
TACTL |= MC0;//Always running
ms_tick_count = 0; //Reset millisecond counter
while(ms_tick_count < theTime )
{
//Do Nothing
}
TACTL |= TACLR;
}
//Blocks for a number of microseconds
//Starts and resets TimerA
void timer_waitMicro(uint16_t theTime)
{
//uint16_t finishTime = theTime;
TACTL |= MC1; //Contiuous Mode
while(1)
{
if(TAR >= theTime || (TAIV & TAIFG)) break;
}
TACTL |= TACLR;
}