<< Chapter < Page Chapter >> Page >
We will explore a energy-efficient way of measuring time by using timers. A timer is a register which counts up to a certainnumber at each clock tick. During this, the MSP430 can switch to a low-power mode. Each time the timer threshold isreached, a timer interrupt wakes the MSP430, which toggles the two LEDs.

Running the code

  • Copy the code presented below Alternatively, this code is available in the downloadable source code . Open source_code/iar_v4.11/lab_ezwsn.eww with IAR. The project corresponding to this section is called led_timer . .
  • Compile and download the code onto the board (Ctrl+D) .
  • Let the code execute (F5) , both LEDs should blink.

#include "io430.h" #include "in430.h"int main( void ) {WDTCTL = WDTPW + WDTHOLD; P1DIR |= 0x03;BCSCTL3 |= LFXT1S_2; TACCTL0 = CCIE;TACCR0 = 1000; TACTL = MC_1+TASSEL_1;__bis_SR_register(GIE+LPM3_bits); }#pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void){ P1OUT ^= 0x03;}
Blink LEDs using timer interrupts

Some keys for understanding the code:

  • Line 7 switches on the ACLK by sourcing it to the VLO , a very low power crystal oscillator inside the MSP430, different from the more accurate and energy hungry DCO (Digitally Controlled Oscillator). The DCO drives the MCLK and the VLO the ACLK. ACLK is used for the timer; MCLK for executing code.When there is no code to be executed (i.e. when waiting for interrupts), a low power mode (in which DCO is switched off) can be used.
  • Line 8 enables interrupts for Timer_A .
  • Line 9 sets the value up to which Timer_A will count.
  • Line 10 tells Timer_A to count up ( MC_1 ) each time ACLK ticks ( TASSEL_1 ).
  • Line 11 enables interrupts globally and enters LPM3. Note that LPM3 leave only ACLK running, which is exactly what we need because our Time_A runs off ACLK.

Measuring time

We use extension pin P6 to measure time exactly. Therefore:

  • add line P2DIR |= 0x08; after line 6 to declare P2.3 as output;
  • add line P2OUT ^= 0x08; after line 16 to toggle P2.3 after toggling the LEDs;
  • connect a probe of your oscilloscope to extension port P6 , ground on extension port P1 . Power on the board, you're now able to read the duration between two toggles.
  • reprogram your board with TACCR0 values between 1000 and 30000; verify that the times obtained are close to the following:

Duration when using timers
TACCR0 value measured toggle duration
500 47.40ms
1000 95.00ms
10000 950.0ms
20000 1890ms

This table informs you that 1000 ACLK cycles take 95.00ms, one ACLK cycle thus takes 95μs, the VLO on the MSP430 thus runs at 10.5kHz. In theory, the VLO runs at 12kHz; the exact value depends on the voltage of the batteriesand on the temperature.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500. OpenStax CNX. Apr 26, 2009 Download for free at http://cnx.org/content/col10684/1.10
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?

Ask