This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:embeddedcommunicationprotocols2:pwm [2023/08/21 10:37] – pczekalski | en: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. | + | {{: |
- | To control voltage, instead of using inefficient resistance-based voltage dividers (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. Only two voltages are delivered to the device: low (0V) and HIGH (Vcc). One can observe | + | The PWM signal controls the energy delivered to the device, usually a DC motor, LED light, bulb, etc. |
- | 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. | + | 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 |
+ | 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 important> | ||
+ | |||
+ | PWM signal is then characterised by the following: | ||
+ | * voltage (values when HIGH and LOW), | ||
+ | * frequency, | ||
+ | * duty cycle. | ||
+ | |||
+ | === Generating PWM === | ||
+ | |||
+ | In microcontrollers, | ||
+ | |||
+ | A frequency of 5kHz is equivalent to 0.2ms period that can be controlled in steps of '' | ||
+ | Sample visualisation of the 5kHz PWM signal (3.3V) is presented in the following figures, with a duty cycle of, respectively: | ||
+ | * 50/ | ||
+ | * 100/ | ||
+ | * 150/ | ||
+ | * 200/ | ||
+ | * 250/ | ||
+ | |||
+ | <figure pwm1> | ||
+ | {{ : | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <figure pwm2> | ||
+ | {{ : | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <figure pwm3> | ||
+ | {{ : | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <figure pwm4> | ||
+ | {{ : | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <figure pwm5> | ||
+ | {{ : | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | 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. | ||
- | <note important> |