Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:embeddedcommunicationprotocols2:pwm [2023/08/21 10:53] pczekalskien:iot-open:embeddedcommunicationprotocols2:pwm [2023/11/23 16:10] (current) pczekalski
Line 1: Line 1:
-==== PWM ==== +====== PWM ====== 
-The PWM signal controls the amount of energy delivered to the device, usually a DC motor, LED light, bulb, etc. +{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\ 
 +The PWM signal controls the energy delivered to the device, usually a DC motor, LED light, bulb, etc. 
 To control voltage, instead of using inefficient resistance-based voltage dividers (where the remaining part of the voltage is distracted as heat), PWM is based on approximating the energy delivered to the device with periodical switching on and off (HIGH and LOW). Only two voltages are delivered to the device: low (0V) and HIGH (Vcc, e.g. +5V). One can easily observe how PWM works, e.g. when dimming the LED, if recorded with a high fps camera: the LED light flashes with the PWM signal frequency.\\ To control voltage, instead of using inefficient resistance-based voltage dividers (where the remaining part of the voltage is distracted as heat), PWM is based on approximating the energy delivered to the device with periodical switching on and off (HIGH and LOW). Only two voltages are delivered to the device: low (0V) and HIGH (Vcc, e.g. +5V). One can easily observe how PWM works, e.g. when dimming the LED, if recorded with a high fps camera: the LED light flashes with the PWM signal frequency.\\
-PWM controls, in fact, the ratio between HIGH and LOW signals in one period: the higher the ratio, the more energy is being delivered to the device. It is called a duty cycle. A perfect square wave signal, usually referenced as a clock signal, has a duty cycle of 50% (or 0.5); thus, its energy is half of the energy that can be carried when the signal is HIGH all the time. LED light with a duty cycle of 100% will be fully bright, and with a duty cycle of 0 will be off. +PWM controls, in fact, the ratio between HIGH and LOW signals in one period: the higher the ratio, the more energy is being delivered to the device. It is called a duty cycle. A perfect square wave signal, usually referenced as a clock signal, has a duty cycle of 50% (or 0.5); thus, its energy is half of the energy that can be carried when the signal is HIGH all the time. An LED light with a duty cycle of 100% will be fully bright, and with a duty cycle of 0 will be off. 
  
 <note tip>A 50% duty cycle does not necessarily transfer straightforwardly to 50% of brightness or 50% of maximum rpm of the DC motor rotation, as characteristics of the devices regarding the voltage and energy provided to their input may be non-linear.</note> <note tip>A 50% duty cycle does not necessarily transfer straightforwardly to 50% of brightness or 50% of maximum rpm of the DC motor rotation, as characteristics of the devices regarding the voltage and energy provided to their input may be non-linear.</note>
Line 13: Line 14:
   * duty cycle.   * duty cycle.
  
-In microcontrollers, PWM used to be generated with timers and interrupts to ensure asynchronous operation and stability of the operation.+=== Generating PWM === 
 + 
 +In microcontrollers, PWM used to be generated with timers and interrupts to ensure asynchronous operation and stability of the operation. Due to the digital nature of the signal generation, a duty cycle generation precision is given by the PWM timer resolution. An 8-bit resolution splits a period into 256 chunks, and a single chunk defines the minimum time one can increment or decrement the duty cycle. Modern MCUs provide developers with much higher resolution, even up to 14-bit. 
 + 
 +A frequency of 5kHz is equivalent to 0.2ms period that can be controlled in steps of ''0.2/256 ms ~= 781 ns''.\\ 
 +Sample visualisation of the 5kHz PWM signal (3.3V) is presented in the following figures, with a duty cycle of, respectively: 
 +  * 50/256->~39us (19.5%) in image {{ref>pwm1}}, 
 +  * 100/256->~78us (28%) in image {{ref>pwm2}},  
 +  * 150/256->~117us (58.6%) in image {{ref>pwm3}},  
 +  * 200/256->~156us (78.1%) in image {{ref>pwm4}}, 
 +  * 250/255->~195us (98%) in image {{ref>pwm5}}. 
 + 
 +<figure pwm1> 
 +{{ :en:iot-open:embeddedcommunicationprotocols2:pwm_1.png?400 | Visualisation of the 5kHz PWM signal with a duty cycle of 19.5%}} 
 +<caption>Visualisation of the 5kHz PWM signal with a duty cycle of 19.5%</caption> 
 +</figure> 
 + 
 +<figure pwm2> 
 +{{ :en:iot-open:embeddedcommunicationprotocols2:pwm_2.png?400 | Visualisation of the 5kHz PWM signal with a duty cycle of 28%}} 
 +<caption>Visualisation of the 5kHz PWM signal with a duty cycle of 28%</caption> 
 +</figure> 
 + 
 +<figure pwm3> 
 +{{ :en:iot-open:embeddedcommunicationprotocols2:pwm_3.png?400 | Visualisation of the 5kHz PWM signal with a duty cycle of 58.6%}} 
 +<caption>Visualisation of the 5kHz PWM signal with a duty cycle of 58.6%</caption> 
 +</figure> 
 + 
 +<figure pwm4> 
 +{{ :en:iot-open:embeddedcommunicationprotocols2:pwm_4.png?400 | Visualisation of the 5kHz PWM signal with a duty cycle of 78.1%}} 
 +<caption>Visualisation of the 5kHz PWM signal with a duty cycle of 78.1%</caption> 
 +</figure> 
 + 
 +<figure pwm5> 
 +{{ :en:iot-open:embeddedcommunicationprotocols2:pwm_5.png?400 | Visualisation of the 5kHz PWM signal with a duty cycle of 98%}} 
 +<caption>Visualisation of the 5kHz PWM signal with a duty cycle of 98%</caption> 
 +</figure> 
 + 
 +<note important>Because of the limited hardware resources, an increase in PWM generation resolution or PWM signal frequency may cause an inability to generate a signal or instability of the PWM generation process. Always refer to the MCU's hardware specification for details on the PWM signal limits.</note> 
 + 
 +A voltage delivered to the device powered with a PWM signal can be calculated as an integral of the PWM signal over time: e.g., a 50% duty cycle of the 5V signal is equivalent to the delivery of the constant 2.5V. 
en/iot-open/embeddedcommunicationprotocols2/pwm.1692615225.txt.gz · Last modified: 2023/08/21 07:53 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0