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.

MSP430 How to read capture

Hi,

I am using sample code supplied by TI "msp430g2xx3_ta_21.c" to produce a PWM (3.2KHz) and then Capture the signal on Pin 1.2. this seems to work fine. I have verified 3.2K on a scope. But i am having trouble interrupting how to read the frequency. 

The way i am approaching this is to put a brake point at this line "ON_Period = FEdge-REdge1; // On period" and then i view the DEC value of "Period" which reads 2436. The trouble i have is converting this value to frequency. I assumed it to be  65535/2436 but this is not the case.

any help would be good:

thanks,

Period = REdge2 - REdge1; // Calculate Period
ON_Period = FEdge-REdge1; // On period

  • Damien Gilbane said:
    But i am having trouble interrupting how to read the frequency. 

    You can measure frequency by counting cycles during known time (1 sec for example) or you can measure length of single interval - if you have good high speed time reference (HF XTAL) and timer available.

  • Damien Gilbane said:
    The trouble i have is converting this value to frequency. I assumed it to be  65535/2436 but this is not the case.

    The tick difference "period" is the number of timer ticks between the edges. The timer register width is unimportant here (it is only of interest to calculate the overflow correction (which is done automatically by the subtraction, if both values are unsigned int) and the detection range (periods greater than 65535 timer ticks are aliased modulo 65536).

    To calculate the frequency, you'll need to know the timer clock frequency. Divide it by the tick count and you have the resulting PWM frequency. If with 10MHz Timer clock speed, two subsequent edges are 100 ticks apart, then the observed frequency is 10MHz/100 = 100kHz.

    So apparently, with 3.2kHz PWM frequency and 2436 counts, your timer seems to be clocked with 7.795200MHz (inverse calculation).

    However, this is for the full period (two subsequent identical edges).

    If you want to know the 'on' period, this is no frequency at all. Just a time span. Here things become a bit tricky.
    For the PWM frequency (and therefore the total period of one wave) you need to measure two subsequent identical edges (like above, just divide the pulse count by frequency and you'll get the period duration in Hz)
    Same for the difference between two different edges (rising, then falling). Divide it by the clock frequency and you'll get the high (or low) pulse duration. Divide it by the total wave duration and you'll get the duty cycle. Or, simpler, divide the tick difference between the two different edges by the tick count between two identical edges.

**Attention** This is a public forum