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.

MSP430G2533: Accurate Time measurement using Timer A

Part Number: MSP430G2533

I wish to use the MSP430G2533 to make an accurate time measurement using an external Crystal Clock and an external trigger. I realize that the XIN/XOUT can not be used with a high frequency crystal.  I looked at the specifications for digital IO and did not see a maximum frequency or minimum period specification.  Can I connect an 8MHz or even a 4MHz crystal oscillator to P1.0 (TA0.TACLK) and use timer A0 with the edge trigger using P1.1 (Timer 0 CCI0A) to make edge to edge time measurements. I assume the same answer would apply if I use P3.7 (TA1.TACLK) as the high frequency clock input and P2.5 (Timer 1 CCI2B) to make edge to edge time measurements.

  • Hi Larry,

    According to the MSP430x2xx family users guide, the LFXT oscillator is capable of supporting higher frequency crystals, resonators or input clock frequencies when operating in HF mode (XTS = 1).

  • Hello Dennis,

    The reason I did not think the MSP430G2533 supported HF mode was in Figure 5.1 (MSP430x2xx Family Guide). It says "MSP430F20xx, MSP430G2xx1, MSP430G2xx2, MSP430G2xx3: LFXT1 does not support HF mode". Is the "MSP430G2xx3" a mistake in this statement?
  • Hi Larry,

    You are correct. I missed the MSP430G2xx3 or it didn't register with me - sorry.
    The timer modules can be clocked as fast as the system clock, but since you want to drive it through and IO pin, let me check to see if there are any the limitations.
  • "to make edge to edge time measurements."

    unless the input capture modules has some really long edge prescalers or DMA, that kind of approach isn't advisable for measuring fast pulse trains.

    instead, count the input (unknown) pulse vs. a known pulse - like your system clock: count how many edges in one pulse train vs. a given number of edges in another pulse train.

  • Thanks for help, I did not clearly state what I was measuring. Here is more detail.

    I wish to accurately measure frequencies less than 800Hz. So to get an accurate (better than 0.1Hz) frequency measurement would take 10 seconds (0.1Hz) or 100 seconds for 0.01Hz accuracy. Instead I wish to use either an 8MHz or 4MHz clock to Timer A and use a + to + edge or - to - edge to accurately measure the number of 125nsec (8Mhz) or 250nsec (4MHz) clocks for each period. Use interrupts to store the count values, subtract last from newest value, store the difference value, then average 8, maybe 16 of these difference values to get the measured frequency as a time measurement. At these low frequencies there is over a 1000usecs between interrupts. Please let me know if the MSP430G2533 Timer A 0 or 1 can support being clocked at 4MHz or 8Mhz through the IO ports and that the Edge Triger IO Port has less than a 125nsec delay.
  • not sure why you wish to clock those pins but the simplest solution would be to clock your mcu with a 8Mhz or a 4Mhz clock, and apply the unknown frequency to the input capture pin of a timer.

    assuming 800Hz signal, you would have an interval of 8Mhz / 800Hz = 10K ticks. at +/- 1 tick, that means your accuracy would be 1/10K * 800 = 0.08Hz. alternatively, counting every 8 edges would be enough for 0.01Hz accuracy.

    using external interrupts would also work, with more jitters obviously.

    anything else is too complicated.

    the ISR would look something like this:

    static uint16_t tick_prev=0; //tick at the first edge
    static uint8_t tick_cnt=0; //tick counter
    uint16_t tick=CCRx; //read input capture register

    //clear the flag
    if (++tick_cnt == TICK_CNT) { //sufficient edges have arrived?
    tick_cnt = 0; //reset tick_cnt
    tick_pr = tick - tick_prev; //calculate the period
    tick_prev = tick_pr; //update first edge for the next measurement
    }


    TICK_CNT is the number of edges you wish between two measurements. the code assumes a free running clock at 0xffff and time between the two edges is less than 0xffff ticks.
  • Hello Danny,

    I believe we are making the measurement the same way, but I believe you are saying I can input the 8MHz crystal Oscillator through the XIN (P2.6). I did not realize that was possible since HF mode was not available.

    Does this mean that HF mode just applies to crystals, so that an external 8MHz Crystal Oscillator through XIN becomes LFXT1CLK which becomes ACLK at 8MHz?

    Is this how to set up XIN as an external Crystal Oscillator:
    P2DIR for P2.6= 0 (an input)
    P2SEL for bit 6 = 1
    P2SEL2 for bit 6 =0
    and then bit 7 (XOUT) is just another IO pin with PSEL bit 7=0, P2SEL2=0
  • Hi Larry,

    It turns out there is no spec for the maximum frequency on the GPIO when configured as an INPUT. When configured as an output the GPIO can operate at system maximum clock of 16MHz with little or no load and 8MHz when loaded (refer to datasheet for details).

    The TIMER_A module can be clocked up to the system maximum clock of 16MHz, so from what I'm being told, you should be able to to provide a clock signal at 8MHz to the TIMER_A TACLK input.
  • Hello Larry,

    It has been some time since your last response, so I'm assuming you have resolved your issue and I will be closing this thread.
    If this is not the case and you need additional help, you can re-open this same thread.

**Attention** This is a public forum