Use PYBOARD development board, chip for STM32F405VET, software using micropython is very simple, micropython like python, interpreted language,
By simulating a serial port on a program to the development board, upload software using uPyCraft v1.1 other software can also be, a serial port debug groups can hand, development board can use ordinary serial port, here I use USB emulated serial,
The import math
The import pyb
The from pyb import Timer, Pin
The import STM
The class pwm_sin:
Def __init__ (self) :
Self. Buf=bytearray containing (100)
For I in range (len (self. Buf)) :
Self. Buf [I]=128 + int (127 * math.h sin (2 * math.h PI * I/len (self. Buf)))
Pa0=Pin (' pa0, Pin OUT_PP)
Self. T6=Timer (6, prescaler=83, period=19999)
T2=Timer (2, prescaler=83, period=254)
Self. Ch1=t2. The channel (1, the Timer. The PWM, pin=pa0)
T2. Callback (self. Timer_callback)
Def __del__ (self) :
Pass
@ micropython. Native
Def timer_callback (self timer) :
T=self. T6. Counter ()//200
The self. The ch1. Pulse_width (self. Buf [t])
P=pwm_sin ()
Before filtering waveform
CodePudding user response:
Self. Buf=bytearray containing (100)For I in range (len (self. Buf)) :
Self. Buf [I]=128 + int (127 * math.h sin (2 * math.h PI * I/len (self. Buf)))
These three lines is in the self. The buf, 100 points constitute a cycle of sine wave, values range from 128 to 255
Other Suggestions reference
https://docs.singtown.com/micropython/zh/latest/openmvcam/library/pyb.Timer.html
https://docs.singtown.com/micropython/zh/latest/openmvcam/library/pyb.Pin.html
Write very detailed document