I want to measure an input signal on P1.1 using MSP430G2112 and to display it on a LCD conected on P2. I use Timer0_ A and interrupt routine.
If routine is activated LED P1.6 flashes. The problem is that I can't read the value of time that pass between 2 interrupts.
I put the TACCR0 value in "nr" variable and display it on LCD but the value is 0.
I post the code and please tell me where I am wrong and how is correct.
Many thanks!
#include "msp430.h"
//LCD initiation
unsigned int nr, dif, Compare, Oldcapture;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
InitializeLcm() ; // defined in LCD initiation
ClearLcmScreen(); // defined in LCD initiation
__delay_cycles(65000);
BCSCTL3 |= XCAP_3;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1DIR = ~BIT1; //imput signal P1.1
P1SEL |= BIT1;
P1OUT |= BIT6; // P1.6 initial state ON
P1OUT &= ~BIT0; // P1.0 initial state OFF
TACTL |= TASSEL_1 + TACLR + MC_2; // I use an 32768 Hz watch crystal
TACCTL0 |= CM_1+ CCIS_0 + CAP;
CCTL0 |= CCIE;
TACCR0=65000;
_BIS_SR(GIE);
while(1)
{
display (nr); // defined in LCD initiation
display(dif);
__delay_cycles(10000);
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
TA0CCTL0 &= ~CCIFG; // Capture occured, clear flag
P1OUT ^= BIT6;
if (w<100)
{
Compare = TACCR0;
dif = Compare - Oldcapture;
Oldcapture = Compare;
w++;
}
else
{
w=0;
P1OUT ^= BIT0;
nr = TACCR0;
}
}