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.

PWM - Clock and Period Relationship Question

Hi All:

I am new to PWM and I'm not understanding how the Clock is related to setting the period.  (I'm running a TM4C129.)

If my clock is running at 40Mhz and I wanted to set the Pulse With at 75% (or 30,000,000) clock ticks, I would do the following:

ulClock = 40000000;

PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulClock);

PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, ulClock * 0.75);

I'm not sure why I just can set the clock to let's say 100 and do the same thing.

There is something about the Clock parameter that is important here and I'm just not seeing it.

Any thoughts?

Also, when I am controlling motors using PWM, is the PWM hardware taking cycles 'away' from 'normal processing'.

Thus, if I was running 95% PWM on a pin, then the rest of the code is only getting 5% of rest of the processor.  Sounds weird; but, had to ask.

Just not seeing this.  A high level explanation would be great.

By the way, I have been hacking away at this system for a long long time.  Learned a lot.  If not for this forum, I would have given up.  I am finally getting close to the end of coding.   Thanks for all of your help.

Rick

  • First, that clock parameter sets the period of the PWM. When the value is the same as the peripheral clock frequency the period is one second. When set to clock/4 the period becomes1/4 second or equivalently the frequency becomes 4 hz. So reducing the argument to 100 makes th PWM frequency clock/100.

    Second the PWM is implemented as a simple digital counter and comparator (well a little more than that) so it uses no CPU resources. Interestingly enough it's also one of the few peripherals you cannot buy a discrete implementation of, at least not that I've been able to find.

    Robert

    Or any rep I've asked to look either.
  • Adding to the good input from friend Robert - it is usual that the frequency of the PWM must be "adapted" to best suit the individual, "Use case."   In your motor control work - usually but not always - you'll want a PWM frequency at or just beyond 20KHz.   (that's the top frequency most adult humans can detect - alas not moi)

    Displays - especially backlights - usually are PWM modulated to adjust brightness - and the ability to alter the PWM frequency may prove crucial/critical here.   "Beating" between display "scan" and the back-light PWM can produce unwanted display patterns - similar to misadjusted/absent "horizontal hold" on past (analog) TVs.

    Lesson here is that your determination of the optimal PWM frequency is normally your first order of business.

    Duty Cycle has not yet arrived - this thread.  That's the ratio: time(PWM_High)/time(PWM_Period).   It is this ratio which determines the power delivered to the load.

    As to getting, "Close to the end of coding," you may find that goal elusive.   As your experience & skills build - initial goals may "transform" (unlike political ones) they may become more appropriate, more tightly focused, and may "push back" those "once close" goal-posts...

  • Robert and cb1-:

    As usual, I am not disappointed!! Thank you for the thoughtful answers.

    Regarding "Close to the end of coding"... Oh, gosh... I really do not have the emotional energy to even think about that.

    Needless to say, thanks guys. Your help was very much appreciated.

    Rick
  • Rick Faszold said:
    Re:  'Close to the end of coding" I really do not have the emotional energy to even think about that.  

    Nor do we my friend - nor do we...

    Our small tech firm mandates multiple notebooks, "At the Ready"...

    • Current Client Project Spec
    • Client Change Requests
    • Project Future Improvements

    The addition (and discipline) of that "Future Improvement" book has well reduced our number of, "Mental Health" Days...   (alas although sold/promised - we/others - as feared - could not "keep" our doctors...)