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.

TAR values obatianed in two ways

Other Parts Discussed in Thread: MSP430F1232

I have a question about TAR (Timer_A counter) values.

Attached at the bottom is my sample code.  I used MSP430F1232 and Iar EW IDE.

 

When I stop with breakpoints at "case 10:" sentence and see the TAR values multiple times,

I obtain TAR values like "4354, 10969, 51058". They looks some random values.

 

On the other hand, when I stop with breakpoints at "if(cnt > 7) { _NOP() }", I see the

{1, 1, 1, 1, 1, 0, 0 ....} in the array tar[ ]. They seems correct (meaning set zero by overflow).

 

I use ACLK (external crystal of 32768Hz) as a clock source. When I use external crystal,

 is it correct that  the TAR countup is not stopped while I stop the software with breakpoints

causing the difference shown above?

 

I have been using MSP430 for over 1 years now,  but did not notice this kind of feature.

 

=====================

#include  <msp430x12x2.h>
unsigned int tar[10];
int cnt = 0;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;            
  P1DIR |= 0x01;                       
  TACTL = TASSEL_1 + MC_2 + TAIE;

  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/ interrupt
}

#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
  switch( TAIV )
  {
    case  2:  break;             
    case  4:  break;                     
    case 10:  P1OUT ^= 0x01;              
            tar[cnt++] = TAR;
            if(cnt > 7) {
                _NOP();  
            }
                _NOP();
              break;
  }
}

 

 

 

 

 

 

 

 

  • In IAR EW, after you start debugging, go to Emulator -> Advanced -> Clock Control.  There you which clocks and timers (etc) to stop when the emulator stops (e.g., at breakpoints).  The options you see are dependent on your specific MSP430.  It is a great feature, but your MSP430 might not support it.

    Many "small" MSP430s merely mask off the DCO output during emulation stop.  That doesn't cover ACLK sourced by XT1, so it keeps on ticking.

    Also, I realize you posted "test" code, but...

    • You should consider reading TAR using a majority-vote mechanism.  Keep reading TAR until you get the same value twice in a row.  Then that's your reading.  This reading technique is really important because there is a tiny instant during which TAR is in the process of counting (at the ACLK edge).  If you read TAR at just the wrong time, you can get a wild value.
    • You should consider using the __even_in_range(var, limit) directive in your switch statement.  Switch statements can be pretty slow, and you can speed them up significantly when your switching values are all even within a particular range, which is exactly the case for the xIV registers.  This should improve your latency enough to fill your array with zeros instead of getting some 1s.

    Jeff

  • Thank you very much for your reply, Jeff Tenney.

     

    I checked the "Emulator -> ..." option, but the MSP430F1232 was not supported with this function.

    And ACLK does not stop according to your reply. Then I can get it about the behavior of what I checked.

     

    Also, thank you very much for the exstra information on effectively using MSP430s. When I use

    TAR values, I will use the majority-vote mechanism. And I will consider to use __even_in_range.

     

    Best regards

     

**Attention** This is a public forum