0% found this document useful (0 votes)
9 views6 pages

Tutorial 14 - Timmer Counter & Input Output Handling - Past Paper Discussion Part II (LO3 & LO4)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Tutorial 14 - Timmer Counter & Input Output Handling - Past Paper Discussion Part II (LO3 & LO4)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Tutorial 14 – Past paper Discussion Part II

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

Sensor Motor Valve

1 2 3 4 A B 1 2

HIGH HIGH HIGH HIGH OFF OFF ON OFF

LOW LOW HIGH HIGH ON OFF OFF ON


Table 3.1: Client request
Q3.
#include <msp430.h>

/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

// output configured

//BIT4 & BIT 5 = MOTOR


//BIT6 & BIT7 = ACTUATOR
P1DIR = BIT4 + BIT5 + BIT6 + BIT7; // Direction set as output
P1OUT &= ~BIT4 + ~BIT5 + ~BIT6 + ~BIT7; // Initial logic law for all
outputs

// sensor input configured sensor 1 = BIT0, sensor 2 = BIT1, sensor 3 = BIT2,


sensor 4 = BIT3

//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;

// Low power mode 4 switched on


__bis_SR_register(LPM4_bits + GIE);

#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.

State any other assumptions you make in your answer.

With 10Hz signal,

Period in second = DIV (TACCRO+1)/Input clock frequency

1/10 = 2 (X+1)/(1x10^6)

0.1 = 2(X+1)/10^6

TACCRO value = 49,999

Period = on time + off time

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
*
*/

volatile unsigned int k=0;


int main(void) {
void configureClocks();
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR = BIT4+BIT5; // Direction set as output


P1OUT &= ~BIT4 + ~BIT5; // Initial logic law for all outputs

// sensor input configured push button 1 = BIT0

//sensor 1
P1DIR &= ~BIT0;
// P1OUT |= BIT0;
P1IE |= BIT0;
P1IES &= ~BIT0;
P1IFG &= ~BIT0;

while(1)
{

__enable_interrupt();

//__bis_SR_register (LPM0 + GIE);

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;

//Timer A0 interrupts service routine


#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)

if(k==0){ P1OUT ^= BIT4;}

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;
}

You might also like