Tutorial 14 - Timmer Counter & Input Output Handling - Past Paper Discussion Part II (LO3 & LO4)
Tutorial 14 - Timmer Counter & Input Output Handling - Past Paper Discussion Part II (LO3 & LO4)
A client requested you to develop a water level controlling system for two water tanks as shown
in the Figure 3.1. Here tank 1 and 2 are connected to motor A and B, respectively. Each tank is
fitted with two water level detecting sensors and one water control valve. Sensors would trigger a
logic HIGH when the water level is above the sensor position and it gives a logic LOW when the
water level is below the sensor position. Both motors will be switched ON when they have been
given a logic HIGH, and will be switched OFF with logic LOW. Both control valves will be
switched ON (open) by giving logic HIGH, and OFF with logic LOW (close). Client needs a
controller to be designed to perform all the tasks given in Table 3.1. This system should be in the
highest-low power mode at the initial state (when switched on). Here, you are supposed to use C
language (with comments) and MSP430 as the controller device.
Figure 3.1
1 2 3 4 A B 1 2
/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
// output configured
//sensor 1
P1DIR &= ~BIT0;
// P1OUT |= BIT0;
P1IE |= BIT0;
P1IES &= ~BIT0;
P1IFG &= ~BIT0;
//sensor 2
P1DIR &= ~BIT1;
// P1OUT |= BIT1;
P1IE |= BIT1;
P1IES &= ~BIT1;
P1IFG &= ~BIT1;
//sensor 3
P1DIR &= ~BIT2;
// P1OUT |= BIT2;
P1IE |= BIT2;
P1IES &= ~BIT2;
P1IFG &= ~BIT2;
//sensor 4
P1DIR &= ~BIT3;
// P1OUT |= BIT3;
P1IE |= BIT3;
P1IES &= ~BIT3;
P1IFG &= ~BIT3;
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if((P1IFG & BIT0) && (P1IFG & BIT1) && (P1IFG & BIT2) && (P1IFG & BIT3))
{
P1OUT |= BIT4;
P1OUT |= BIT5;
P1OUT |= BIT6;
P1OUT |= BIT7;
P1IFG &= ~BIT0;
P1IFG &= ~BIT1;
P1IFG &= ~BIT2;
P1IFG &= ~BIT3;
if((P1IFG & ~BIT0) && (P1IFG & ~BIT1) && (P1IFG & BIT2) && (P1IFG &
BIT3)) {
P1OUT |= BIT4;
P1OUT &= ~BIT5;
P1OUT &= ~BIT6;
P1OUT |= BIT7;
P1IFG &= ~BIT0;
P1IFG &= ~BIT1;
P1IFG &= ~BIT2;
P1IFG &= ~BIT3;
}
Q4.
An ultrasonic sensor module requires a 10 Hz input clock signal to generate a high frequency
signal. This sensor comes with a push button for mode selection, which generates a 20 Hz signal
when the button is pressed for the first time. With the second push, the Low power mode 3 will
be activated. Mode selection button response should be recognized when only the button is
released after a push. Design a controller with MSP430 microcontroller to accommodate all
these features.
You may assume the following:
At startup, the input clock signal frequency should remain as 10 Hz.
Timer/Counters should be used to generate the input clock signals.
Clock frequency of the microcontroller is 1 MHz.
Use C as the programming language (with comments).
External interrupts may be used as required.
All port pins may be used as general purpose digital I/O.
The timer/counter (s) registers are 16 bit.
1/10 = 2 (X+1)/(1x10^6)
0.1 = 2(X+1)/10^6
Therefore, to generate a 10Hz signal TACCRO should be 49,999/2 for on stage = ~24,999 and off stage
~24,999
For a 30Hz signal, TACCRO = 16,665. Therefor for on stage 16,665/2 = ~8,332, for off stage ~8,332.
#include <msp430.h>
/*
* main.c
*
*/
//sensor 1
P1DIR &= ~BIT0;
// P1OUT |= BIT0;
P1IE |= BIT0;
P1IES &= ~BIT0;
P1IFG &= ~BIT0;
while(1)
{
__enable_interrupt();
if (k==0){
TA0CCTL0 = CCIE;
TA0CTL = TASSEL_2 + ID_3 + MC_1 ;
TA0CCR0 =24999; //10hz
// P1OUT ^= BIT4;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
k++;
P1IFG &= ~BIT0;
if (k==1){
TA0CCTL0 = CCIE;
TA0CTL = TASSEL_2 + ID_3 + MC_1 ;
TA0CCR0 =8332;
P1OUT ^= BIT5;
if (k==2){
__bis_SR_register (LPM3);
void configureClocks()
{ // Set system DCO to 2MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// Set LFXT1 to the VLO @ 12kHz 35
BCSCTL3 |= LFXT1S_2;
}