Intel物联网入门教程——Part3: PWM的原理与实现

  Introduction

  PWM stands for pulse width modulation. As the name suggests, there is a “pulse” and with “width”, we mess(“modulation”). The idea here is to change the width of the pulse, resulting in another pulse that meets our needs.

  Why do we need it?

  With digital systems like Arduino, Galileo/Edison, most often, we are dealing with two discrete voltage levels, 0 (GND, logical low) or 1 (logical high, represented by 5 V, 3.3V or 1.8V). PWM is alt="" width="320" height="88" />

 

  So going by the definition of period, the following shows how period is measured (the time interval after which pattern repeats)

  

 

  The other thing that can be controlled is the duty cycle. Duty cycle defines the amount of time the signal stays “on”. It is measured in terms of percentage. In the above images, the duty cycle is said to be 50% because the signal stays alt="" width="300" height="260" />

 

  

物联网

 

  The script:

  The intensity with which LED glows depends>= mraa.Pwm(PWM_PIN)

  Then set the period using

  pwm.period_us(5000)

  Once that is done, start outputting the pulse train at the selected pin :

  pwm.enable(True)

  and finally, the duty cycle is controlled using the write() api:

  pwm.write(value)

  On github, you can find the code here: https://github.com/navin-bhaskar/Python-on-Galileo...