pwm_control.py
# Ce travail est publié sous licence MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Tous droits réservés.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Exemple de contrôle PWM
#
# Cet exemple montre comment faire du PWM avec votre OpenMV Cam.
#
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!! REMARQUE !!!
# C'EST LA SEULE BROCHE LIBRE LORS DE L'UTILISATION DU VISION SHIELD.
# N'UTILISEZ AUCUNE AUTRE BROCHE LORS DE L'UTILISATION DU VISION SHIELD.
# PWM7/PH15
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
import time
from pyb import Pin, Timer
class PWM:
def __init__(self, pin, tim, ch):
self.pin = pin
self.tim = tim
self.ch = ch
pwms = {
# 'PWM1' : PWM('PA8', 1, 1), # TIM1 est réservé.
"PWM2": PWM("PC6", 3, 1),
"PWM3": PWM("PC7", 3, 2),
# 'PWM4' : PWM('PG7', 0, 0), # HRTIM non pris en charge.
"PWM5": PWM("PJ11", 8, 2),
"PWM6": PWM("PK1", 8, 3),
"PWM7": PWM("PH15", 8, 3),
}
# Générer une onde carrée de 1 kHz avec un rapport cyclique de 50 % sur le PWM suivant.
for k, pwm in pwms.items():
tim = Timer(pwm.tim, freq=1000) # Fréquence en Hz
ch = tim.channel(pwm.ch, Timer.PWM, pin=Pin(pwm.pin), pulse_width_percent=50)
while True:
time.sleep_ms(1000)