-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterrupt_handlers.c
73 lines (58 loc) · 2.1 KB
/
interrupt_handlers.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
/*
* interrupt_handlers.c
* Scooter final project's implementation file for interrupt handlers
* Authors: Ryan ZumBrunnen, Guanxiong Fu and Arash Yousefdezah
* Created on: October 26, 2017
*
*/
#include "msp.h"
#include "configuration.h"
#include "interrupt_handlers.h"
#include "conversion.h"
#include "send_terminal.h"
extern volatile uint8_t flag_dist;
extern volatile uint8_t flag_vel;
extern volatile uint32_t count_pin;
extern volatile float distance;
extern volatile float distance_prev;
extern volatile float velocity;
extern volatile float velocity_prev;
extern volatile float Nadc;
extern volatile float Nadcx;
extern volatile float Nadcy;
extern volatile float Nadcz;
void PORT1_IRQHandler(void){
if (P1->IFG & BIT1){ // Left button press
flag_dist = 1;
P1->IFG &= ~BIT1; // clear interrupt flag for Left button
// NVIC_DisableIRQ(T32_INT1_IRQn);
}
if (P1->IFG & BIT4){ // Right button press
ADC14->CTL0 |= ADC14_CTL0_SC; // start sampling and conversion
P1->IFG &= ~BIT4;
}
if (P1->IFG & BIT6) { // input interrupt
count_pin++; // count the number of time the interrupt is triggered
P1->IFG &= ~(BIT6); // clear interrupt flag
}
}
void T32_INT1_IRQHandler(void){
distance = count_pin * 0.022;
velocity_prev = velocity;
velocity = distance - distance_prev;
distance_prev = distance;
flag_vel = 1; // goes to main because function calls inside ISRs is bad practice
ADC14->CTL0 |= ADC14_CTL0_SC; // start sampling and conversion
TIMER32_1->INTCLR = 0;
}
void ADC14_IRQHandler(void){
if (ADC14->IFGR0 & ADC14_IFGR0_IFG0){
Nadc = ADC14->MEM[0]; //Nadc value for temperature
// don't need to clear flag because it automatically clears when data is read
}
if (ADC14->IFGR0 & (ADC14_IFGR0_IFG1 | ADC14_IFGR0_IFG2 | ADC14_IFGR0_IFG3)){
Nadcx = ADC14->MEM[1]; // Nadc value for accelerometer in x direction
Nadcy = ADC14->MEM[2]; // y direction
Nadcz = ADC14->MEM[3]; // z direction
}
}