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.

How to count PWM pulses in TM4C129

Hi All,

We are using TM4C1297 controller with TI-RTOS to generate four PWM pulses (PWM0, PWM1, PWM2 and PWM4). We need to count the number of PWM pulses generated with different frequencies on PWM0, PWM1, PWM2 and PWM4.

Can any one help on the logic to count the exact pulses generated on each pins.

Regards,

M Srinivas

  • Simplest & fastest means to, "Count PWM impulses" results from routing those PWM Outputs (both) to your external device (and) to an MCU Timer pin. MCU Timer is ideally equipped to serve as a counter and may signal you (via an interrupt) when the target number of impulses has arrived...
  • Thanks for the reply,

    We need to count internally through software. Do you have any logic?
  • You could  read the PWM control block pin driver register during each PWM interrupt cycle. Then keep a total of each generators pin changes by checking a test condition exist or not.

    ulPWMEnable = HWREG(PWM0_BASE + PWM_O_ENABLE);

  • Srinivas Mula said:
    We need to count internally through software

    Really?   Does that desire not place added time, effort & performance degrades before you?

    ARM MCUs are RICH w/Timers - managing your count objective via a Timer meets most all user requirements...

  • Hi,

    Thanks for the reply.
    We tried with PWM interrupt logic but we are getting more pulses than actual pulses. Can you post the simple logic using Timer to count the PWM pulses?

    Regards,
    M Srinivas
  • Srinivas Mula said:
    Can you post the simple logic using Timer to count the PWM pulses? 

    Surely - but that's your job - is it not?   (especially so as you note that the logic is "simple.")

    MCU's Timer has multiple modes - shouldn't you read/review - and derive the "simple" Timer set-up & configuration - to achieve your objective?   (recall that we are told - it's "simple.")

  • To what end purpose? It seems a rather odd task to take on.

    Robert
  • Mais certainement, mon ami.  

    Such "odd tasks" (never/ever described or justified) prove (more) the rule than the exception...

    And - the elegance, simplicity & background operation of the Timer is shunned - yet not noted w/in poster's "spec."  

    Yet we "fear not" - poster assures that (this) odd (and now restricted) task is, "simple."

    Should PWM interrupts be employed - simple SW counter w/in each interrupt - (may) prove, "no brainer."    (there is NO need for the "qualifier" - suggested by another)

  • Dear cb1,

    Kindly do not reply. If u have logic to count (exact) 4 PWM pulses, just post it.
  • OK - let the record show:

    • a crisp, clear method of "background counting" your pulses was "off the bat" provided
    • poster (then) changed his spec - stating that (only) SW was allowed
    • others arrived - noted the "strangeness" of poster's requirement
    • suggestion was then made that poster include a SW Counter w/in each/every PWM interrupt - clearly meeting poster's (first & altered) spec
    • despite TWO helpers seeking, "Raison d'etre" - no explanation nor justification of so strange a request was offered

    Poster - apparently missing (item 4, above listing - which solves his requirement) rejects able & proper assistance...