I'm currently attempting to drive a servo motor using a STM32 NUCLEO F767ZI. According to the Micropython docs, there should be a PWM class within the machine module. I've even seen mention of a Servo class under the pyb module. By running dir(machine) and dir(pyb), I don't seem to have either on my build of Micropython.
I've looked through the docs and found where some ports should have the PWM class, whereas other ports use the Timer class to accomplish PWM.
Is the PWM class the universal solution for PWM use, or would Timer be used to generate PWM for STM32?
I'm running Version: 0221 Build: Jun 23 2017 17:43:45.
STM32 NUCLEO F767ZI PWM
Re: STM32 NUCLEO F767ZI PWM
This is what has worked for me in the past on STM32 L4s and F0s:
Note that, the information about which pins are connected to each combination of Timer+Channel is available on the MCU data sheet (see the alternate function table), and the Alternate function CSV on github (ports / stm32 / boards / [your MCU])
Example:
Code: Select all
import pyb
timer2 = pyb.Timer(2, freq=1000)
ch1 = timer2.channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.PA0, pulse_width_percent=50)
Example:
Code: Select all
# PA0 TIM2_CH1
# PA1 TIM2_CH2
# PA2 TIM2_CH3
# PA3 TIM2_CH4
Re: STM32 NUCLEO F767ZI PWM
Thank you very much, Asensio12! With your help, I was able to get PWM working! I've noticed that any pin that is tied to a particular timer/channel pair initialize when that command is executed.
For example:
This will generate PWM output from pin D13/PA_5 at a 50% duty cycle, but I observed the same output from pins PA_15 and PA_0 as well. I was able to run 'pyb.Pin.board.[PIN NAME].init(0)' to disable output from any number of the pins.
This raises the question: Is there a way to ensure that only the desired pin ouputs PWM?
For example:
Code: Select all
timer2 = pyb.Timer(2, freq=1000)
ch1 = timer2.channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.D13, pulse_width_percent=50)
This raises the question: Is there a way to ensure that only the desired pin ouputs PWM?