<< Chapter < Page | Chapter >> Page > |
source_code/iar_v4.11/lab_ezwsn.eww
with IAR. The project corresponding to this section is called
led_timer
. .#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:
Timer_A
.Timer_A
will count.Timer_A
to count up (
MC_1
) each time ACLK ticks (
TASSEL_1
).Time_A
runs
off ACLK.We use extension pin
P6
to measure time exactly. Therefore:
P2DIR |= 0x08;
after line 6 to declare
P2.3
as output;P2OUT ^= 0x08;
after line 16 to toggle
P2.3
after toggling the
LEDs;P6
, ground on extension
port
P1
. Power on the board, you're now able to read the duration between two
toggles.TACCR0
values between 1000 and 30000; verify that
the times obtained are close to the following: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.
Notification Switch
Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?