forked from ma535468/contrl-iv-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
62 lines (49 loc) · 1.14 KB
/
main.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
#include <msp430.h>
#include <math.h>
#define LED1 BIT0
double velocity(double height);
void resetVelocity(double velocityArray[]);
double gravity = 9.81;
double step = 0.5;
unsigned int i;
int main(void)
{
double testHeight;
double velocityArray[10];
P1DIR |= LED1;
TA0CCTL0 = CCIE;
TA0CTL = TASSEL_1 | ID_1 | MC_1 | TACLR;
TA0CCR0 = 0x8000;
TA0R = 0;
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
__bis_SR_register(GIE); // Enable global interrupts.
while(1)
{
testHeight = 5.0;
resetVelocity(velocityArray);
for(i=0; i<10; i++)
{
testHeight -= step;
if(testHeight > 2.5)
velocityArray[i] = 0;
else
velocityArray[i] = velocity(testHeight);
}
}
}
//Velocity of water flow from IV.
double velocity(double height)
{
return sqrt(2*gravity*height);
}
//Simple function that resets velocity memory.
void resetVelocity(double velocityArray[])
{
for(i = 0; i<10; i++)
velocityArray[i] = 0;
}
#pragma vector = TIMER0_A0_VECTOR;
__interrupt void Timer(void)
{
P1OUT ^= LED1;
}