This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pulse width measurement using T3IN ONLY!

Hi,
I had a design counting pulses from pin T3IN on GPT1-T3. The design now requires a pulse width to be measured instead of pulses being counted. Our hardware has access ONLY to T3IN, not CAPIN etc.

Problem: How can I set up GPT1/2 to measure the pulse width with only T3IN pin ?

Still getting to grips with capture/reload and interrupts, but reckon someone's done this before...!

Thanks for any advice.
Rup.

  • I've not used this feature so far, but checking the XC161 user manual, I think that you have to use GPT1 in Gated Timer Mode. Just quoting the description in the user manual:
    If T3M = 010B, the timer is enabled when T3IN shows a low level. A high level at this line stops the timer. If T3M = 011B, line T3IN must have a high level in order to enable the timer. Additionally, the timer can be turned on or off by software using bit T3R. The timer will only run if T3R is 1 and the gate is active. It will stop if either T3R is 0 or the gate is inactive.

    Thomas

  • Thanks for your note Thomas.

    The next sentence in the manual after your extract reads:
    Note: A transition of the gate signal at pin T3IN does not cause an interrupt request.

    This is the killer for me!
    Best for me would be an interrupt (or PEC transfer) to take the result into a variable. I want to avoid a timer value for both the mark and the space of the PWM signal. So triggering an IRQ on (either) a rising or falling edge would be perfect. CAPIN through CAPREL in GPT2 seems to be exactly what I need - but I don't have access to CAPIN pin!

    I think I can make a workaround by sensing the status of T3IN when I read GPT1_T3 - but this will be asynchronous with the PWM signal.

    Rup

  • You can capture timer T5 value to CAPREL register on T3IN transition(s), and get an interrupt. Read timer block GPT2 description.

    Sauli

  • Thanks Sauli,
    I ended up coding a solution through GPT5, T3 and CAPREL as the manual shows, although this gives an interrupt on both edges, (unless I've misunderstood it)which as I said I don't want. The benefit is measurement of the mark and space values for safety checking, so that'll do.