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.