This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I copied a simple test program from MSP430 examples that uses Timer_A for frequency capture. Basically the captured_clocks buffer should contain the pulse widths between the input pulses. So if I feed 1 kHz square wave into the P1.3 (pin 3) and set the clock for 1 MHz the buffer should have values [1000,1000,1000]. However when I run the program I only get garbage in the buffer (e.g. [62,26,52678]). Any ideas what goes wrong? I'm using MSP430G2553 with Launchpad.
#include "msp430g2553.h"
unsigned int previosly_captured_clock = 0;
unsigned int captured_clocks[10];
unsigned char i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
P1SEL |= BIT1; // P1.1 timer input
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
TACCTL0 = CM_1+CCIS_0+SCS+CAP+CCIE; // Positive edge + Capture input select 0 + Synchronous capture + Capture mode + Capture interrupt enable
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
unsigned int captured_clock = TACCR0;
captured_clocks[i++] = captured_clock - previosly_captured_clock;
previosly_captured_clock = captured_clock;
if (i>10) {
__no_operation(); // Breakpoint here
i = 0;
}
}
First of all, I have never worked with this uC family, so my words are a basic guideline.
Sami Lakka said:P1SEL |= BIT1; // P1.1 timer input
Since you are using the pin 1.3, moreover you have selected the pin as peripheral module function, do not have to configure this pin as an input (PxDIR &= ~BITX)to a correct functionality?
Sorry for not giving you more information.
Hi,
Thanks for the suggestion, unfortunately it did not help. I'm having a little bit hard time configuring the Timer_A correctly. There aren't any samples that I know of which use Timer_A in capture mode with MSP430G2553.
Well, isn't P1.1 connected to the FET for the backchannel UART?
On LaunchPad V1.5, the default connection is P1.1 connected to the incoming data, so maybe your square wave just fights the TUSB serial signal on that pin.
**Attention** This is a public forum