{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
\f0\fs24 \cf0 #include <msp430x20x2.h> \
\
#define LED0 BIT0\
#define LED1 BIT6 \
#define BUTTON BIT3\
\
int i, j;\
volatile int interval=0, lastcount=0, count = 0;\
\
int main(void)\
\{\
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer\
P1DIR |= (LED0 + LED1); // Set P1.0 to output direction \
// P1.3 must stay at input\
P1OUT &= ~(LED0 + LED1); // set P1.0 to 0 (LED OFF)\
P1IE |= BUTTON; // P1.3 interrupt enabled\
TACCR0 = 32768;\
TACTL = TASSEL_1 + MC_1 + TACLR;\
P1IFG &= ~BUTTON; // P1.3 IFG cleared\
\
\
__enable_interrupt(); // enable all interrupts\
for(;;)\
\{\}\
\}\
\
void test()\
\{\
P1OUT ^= LED0;\
count=TAR;\
interval=count-lastcount;\
lastcount=count;\
if(interval<165 && interval>162)\
\{\
P1OUT ^= LED1; // P1.0 = toggle\
\}\
\}\
\
\
#pragma vector=TIMERA0_VECTOR // Timer A0 interrupt service routine\
__interrupt void Timer_A (void)\
\{\
\}\
\
\
// Port 1 interrupt service routine\
#pragma vector=PORT1_VECTOR\
__interrupt void Port_1(void)\
\{\
test();\
P1IFG &= ~BUTTON; // P1.3 IFG cleared\
\}}
I am running this code on a MSP430 Launchpad, and when I hit the button on P1.3 the red LED goes on and off. When I feed it a 200 Hz square wave pulse it does not light up the green LED as expected.
The way I am calculating is...
TACCR0=32768; //32768 counts per second
200 Hz means 5ms time period
Counts in 5 ms = .005*32768 = 163.84 counts
Any help will be greatly appreciated.