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.

MSP430F1611 timer capture mode

Other Parts Discussed in Thread: MSP430F1611

Hi

I am using comparator to detect 16kHz signal at CA0 compared with 0.5Vcc. I can see CAOUT signal accordingly which verifies that comparator is working fine. Now I want to use timer in capture mode to read the pulse duration (CCI1B internal) I configured the comparator and timer module as following but I am unable to store the timer values. Please guide me

P6OUT = 0x00; 

CACTL1 = CARSEL+CAREF_2; // Comp. A Int. Ref. enable on CA1 Comp. A Int. Ref. Select 2 : 0.5*Vcc
CACTL2 = P2CA0+CAF+CAOUT; // Comp. A Connect External Signal to CA0

CACTL1 |= CAON+CAIE ;  

I am not sure about timer configuration

TACTL = TASSEL_2 + ID_0 + MC_2; // Use SMCLK (1 MHz Calibrated), no division, continuous mode
TACCTL1 = CCIS_1 + CAP + CCIE + SCS +CCI ; // Use CAOUT for input, synchronize, set to capture mode, enable interrupt for TA1.
// NOTE: Capturing mode not started.
TACCTL1 |= CM_2; // start TA1 capture on falling edge.

 

#pragma vector = TIMERA1_VECTOR
__interrupt void TA1_ISR(void) {
if (TAIV==0x02)
{
time=TACCR1;
printf("%d TACCR1", time);   // this always print time=0
TACCTL1 &= ~(CM_2 + CCIFG + CCIE); // Stop TA1 captures, clear interrupt flag.
TACTL &= ~MC_2; // turn off TA.
P6OUT = 0x01; // Done measuring
count++;
}

Any guidance would be helpful.

  • What you mean by "unable to store timer values"? You definitely shall NOT try to printf() anything from ISR. Instead store value in global volatile variable and print it in main() loop

  • Here is a new approach where I am using CAOUT output (16kHz square wave ) generated from comparator to fed in to TA0
    // MSP-FET430P140 Demo - Timer_A0, Capture of ACLK/8 using SMCLK
    //
    SMCLK = 1.07MHz
    // MSP430F1611
    // -----------------
    // /|\|
    // | |
    // | P2.2/CAOUT|---+
    // | | |
    // | P1.1/TA0|<--+
    // | |
    // | P1.0|--->LED

    //
    //******************************************************************************

    #include <msp430.h>
    #include "msp430f1611.h"
    unsigned int new_cap=0;
    unsigned int old_cap=0;
    unsigned int cap_diff=0;

    unsigned int diff_array[16]; // RAM array for differences
    unsigned int capture_array[16]; // RAM array for captures
    unsigned char index=0;
    unsigned char count = 0;

    int main(void)
    {
    volatile unsigned int i;
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    //1.07MHz
    BCSCTL1 = RSEL2;// RSEL=4(100)
    DCOCTL = DCO1+DCO2;
    P1DIR = 0x01; // Set P1.0 out,1.1 input dir
    P1OUT &= ~0x01; // LED off
    P1SEL = 0x02; // Set P1.1 to TA0
    //P2DIR = 0x01; // P2.0-ACLK
    //P2SEL |= 0x01;
    //BCSCTL1 |= DIVA_3; // ACLK/8
    P2DIR &= ~0x08; // P2.3 i/p direction
    P2DIR |= 0x04; // P2.2 0/p direction
    P1DIR |= 0x10; // P1.4 output SMCLK
    P2SEL |= 0x0C; // CA0 select, caout
    P1SEL |= 0x10; // SMCLK output P1.4

    //comparator
    CACTL1 = CARSEL+CAREF_2; // Comp. A Int. Ref. enable on CA1
    // Comp. A Int. Ref. Select 2 : 0.5*Vcc
    CACTL2 = P2CA0+CAF+CAOUT; // Comp. A Connect External Signal to CA0
    // Comp. A Enable Output Filte
    CACTL1 |= CAON;
    CACTL1 |= CAON+CAIE ;


    //Timer

    CCTL0 = CM_1 + SCS + CCIS_0 + CAP + CCIE; // Rising edge + CCI0A (P1.1)
    // + Capture Mode + Interrupt

    TACTL = TASSEL_2 + MC_2; // SMCLK + Continuous Mode

    __bis_SR_register(LPM0_bits + GIE); // LPM0 + Enable global ints
    }

    #pragma vector=TIMERA0_VECTOR
    __interrupt void TimerA0(void)
    {
    new_cap = TACCR0;
    cap_diff = new_cap - old_cap;

    diff_array[index] = cap_diff; // record difference to RAM array
    capture_array[index++] = new_cap;
    if (index == 16)
    {
    index = 0;
    P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
    }
    old_cap = new_cap; // store this capture value
    count ++;
    if (count == 32)
    {
    count = 0;
    __no_operation(); // SET BREAKPOINT HERE
    }

    }

    count in ISR never reaches 32. I am not sure how to calculate the the frequency as 16kHz with diff_array which is 0 all the time.
  • You set CAIE. But I don’t see a comparator ISR in your code. If there is none, then as soon as the comparator triggers, the MSP resets (the comparator interrupt has a higher priority than the TimerA interrupt, so it is granted first - and jumps into the void, eventually resetting the MSP.
  • All the global data/variables you access from ISR, shall be volatile. Does count reaches, let' s say 2? Are you sure your ISR is fired at least one time?

**Attention** This is a public forum