Question: MSP430 programming in C 1. Connect a temperature sensor to MSP430 using the scheme given in Lab 6 (you may change the pin though). Connect
MSP430 programming in C
1. Connect a temperature sensor to MSP430 using the scheme given in Lab 6 (you may change the pin though). Connect a 7-segment display to the pins of your choice (using what you have learned in Lab 5). The 7-segment display is used to display the temperature value measured by the temperature sensor in 0F. Connect an LED to mimic a fan. Connect a switch to MSP430 too. Write a program in C which achieves the following tasks:
2. Initially the 7-segment digits are all off and the switch is at the off position. The system is in a low power mode (mode 3). (10%)
3. When the switch is turned to the on position, the system leaves the low power mode. This step needs to be done using a Port I/O interrupt. (10%)
5. The program now enters the active mode, every second the program does an A/D conversion. You must use a Timer for the task. (5-7: 40%)
6. Every 5 seconds an average value of the temperature samples is calculated.
8. Initially, there is no output to the LED. Assume that the initial room temperature is below 76 0F. (8-11: 30%)
9. When the average temperature reading is at a level corresponding to 76 0F, a PWM signal (duty cycle = 0.1) is sent to the LED. (At this time, the LED is dim).
10. The duty cycle changes proportionally to the temperature measured until it reaches 86 0F, at which time, a PWM signal with duty cycle = 0.95 is sent to the LED. Test your circuit using a heating tool to change temperature to above 86 0F. Observe if the system output is correct. (The LED changes its brightness until it reaches the brightest - 95% of the duty cycle). The duty cycle is fixed to 95% when the temperature is above 86 0F.
11. When the temperature reading is back to below 86 0F and then below 76 0F, the PWM signal becomes smaller and smaller and then disappears. Again observe the corresponding output.
The main program:
int main(void)
{
//Port Initializations
//Port Interrupt for switch at P1.X
//Set edge transition pattern
//Reset port interrupt flags
//Initial setting for the Timer
//Enable interrupt system
//Enter low power mode
//configure ADC
while(1)
{
//Set PWM duty cycle depending on the input temperature
//insert code for PWM
}
}
Code for PWM:
P2SEL |= BIT1;
TA1CCR0 = period - 1; //Set PWM for LED at P1.X
TA1CCR1 = period * D;
TA1CCTL1 = OUTMOD_7;
TA1CTL = TASSEL_2|MC_1;
Configure ACD:
void ConfigureAdc(void)
{
//revise code from Lab 5, SINGLE CHANNEL SINGLE CONVERSION
}
Port I/O ISR (assume that a pin in port 1 is used):
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
//Leave low power mode
//Enable WDT for 7-seg display
//Timer_A for timing of A/D conversions; 1 second intervals
//A/D Conversion setup
//display z-number digits
//reset Port I/O interrupt flags
}
In Timer A interrupt:
#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
switch(TAIV)
{
case 0x02: break;
case 0x04: break;
case 0x0A:
//if the input switch is on, do
{
//Get an A/D sample,
//If 5 samples are collected, take an average and display it. //Else keep looping for more samples
}
break;
}
}
Read AD Samples:
void getanalogvalues()
{
//modify code from Lab 5
}
Use Watchdog Timer Interrupt for display control:
// WDT interrupt service routine
#pragma vector=WDT_VECTOR //define the watchdog timer interrupt vector
__interrupt void WDT(void)
{
//modify code given in Lab 5.
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
