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.

Change the compare value of PWM generators in every cycle

Hello together,

my Problem is the following: I want to change the compare value of three pwm generators of one module before every count cycle of the pwm. If I do this in the pwm count to zero Interrupt, it takes a short time to change the output signal. During this time the old values are on the outputs. Does anybody know how I can change the compare values otherwise?

Thank you very much in advance for your answer

  • Thomas,

    It is not clear to me what you want to achieve.

    Assume that you set up a count down operation, You can setup the PWM pin to go low when counter reaches zero and to go high when counter reaches the comapare value. In this way, the load register controls the period and the compare register controls the duty cycle (high time). In you application, you can update those registers as your wish. The updated value will be loaded into timer when the counter reaches zero. Due to the asynchronous operation between CPU and timer, I would suggest to update load register before the compare register to avoid glitch.

    Thanks and regards,

    Zhaohong

     

  • Hello Thomas,

    It should be possible to do so. I am making some assumptions so that you can confirm

    Assumption-1: The 3 PWM generators have the same LOAD Value

    Assumption-2: The 3 PWM generators require only the compare value to be changed

    What you would need to do is

    1. Make sure all comparators and generators are kept in locally synchronized mode which will allow values to loaded on zero count.

    2. After enabling the 3 generators use the PWMSYNC register to synchronize the 3 generators

    3. On every zero interrupt load the new values, which will be loaded next time the counter becomes 0

    Regards

    Amit

  • Hello,

    Thanks for the answers. It's difficult to explain. I do an other try:

    What I want is something like this

    What I get is this:

    The red break- in's are not desired. The problem is the the Generators are synchronized.

    Does anybody know more about this?

    Thanks and regards

    Thomas

  • Hello Amit,

    I can answer both of the two assumptions with yes.

    And I have done it after your description.

    I drew some diagram for a better decription.

    Thanks

  • Hello Thomas,

    Can you please share your CCS project with us, so that we can investigate what is happening?

    Also it is not clear if this is on TM4C123 or a TM4C129 device? Please let us know the same as well.

    Regards

    Amit

  • Thomas Barth said:
    want to change the compare value of three pwm generators of one module before every count cycle of the pwm.

    I believe this high a frequency of PWM update to be extremely unusual - especially so if the PWM frequency is at/beyond 8KHz.   Now our group has long employed MCUs from here (and elsewhere) to control BLDC motors - and we perform classic, "Cycle by cycle" current-limiting.   Yet - we never seek to change the PWM duty cycle at our (20KHz) PWM rate!

    Simply put - is so high a change rate in PWM duty cycle really necessary? 

    In terms of motors, power actuators - we find that duty cycle response is more than adequate via 1mS update rates.  The natural mechanical inertia of such systems over-rides/dominates most any faster update rate.  And - @ 20KHz there is just 50uS available to perform the needed calculations and any/all other required MCU/signal, "housekeeping."

    Note that this vendor has long produced a BLDC-RDK motor kit - and the 1mS PWM update rate was enforced therein.  Believe that value is reasonably "standard" w/in motor/actuator control...

    For the most robust operation - should you really need to vastly increase duty cycle update - I'd confine such updates to no more than every 5 or 10 PWM cycles. (note that our/others "standard" 1mS rate is 20 such, 20KHz PWM Cycles...)

  • Thomas Barth said:

    What I get is this:

     Hi Thomas, can you capture on scope and post it ? Also capture together a toggle pin on a port to see where update are located. ( your X point and I suppose interrupt begin/end)

  • Note: Both you and one Felix (alter-ego) uniquely employ, "Hello Together!"

    Is that just "cut/paste" run amuck?  Hello All makes sense - is very inclusive.  But phrase - now in your repeated rotation - is far more inventive/confusing than "normal/customary."

  • cb1- said:
    Note: Both you and one Felix (alter-ego) uniquely employ, "Hello Together!"

    ---- **** Off TOPIC Mode On ****----

    Hi CB1, may be these guy (like me too) are not mother tongue?

     In let me try google translation...

     French seems work...

    Bonjour à tous vous, -> Hello to you all,

     Bonjour à tout le monde -> Hello to Everyone

    Bonjour ensemble -> Hello All

    On parle française -> We speak French

     

    Italian too

    Buongiorno a tutti voi, -> Good morning to all of you

    German... react better also moving <<an>> to correct form....

    Guten Morgen  alle an, -> Good morning all on,

     Google learned a lot ;) People less...

    --------------- 

    Mon ami, rien ne va plus... (this can fault google translator too :D )

     

  • Dear cb1 and Roberto Romano,

    congratulations, you are right, my mother tongue is not english. If this disturbs you, please do not answer my questions and please do not write about 500 lines about how good ist Google translator. It does not care. Have you got all of your community Points like this?

    But thank you for your tip. Simply send a message next time.

    For the Otherones who answered my question: Thank you for the qualified answers. If I'm in lab, I post the photo of the oszy and my code. The model of my board is included in the tags.

    Regards

     

  • @Roberto,

    My group much enjoyed your post - thank you!

    Ain't rushing back anytime soon to poster - in my case I provided tech detail - to silence.  (other walls await my hard head...)

  • Thomas Barth said:

    congratulations, you are right, my mother tongue is not english. If this disturbs you, please do not answer my questions and please do not write about 500 lines about how good ist Google translator. It does not care. Have you got all of your community Points like this?

    ****** Off Topic *******

     Thomas forgot that and read between lines, I am not mother tongue too and was directed to CB1, I am sure my language is not so clean too and mother taste still remain interspersed, CB1 text sometime is too complex and require me and I suppose a lot of native learn about non common use of, google is not able to generally translate to a readable form from to English nor backward, some progress from little language went to light but don't expect use it more than as a simple dictionary... Anyway I am sure Goggle Translate is not able to translate this as you are doing I think yourself.

     ****** OFF Topic End ******

     So I am able to somewhere read error injected from other languages, you are not one without knowledge so taste error to expression is not so important, please let me concentrate on what is your trouble:

    from tag [] I infer this:

     You are working on a Connected launchpad on processor TM4C1294NCPT

     Before to got lab I suppose you know the issue you got, red lines are some form of negative pulse or glitch?

     Prepare to also help Amit a test doing this and reproduce issue:

     Toggle a port bit entering/exiting interrupt servicing port

     Toggle another port bit before/after set PWM

     Capture on scope PWM output and these two port output too.

     As Amit requested compress your code and decide if can be posted on public area or privately send to.

    --------------------------

     Initial writing is interpreted this way:

     You are using 3 compare channel on same counter.

     You loaded Counter load setting the PWM period (and this is same for all 3 channel of same counter)

     You set an interrupt on zero counter and service do this:

       Change load of all 3 channel.

     ----------

     From your sketch:

      x to x is the pwm period from load register and is same on both

      period before load is near 16.66% 1 about of 6 pulse width fit the period so pwm ->1/6

     After load you wish have one full period set to 1 (so 100% duty cycle) then I suppose reload old 16% value to extend on next period.

    Period of     PWM      1   2   3   4   5   ...   n   n+1 n+2 n+3

     PWM % sequence : 16 16 16  16 16  ... 100 16     x    y ...

     When you set new pwm you got a glitch on first red or output goes down?

    -----------

     You get a strange thing I didn't fully grasped, try one of this if more close to:

     1 You expect pwm change extending next cycle to all the period (100%) and some glitch are on output

     2 You expect extending and new value don't load?

    try some simple sequence explaining and don't worry language I provide CB1 punishment and continue in my information drill-out ;)

  • Hello Roberto,

    I found the mistake, but I do not know, how to correct it.

    From one pulse to the next is one pwm Periode. My aim is it to invert the pwm output in each periode and if i do this I get pulses before every inversion. I think this is because it took to long to invert the output.

    I invert the output in my count to zero interrupt. I tried to do the inversion earlier, but the controller does not wait until the counter counts to zero (lokal synchronization).

    Thanks for help.

    Thomas

  • Thomas Barth said:
    I invert the output in my count to zero interrupt. I tried to do the inversion earlier, but the controller does not wait until the counter counts to zero (lokal synchronization).

     Uhm, If i got the correct sense you need a PWM one pulse low and one pulse high?

     So why not use PWM, 100-PWM, PWM , 100-PWM?

     Is this the sense your request is?

    Thomas Barth said:
    From one pulse to the next is one pwm Periode. My aim is it to invert the pwm output in each periode and if i do this I get pulses before every inversion. I think this is because it took to long to invert the output.

     So the glitch (short pulses like needle) are on pwm or where you are touching the code.. please do sample other channnel as I proposed, this can help all us to pinpoint trouble.

    Thomas Barth said:
    I invert the output in my count to zero interrupt. I tried to do the inversion earlier, but the controller does not wait until the counter counts to zero (lokal synchronization).

     If I get correct sense on this phrase then try use the software than hardware solution and tell me what i hit and what is not close to your project.

     Every case please add code to have two port tell us where code writing / interrupt service are.

     

    Post edit:

     Like you forgot tell us I forgot ask you:

     Please can you explain what you find  wrong?

    Thomas Barth said:
    I found the mistake, but I do not know, how to correct it.

     Post edit 2:

     I find one part has no sense so I barred it. Setting PWM and 100-PWM alternately generate a square wave as the one is on scope screen. More detail are necessary.

  • Hello Thomas,

    It would be good if you can post the code. The local synchronization works fine on TM4C123.

    If the intent is to invert the output then that cannot be synchronized to zero count, but based on the code we can surely find a way around it.

    Regards

    Amit

  • Thomas Barth said:
    I invert the output in my count to zero interrupt. I tried to do the inversion earlier, but the controller does not wait until the counter counts to zero (lokal synchronization).

     Hi, from your scope image I suppose it is an analog one, positive spike appear less thick as negative one, is your code acting different on positive or negative update? If scope is digital changing sampling rate image change due to aliasing or spikes are of different width?

     Thomas, please don't miss answer question:

    Thomas Barth said:
    lokal synchronization

     This resemble are you German? If so try post description in your language, I am not so fluent but I try read at my best, maybe better private I try translate for you.

     What your application is devoted to? So what are you trying to drive/generate?

     Pack code and send to Amit is feasible?

     I exhausted my fantasy on digging your posts.