-
Notifications
You must be signed in to change notification settings - Fork 3
/
temp.c
executable file
·97 lines (75 loc) · 2.14 KB
/
temp.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//******************************************************************************
//
//
// R. von Kurnatowski III
// TX/RX Labs
// November 2011
// Built with CCE Version: 4.0.1
//******************************************************************************
#include "txrxlpf.h"
#include "msp430xG46x.h"
#include "temp.h"
#include "powermgmt.h"
void initTemp() {
CACTL1 = CAON + CAREF_1+CARSEL; // Enable Comp, ref = 0.5*Vcc
CACTL2 = P2CA0 + CAF; // Pin to CA0
TACCTL1 |= CM_2 + CCIS_1 + CAP;
}
// note all pins connnected to cap not included as d and c must be high impedence
unsigned int measureDis(unsigned char cpin, unsigned char dpin) {
unsigned int dtime;
__no_operation();
P8SEL &= ~cpin;
P8SEL &= ~dpin;
P8DIR &= ~dpin;
P8DIR |= cpin;//charge cap using cpin
P8OUT |= cpin;
P8OUT |= dpin;
TACCTL1 |= CCIE;
TACTL = TASSEL_1;
TACTL |= TACLR;
CACTL1 = CAON;
__no_operation();
P8DIR &= ~cpin; //high impedence cpin
P8DIR |= dpin; // dpin output and high
TACTL |= MC_2; // start capture timer counting
P8OUT &= ~dpin; // start discharge using dpin
LPM3;// wait for capture interrupt in lpm
TACCTL1 &= ~CCIE;
dtime = TACCR1;// get time value
P8DIR &= ~dpin; // high impendence dpin
TACTL = MC_0;
CACTL1 &= ~CAON;
return dtime;
}
void executeTemp(unsigned char* buffer, unsigned int length) {
initTemp();
unsigned int a = measureDis(BIT4, BIT4);
unsigned int b = measureDis(BIT4, BIT5);
__no_operation();
*buffer = (unsigned char)((a & 0xFF00)>>8);
buffer++;
*buffer = (unsigned char)((a & 0x00FF));
buffer++;
*buffer = (unsigned char)((b & 0xFF00)>>8);
buffer++;
*buffer = (unsigned char)((b & 0x00FF));
buffer++;
return;
}
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
{
switch( TAIV )
{
case 2:
__no_operation();
__bic_SR_register_on_exit(LPM3_bits);
break;
default:
__no_operation();
__bic_SR_register_on_exit(LPM3_bits);
break;
}
}