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

PWM tips.

Assume a constant frequency PWM.
Assume that a period begins on the low to high transition. Suppose an application needs to change the duty cycle.
Question 1. Should (must) changes to the duty cycle be done on the same edge (i.e. low to high)? Can the change be done on _any_ part of the cycle?

Question 2. Are there scenarios where the duty cycle should be changed gradually? For example, consecutive cycles could see only one bit change until the new duty cycle is reached.

  • As for the first question, it's written in the microcontroller manual. I'm using ST10F168, and the manual says that the pulse width register is updated at the beginning of every new PWM cycle.
    If you want to implement gradual change of the duty cycle, you could use PWM interrupt and PEC to update the pulse width register. I can't see a faster way of updating the duty cycle.
    I'm assuming that the questions were about the C166/ST10 microcontroller PWM module.

    Regards,
    Mike.

  • In our PWM applications we usually change the duty cycle gradually to prevent jerky movement but it is usually done at a higher level.

    For example, we might use a voltage controlled electrical proportional hydaulic valve where flow is controled by varying the duty cycle of the applied voltage. Here we would implement a slew rate limit on flow demand. Since duty cycle would be a function the flow demand, this results in a slew rate limit on the duty cycle. (We usually allow a means for the customer to vary the slope of the limit).

    We output the new duty cycle command at the periodic rate of software task performing this function and don't worry about waiting for the start of the PWM period.

    This degree of control has always been adequate for our applications but perhaps yours requires a finer level of control.

    -Walt

  • You have to look at your system a little to determine some of these parameters. As an example, if the object you are controlling has a limit of 1 khz, then sending changes faster than this will not effectively do anything to the system. The inertia of the object acts as a low pass filter, only allowing changes below a certain frequency to take effect.

    Some systems have filters designed into them to smooth out changes to the hardware. These can be simple RC filters, or more complex designs with op-amp(s) and multiple poles to assist with the operation. Often it is simpler (and more effective) to add a filter in hardware than in software.

    There have been some excellent articles in Embbeded Systems magazine on this subject. You can get a CD from them with all issues and the pertaining articles. http://www.embedded.com is the website.