Created
April 7, 2015 12:00
-
-
Save navin-bhaskar/b3323cfd0b47d3cacd7a to your computer and use it in GitHub Desktop.
PWM example on Intel Galileo/Edison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import mraa | |
import time | |
PWM_PIN = 5 | |
pwm = mraa.Pwm(PWM_PIN) | |
""" | |
Control the period with "period_us" | |
+----------------+ +----------------+ | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
+ +----------------+ +----------------+ | |
^ ^ | |
| | | |
|<---------- Period ------------->| | |
| ^ | | |
| | | | |
| | |
pwm.period_us(5000) | |
""" | |
pwm.period_us(5000) # Set the period as 5000 us or 5ms | |
pwm.enable(True) # enable PWM | |
value = 0 | |
delta = 0.05 # Used to manipulate duty cycle of the pulse | |
while 1: | |
if (value >= 1): | |
# Itensity at max, need to reduce the duty cycle, set -ve delta | |
value = 1 | |
delta = -0.05 | |
elif (value <=0): | |
value = 0 | |
# Intensity at lowest, set a +ve delta | |
delta = 0.05 | |
""" | |
Control the duty cycle with "write" | |
+------+ +------+ | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+ +----------------------------+ +---------------------------+ | |
^ ^ | |
| | | |
|<---->| | |
^ | |
| | |
| | |
pwm.write(0.2) | |
""" | |
pwm.write(value) # Set the duty cycle | |
value = value + delta | |
time.sleep(0.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment