Timer Implementation MSP430F5529LP

Started by John777 2 years ago2 replieslatest reply 2 years ago92 views

Hello everyone! I am new to the world of microcontrollers. For the moment, i am using a MSP430F5529LaunchPad - Code Composer Studio 7.4 and I am trying to implement the following task:

“Design and implement a car belt controller. The controller will illuminate a red LED on the vehicle's car seat diagram if someone is sitting in a car seat and is not fastened within a fixed amount of time. If the passenger is fastened within the above space, the controller will turn on a green LED respectively. This system has three inputs and two outputs. The inputs are a Push Button Sensor (P1.1) to know when a person is sitting, a Push Button (P2.1) that recognizes whether the belt is tied or not by the passenger and a timer notifying that the required time has elapsed. The controller is idle when there is no one in the seat. When someone sits, the controller turns on the timer. If the stopwatch stops before the seat belt is tightened, the red LED lights up. If the seat belt is fastened in time, the green LED lights up and the controller enters a surveillance mode. During the surveillance it is checked whether the passenger continues to have the belt tied. When the passenger leaves the seat, the controller returns to idle status.”

So far, I wrote the following program:

#include <msp430.h>

#include <driverlib.h>

volatile unsigned short SEAT =0;

volatile unsigned short BELT =0;

void main()











while (1){



GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN7 );







I think it’s ok, but I don’t know how to implement the timer that lights the red LED to notify that someone is sitting in a car seat and is not fastened within a fixed amount of time (for example after 10secs).

I would really appreciate if someone could add to the above program the necessary code because my head is really going to explode!

[ - ]
Reply by jmford94September 3, 2018

There are timers in the MSP430 that you can configure to create the time delay needed.  Then you can trigger the timer off the seat switch.  Then if the timer expires before you get the belt switch, then you illuminate the red light. as soon as the belt switch is activated, you can reset the timer and turn on the green light.  

[ - ]
Reply by SolderdotSeptember 5, 2018

Besides the timer there is some flaw in your application. You check the status of the variables SEAT and BELT in your while(1) loop, however those are updated exactly once before the loop. So even if the value changes after the application has launched your application will not notice that.

Further, your application does not realy cover the requirements.

It should support multiple states. Here's a quick draft for the straight forward cases, some special cases are not contained:

Idle: This is the initial state the system assumes after reset. Proceed to "seated" if SEAT = 1, otherwise stay at "Idle"

Seated: On entry of this state start timer. Wait for belt being closed. Proceed to "Surveillance" if BELT = 1, proceed to "Alarm" in case timer expires, proceed to "Idle" if SEAT = 0, otherwise stay at "Seated".

Surveillance: On entry of this state stop timer. In case BELT = 0 proceed to "Alarm". In case SEAT = 0 proceed to "IDLE". Otherwise stay at "Surveillance".

Alarm: On entry of this state stop timer. In case BELT=1 proceed to "Surveillance". In case of SEAT=0 proceed to "Idle".