This page is optimized for mobile devices, if you would prefer the desktop version just
click here
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 calledled_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.
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 declareP2.3
as output; - add line
P2OUT ^= 0x08;
after line 9 to toggleP2.3
after toggling the LEDs; - connect a probe of your oscilloscope to extension port
P6
, ground on extension portP12
; - 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.
threshold value for
i |
measured toggle duration |
1000 | 6.72ms |
10000 | 67.2ms |
20000 | 134.0ms |
30000 | 201.0ms |
Read also:
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.