Develop STM32F4 using Matlab2017b Simulink model-based automatic code generation (3) ---- (PWM and input capture)

         In the application of STM32 , the PWM mode and input capture mode of the timer are two very commonly used modes. In this tutorial, I will show you how to use simulink to configure the PWM mode and input capture mode. If you have a little understanding of simulink If it is a little deeper, it is very convenient to directly use simulink and PWM to program three - phase alternating current and PID to accurately control the DC motor . The programming efficiency is very high. After writing the basic application tutorial, I will write some tutorials on running simple neural networks, deep learning, signal processing (adaptive filtering, Fourier transform, etc.) on STM32 , which can be applied to the simulink platform. Everyone is still in a simple application of STM32 , and they will use advanced algorithms, so it will not be a waste of time to learn this chip.

Without further ado, let’s start with today’s learning task. Today, we will solve two problems: how to configure PWM and input capture mode, and build a corresponding serial host computer for data visualization.

Let me show you what the whole project is like first. The two flashing lights show that the program is running normally. The IO ports A6, A7, B0, and B1 under timer3 generate PWM waves with a duty ratio of 20, 40, 60, and 80 percent. , B6 under timer4 performs input capture, and sends the captured data through serial port 3.


First look at the configuration of the Basic PWM control, set the period you need, the corresponding Timer, the corresponding IO port, input the corresponding duty cycle, and then the operation of generating the PWM wave can be completed.


Let's take a look at the settings of the input capture control. Set the corresponding timer, the corresponding IO port, and then capture high level or low level, the output has pulse width (unit second), duty cycle, frequency period


The output data type can be selected. Finally, it is necessary to convert the data type according to whether the data type of the data sent by your serial port is consistent.


The corresponding data visualization of the host computer is shown in the figure above. Connect the port corresponding to the signal to be collected with a line, and click Run to see the corresponding data.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325763702&siteId=291194637