-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b33085e
commit 913899c
Showing
11 changed files
with
1,076 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* configuration.c | ||
* Scooter final project's configuration file for timer, gpio, uart, etc. | ||
* 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 <grlib.h> | ||
#include "Crystalfontz128x128_ST7735.h" | ||
|
||
extern Graphics_Context g_sContext; | ||
|
||
void display_configure(void) | ||
{ | ||
/* Initializes display */ | ||
Crystalfontz128x128_Init(); | ||
|
||
/* Set default screen orientation */ | ||
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); | ||
|
||
/* Initializes graphics context */ | ||
Graphics_initContext(&g_sContext, &g_sCrystalfontz128x128); | ||
Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_RED); | ||
Graphics_setBackgroundColor(&g_sContext, GRAPHICS_COLOR_WHITE); | ||
GrContextFontSet(&g_sContext, &g_sFontFixed6x8); | ||
Graphics_clearDisplay(&g_sContext); | ||
Graphics_drawStringCentered(&g_sContext, "Velocity:", AUTO_STRING_LENGTH, 64, 30, OPAQUE_TEXT); | ||
Graphics_drawStringCentered(&g_sContext, "Distance:", AUTO_STRING_LENGTH, 64, 60, OPAQUE_TEXT); | ||
Graphics_drawStringCentered(&g_sContext, "Stopped", AUTO_STRING_LENGTH, 64, 90, OPAQUE_TEXT); | ||
} | ||
|
||
// configuration for GPIO ports | ||
void GPIO_configure(void) | ||
{ | ||
/* Left button configure */ | ||
P1->SEL0 &= ~(BIT1); | ||
P1->SEL1 &= ~(BIT1); | ||
P1->DIR &= ~(BIT1); | ||
P1->OUT |= BIT1; | ||
P1->REN |= BIT1; | ||
P1->IFG &= ~(BIT1); | ||
P1->IES |= BIT1; | ||
P1->IE |= BIT1; | ||
|
||
/* Right button configure */ | ||
P1->SEL0 &= ~(BIT4); | ||
P1->SEL1 &= ~(BIT4); | ||
P1->DIR &= ~(BIT4); | ||
P1->OUT |= BIT4; | ||
P1->REN |= BIT4; | ||
P1->IFG &= ~(BIT4); | ||
P1->IES |= BIT4; | ||
P1->IE |= BIT4; | ||
|
||
//Configure pin for input interrupt | ||
P1->DIR &= ~(BIT6); | ||
P1->SEL0 &= ~(BIT6); | ||
P1->SEL1 &= ~(BIT6); | ||
P1->IE |= BIT6; | ||
P1->REN |= BIT6; | ||
P1->IFG &= ~(BIT6); | ||
|
||
/* P1.0 LED Output */ | ||
P1->DIR |= BIT0; | ||
P1->SEL0 &= ~(BIT0); | ||
P1->SEL1 &= ~(BIT0); | ||
P1->OUT &= ~(BIT0); | ||
|
||
/* RGB LED Output */ | ||
P2->DIR |= BIT0 | BIT1 | BIT2; | ||
P2->SEL0 &= ~(BIT0 | BIT1 | BIT2); | ||
P2->SEL1 &= ~(BIT0 | BIT1 | BIT2); | ||
P2->OUT = BIT0; //Start with red on | ||
|
||
P6->SEL0 |= BIT0; | ||
P6->SEL1 |= BIT0; | ||
|
||
NVIC_EnableIRQ(PORT1_IRQn); | ||
} | ||
|
||
// configuration for Timer32 | ||
void timer_configure(void){ | ||
//enable prescaling, interrupt flag, and set to be periodically repeating | ||
TIMER32_1->CONTROL |= TIMER32_CONTROL_PRESCALE_1 | TIMER32_CONTROL_IE | TIMER32_CONTROL_SIZE | TIMER32_CONTROL_MODE | TIMER32_CONTROL_ENABLE; | ||
TIMER32_1->LOAD = 93749; //time to get 0.5sec | ||
NVIC_EnableIRQ(T32_INT1_IRQn); | ||
} | ||
|
||
|
||
// configuration for ADC14 | ||
void ADC_configure(void){ | ||
// Initialize the shared reference module | ||
// By default, REFMSTR=1 => REFCTL is used to configure the internal reference | ||
while(REF_A->CTL0 & REF_A_CTL0_GENBUSY); // If ref generator busy, WAIT | ||
REF_A->CTL0 = REF_A_CTL0_VSEL_0 | REF_A_CTL0_ON; // Enable internal 1.2V ref | ||
REF_A->CTL0 &= ~REF_A_CTL0_TCOFF; // Turn on Temperature Sensor | ||
|
||
ADC14->CTL0 |= ADC14_CTL0_SHT0_5 | ADC14_CTL0_ON | ADC14_CTL0_SHP | ADC14_CTL0_CONSEQ_1; //multiple sampling (repeating sequence of channel) | ||
ADC14->CTL1 |= ADC14_CTL1_TCMAP | BIT(16) | ADC14_CTL1_RES__14BIT ; // Conf internal temp sensor channel, ADC conversion start address from 1, set resolution to 14 bit | ||
ADC14->MCTL[0]= ADC14_MCTLN_INCH_22 | ADC14_MCTLN_VRSEL_0; // Map Temp Analog channel to MEM0/MCTL0, set 3.3v ref | ||
ADC14->MCTL[1]= ADC14_MCTLN_INCH_14 | ADC14_MCTLN_VRSEL_0; // Map Analog channel for Accelerometer x direction to MEM1/MCTL1, set 3.3v ref Accelerometer X Direction | ||
ADC14->MCTL[2]= ADC14_MCTLN_INCH_13 | ADC14_MCTLN_VRSEL_0; // Y Direction to MEM2/MCTL2 | ||
ADC14->MCTL[3]= ADC14_MCTLN_INCH_11 | ADC14_MCTLN_VRSEL_0 | ADC14_MCTLN_EOS; //Z direction to MEM3/MCTL3 | ||
ADC14->IER0 = ADC14_IER0_IE0 | ADC14_IER0_IE1 | ADC14_IER0_IE2 | ADC14_IER0_IE3; // Enable MCTL1/MEM0 , MCTL1/MEM1 , MCTL2/MEM2 , MCTL3|MEM3 Interrupts | ||
|
||
while(!(REF_A->CTL0 & REF_A_CTL0_GENRDY)); // Wait for ref generator to settle | ||
ADC14->CTL0 |= ADC14_CTL0_ENC; // Enable Conversions | ||
NVIC_EnableIRQ(ADC14_IRQn); // Enable ADC int in NVIC module | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* configuration.c | ||
* Scooter final project's header file for configuration | ||
* Authors: Ryan ZumBrunnen, Guanxiong Fu and Arash Yousefdezah | ||
* Created on: October 26, 2017 | ||
* | ||
*/ | ||
|
||
#ifndef CONFIGURATION_H_ | ||
#define CONFIGURATION_H_ | ||
|
||
void display_configure(void); | ||
|
||
void GPIO_configure(void); | ||
|
||
void timer_configure(void); | ||
|
||
void ADC_configure(void); | ||
|
||
#endif /* CONFIGURATION_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* conversion.c | ||
* Scooter final project's implementation file for conversion functions | ||
* 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" | ||
|
||
void reverse(char s[], int slength) | ||
{ | ||
int i, j; | ||
char c; | ||
|
||
for (i = 0, j = slength-1; i<j; i++, j--) { | ||
c = s[i]; | ||
s[i] = s[j]; | ||
s[j] = c; | ||
} | ||
} | ||
|
||
//itoa taken from https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa and cahnged slightly | ||
int itoa(uint32_t n, char s[]) | ||
{ | ||
int i, sign; | ||
if ((sign = n) < 0) /* record sign */ | ||
n = -n; /* make n positive */ | ||
i = 0; | ||
do { /* generate digits in reverse order */ | ||
s[i++] = n % 10 + '0'; /* get next digit */ | ||
} while ((n /= 10) > 0); /* delete it */ | ||
if (sign < 0) | ||
s[i++] = '-'; | ||
s[i] = '\0'; | ||
reverse(s, i); //MIGHT BE MESSING WITH NULL CHARACTER | ||
return i; | ||
} | ||
|
||
//ftoa taken from http://www.geeksforgeeks.org/convert-floating-point-number-string/ | ||
//and modified to fit our needs better | ||
void ftoa(float n, char s[], int afterpoint){ | ||
// Extract integer part | ||
int ipart = (int)n; | ||
|
||
// Extract floating part | ||
float fpart = n - (float)ipart; | ||
|
||
// convert integer part to string | ||
int position = itoa(ipart, s); | ||
|
||
// check for display option after point | ||
if (afterpoint != 0) | ||
{ | ||
s[position] = '.'; | ||
// Get the value of fraction part upto given no. | ||
// of points after dot. The third parameter is needed | ||
// to handle cases like 233.007 | ||
int tempnum = 1; | ||
int i=0; | ||
for (i = 0; i < afterpoint; i++) | ||
tempnum *= 10; //to get 10^afterpoint | ||
fpart = fpart * tempnum; //should make this a number without dec | ||
if (fpart<0) | ||
fpart=abs(fpart); | ||
tempnum/=10; | ||
while (fpart<tempnum){ //adds back zeros between decimal and trailing digits | ||
itoa(0,s+position+1); | ||
tempnum /= 10; | ||
position++; | ||
} | ||
itoa((uint32_t)fpart, s + position + 1); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* conversion.h | ||
* Scooter final project's header file for conversion functions | ||
* Authors: Ryan ZumBrunnen, Guanxiong Fu and Arash Yousefdezah | ||
* Created on: October 26, 2017 | ||
* | ||
*/ | ||
|
||
|
||
#ifndef CONVERSION_H_ | ||
#define CONVERSION_H_ | ||
#include <stdint.h> | ||
|
||
void reverse(char s[], int slength); | ||
|
||
int itoa(uint32_t n, char s[]); | ||
|
||
void ftoa(float n, char s[], int afterpoint); | ||
|
||
#endif /* CONVERSION_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* interrupt_handlers.h | ||
* Scooter final project's header file for interrupt handlers | ||
* Authors: Ryan ZumBrunnen, Guanxiong Fu and Arash Yousefdezah | ||
* Created on: October 26, 2017 | ||
* | ||
*/ | ||
|
||
|
||
#ifndef INTERRUPT_HANDLERS_H_ | ||
#define INTERRUPT_HANDLERS_H_ | ||
|
||
void PORT1_IRQHandler(void); | ||
|
||
void T32_INT1_IRQHandler(void); | ||
|
||
void ADC14_IRQHandler(void); | ||
|
||
#endif /* INTERRUPT_HANDLERS_H_ */ |
Oops, something went wrong.