<< Chapter < Page Chapter >> Page >

The Basic Timer1 is set to generate an interrupt once every second.

The routine main() ends with the interrupts global activation and puts the device in low power mode, awaiting the next interrupt.

Basic Timer1 ISR begins by activating LED2, indicating the beginning of the routine execution and then switches the state of LED1. The counters are updated in cascade and their contents updated on the LCD, through routines LCD_sec() , LCD_min() and LCD_hour() . The routine ends with switching the state of the clock separation points. Finally, LED2 is turned off.

System configuration

Watchdog timer

The Watchdog Timer is disabled with the objective of reducing energy consumption, but giving up the protection afforded by it. This peripheral is configured by the WDTCTL register. Its access is protected by a password. The value to disable it:

WDTCTL = WDTPW | WDTHOLD; // Stop WDT

Fll+ configuration

A 32.768 kHz crystal is applied to the oscillator LFXT1. Since it is possible to select the internal capacitors using software, the value to write to the FLL_CTL0 configuration register to select the 8 pF capacitors is:

FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal

Taking into consideration the change mentioned earlier to the FLL+ module, what are the frequencies of each of the clock signals?

ACLK = _________________;

MCLK = _________________;

SMCLK = ________________;

Led ports configuration

LED1 and LED2 are connected to ports P2.2 and P2.1 respectively. How should they be configured so that just the bits related to these ports have digital output functions?

P2DIR |= 0x06; // P2.2 and P2.1 as output

How should the P2OUT register be configured so that the application starts with LED1 on and LED2 off?

P2OUT |= 0x04; // LED1 on and LED2 off

Basic timer1 configuration

Basic Timer1 should generate an interrupt once every second. It uses two counters in series, so that the input of the BTCNT2 counter is the output of the BTCNT1 counter divided by 256. The BTCNT1 counter input is the ACLK with a 32.768 kHz frequency. If the selected output of the BTCNT2 counter is divided by 128, what is the time period associated with the Basic Timer1 interrupt? _________

BTCTL = BTDIV | BT_fCLK2_DIV128; // (ACLK/256)/128 IE2 |= BTIE; // Enable Basic Timer1 interrupt//********************************************************* // BasicTimer1 Interrupt Service Routine//********************************************************* #pragma vector=BASICTIMER_VECTOR__interrupt void basic_timer_ISR(void) {P2OUT |=0x02; // LED1 turn on P2OUT ^=0x04; // LED2 tooglesec++; // increment secondsLCD_sec(); // refresh seconds field in LCDif (sec == 60) // one minute was pass {sec = 0; // reset seconds counter min++; // increment minutesLCD_min(); // refresh minutes field in LCD if (min == 60) // one hour was pass{ min = 0; // reset minutes counterhour++; // increment hours LCD_min(); // refresh hours field in LCDif (hour == 24)// one day was pass {hour = 0; // reset hours counter }} }if (sec&0x01) // toogle clock dots {P3_DOT_ON; P5_DOT_ON;} else{ P3_DOT_OFF;P5_DOT_OFF; }P2OUT&=~0x02; // LED1 turn off }

Low power modes

The task simply updates the counters periodically and refreshes the LCD contents. It is possible to configure the registers for an energy-efficient operation.

Which low power mode should be used? _____________

Which system clocks are activated in the low power mode selected? _________________

BIS_SR(LPM3_bits + GIE); // Enter LPM3 + interrupts enabled

Analysis of operation

System clocks inspection

The MCLK, SMCLK and ACLK system clocks are available at ports P1.1, P1.4 and P1.5 respectively. These ports are located on the SW2, RESET_CC and VREG_EN lines, which are available on the H2 Header pins 2, 5 and 6. All these resources are available because the Chipcon RF module is not installed and SW2 is not used.

Using the Registers view, set bits 1, 4 and 5 of P1SEL and P1DIR registers, to choose the secondary function of these ports configured as outputs. By connecting an oscilloscope to those lines, it is possible to monitor the clock signals.

What are the values measured for each of the system clocks?

ACLK: ________________

SMCLK: _______________

MCLK: ________________

Isr execution time

The Basic Timer1 ISR execution time is fundamental to energy conservation, in order to extend the life of the system battery. The routine execution time can be measured by connecting the oscilloscope to port P2.1, which controls LED2. This output is available on pin 2 of Header H4.

The execution time of this routine varies with the number of the counter updates and respective updates to the LCD. What are the times measured for each of these situations and what their frequencies?

Seconds update: ______ with a time period of ______

Seconds and minutes update: ______ with a time period of ______

LCD fields update: ______ with a time period of ______

If the developer chooses to update all the LCD fields at each interrupt, the time required is much greater than the solution presented. Efficient programming contributes to a reduction in the system power consumption.

Measurement of electrical current drawn

The power consumption was discussed in the previous point. The electrical power required by the system during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates the electric current taken by device during operation.

What is the value read? __________

This example and many others are available on the MSP430 Teaching ROM.

Request this ROM, and our other Teaching Materials here (External Link)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching and classroom laboratories based on the “ez430” and "experimenter's board" msp430 microcontroller platforms and code composer essentials. OpenStax CNX. May 19, 2009 Download for free at http://cnx.org/content/col10706/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching and classroom laboratories based on the “ez430” and "experimenter's board" msp430 microcontroller platforms and code composer essentials' conversation and receive update notifications?

Ask