<< Chapter < Page Chapter >> Page >
This example shows a first way of measuring time. __no_operation() instructs the MSP430 to do nothing during one cycle; by repeating this many times, time can bemeasured. As this is neither accurate nor energy-efficient, a more elegant technique will be shown in section 3.4 .

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_loop . .
  • 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; int i;P1DIR |= 0x03; while (1) {P1OUT ^= 0x03; for (i=0;i<10000;i++) { __no_operation();} }}
Blinking LEDs using an active waiting loop

Some keys for understanding the code:

  • Line 9 : the operator ^= causes 1s to become 0s and vice-versa (aka toggling).In case of our LEDs, it causes their on/off state to change;
  • Line 10 : __no_operation(); causes the MSP430 to do nothing for one cycle.

Measuring time

We want to measure time precisely with the oscilloscope. This can, in theory, be done by measuring the voltage at the LEDs, but it is hard to hold the probes right. We will therefore use extension pin P6 represented in the figure below, which is connected to P2.3 on the MSP430.

extension_pins
The extension pins on the eZ430-RF2500 board. Note that the pins with even number (shown on the right) are located on the edge of the board, and are thus accessible more easily.

We will configure P2.3 to be output and toggle its state together with the state of the LEDs. Therefore:

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

Duration when using an active waiting loop
threshold value for i measured toggle duration
1000 6.72ms
10000 67.2ms
20000 134.0ms
30000 201.0ms

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