Micro Python transplantation PWM on MindMotion MM32 single chip microcomputer

Introduction: The software transplanted with micro python with PWM function sent by MindMotion on November 22 was tested. Firstly, the output waveform can be tested on the two PWM channels (PA6 and PA7), but there are still differences between the signal parameters and settings: the spectrum of the output PWM signal is smaller than the set frequency, and the output waveform is just opposite to the set duty cycle.

Keywords: PWM, MindMotion, micropathon

 

§01 MM32 MicroPython

1, Background introduction

    over the past weekend, MindMotion SuYong revised the version with PWM in the transplanted micropathon and sent the latest version:

  Micro Python / mindmotion / firmware-2021-11-22.bin · Zhuo Qing / programming technology - Gitee.com

  for this version Test mindmotion mm32f3277 micropathon - 2021-11-20 new PWM version Fix the existing problems. However, the main framework of the procedure has not changed. That is, the function of eight PWM channels is still completed with the help of two timers.

2, PWM function

   according to the test the day before yesterday, we can know that the main pins and internal timer resources of PWM are as follows:

[Table 1-1 PWM resource allocation]

PWMtimerGPIO
PWM0TIM3PA6
PWM1TIM3PA7
PWM2TIM3PB0
PWM3TIM3PB1
PWM4TIM4PB6
PWM5TIM4PB7
PWM6TIM4PB8
PWM7TIM4PB9

3, Download micro Python

1. Download micro Python

  download the downloaded micro Python to Design mm32f3277 micro Python experimental board with SD card Then use STM32BOOTLOADER for REPL test.

▲ figure 1.3.1 download the new version of micro Python to the beta version

2. Power on test

   after power on, the following is displayed on the REPL interface:

>> Open COM8, baud : 115200

[Y] sdcard ready.
[Y] file system on sdcard ready.
[Y] run the main.py on disk ...
[Y] done. 1
MicroPython v1.16 on 2021-11-22; MB_F3270 with MM32F3277G7P
>>> 

 

§ 02 test PWM

1, Basic test

1. Test basic waveform

  initialize PWM channels 0 and 1, occupy PA6 and PA7 respectively, and output the corresponding PWM waveform.

(1) Test code

from machine                import Pin,PWM
import utime

pwm0 = PWM(0, freq=10000, duty=200)
pwm1 = PWM(1, freq=10000, duty=500)

print("Test PWM.")

(2) Output waveform

   measure the output waveform, as shown in the figure below:

▲ figure 2.1.1 PWM output waveform

  it can be seen that there is an error between this waveform and the set parameters:

  • Frequency error: the actual PWM output frequency is 9.589, and the frequency of the signal measured by the frequency range of FLUKE45 digital multimeter is 9.5914kHz.
  • Duty cycle error: set duty=200. The actual output is 800. The output waveform is reversed.

   the following is the waveform corresponding to the duty of PWM0 set to 1999 respectively.

▲ figure 2.1.2 waveform corresponding to setting duty=1 for pwm0

▲ figure 2.1.3 PWM0 sets the waveform corresponding to duty=999

2. Dynamically change duty

(1) Test code

from machine                import Pin,PWM
import utime

pwm0 = PWM(0, freq=10000, duty=500)
pwm1 = PWM(1, freq=10000, duty=1)

print("Test PWM.")

duty = 1
dutyinc = 20
dir = 0

while True:

    if dir == 0:
        duty += dutyinc
        if duty >= 1000:
            duty = 999
            dir = 1
    else:
        if duty < dutyinc:
            duty = 1
            dir = 0
        else:
            duty -= dutyinc

    pwm1.duty(duty)

    utime.sleep_ms(100)

▲ figure 2.1.4 dynamic change of duty cycle of PWM1

 

※ test summary ※

   tested the software transplanted with micro python with PWM function sent by MindMotion on November 22. Firstly, the output waveform can be tested on two PWM channels (PA6 and PA7), but there are still differences between signal parameters and settings:

  • The output frequency is smaller than the set frequency;
  • The duty cycle of the output is just opposite to the setting.

▲ Figure 3.1 set the output waveform corresponding to PWM grade 100kHz

■ links to relevant literature:

● relevant chart links:

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TESTPWM.PY                   -- by Dr. ZhuoQing 2021-11-22
#
# Note:
#============================================================

from machine                import Pin,PWM
import utime

pwm0 = PWM(0, freq=100000, duty=500)
pwm1 = PWM(1, freq=10000, duty=1)

print("Test PWM.")

duty = 1
dutyinc = 20
dir = 0

while True:

    if dir == 0:
        duty += dutyinc
        if duty >= 1000:
            duty = 999
            dir = 1
    else:
        if duty < dutyinc:
            duty = 1
            dir = 0
        else:
            duty -= dutyinc


    pwm1.duty(duty)

    utime.sleep_ms(100)




#------------------------------------------------------------
#        END OF FILE : TESTPWM.PY
#============================================================

Keywords: micropython pwm

Added by jackwh on Mon, 22 Nov 2021 14:47:08 +0200