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.

capture mode to a frequency counter

THIS MY CODE:

unsigned int buffer[20];
unsigned char i=0;
void main(void)
{
  volatile unsigned int i;

  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;
  InitializeLcm();
  P1SEL |= BIT1;                            // P1.1 CCI0A
  TACTL = TASSEL_2 + MC_2 + ID_3;                  // SMCLK, contmode
  TACCTL0 = CM_1+CCIS_0+SCS+CAP+CCIE;
 
  CCTL1 = CCIE;            // Habilita interrupção do Timer A...
  CCR1  = 31250;           // ... a cada 31.250 ciclos ...
 
   _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
 
}

#pragma vector=TIMERA1_VECTOR
__interrupt void TimerA1(void)
{
    LcmSetCursorPosition(1,0);
    printDecimal(i);
    i = 0;
    CCR1 += 31250;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0(void)
{
 
buffer[i++] = TACCR0;
    if (i>10)
    __no_operation();                       // PLACE BREAKPOINT HERE
                                            // VIEW 'BUFFER' VARIABLE
}

----------------------

I am trying to one frequency counter, in this code, the counter read the value of i, set = 0 and restart the count of pulses

but don´t work... :(

-------------------------------

  • Normally, an ISR cannot be interrupted by an ISR. Priorities apply only if two interrupts compete to be handled. Inyour TimerA1 ISR, oyu do lengthy operations like setitng the cursor position or outputting decimals to the LCD. During this time, the TimerA0 capture ISR is not executed and you'll likely get capture overflows, missing one or more pulses.

    Your TimerA1 ISR should only do the two assignments and then wake main from LPM and let main do th edisplay (then main can go back to sleep).

    Also, using a local variable that has the same name as a global one isn't the best idea. And a local volatile variable makes no sense, unless you pass its reference globally. The compiler knows this and ignores the volatile modifier.
    THe global 'i', however, requires the modifier if main and ISR both access it (whcih will be necessary once you move your display code out of the ISR)

**Attention** This is a public forum