[video game preparation] adjustable PWM output based on STM32 control + LCD display

situation analysis

A junior old fried dough stick. When I was a freshman, I applied to stay in school in time for the 19-year national competition. After the self-study (rowing) started in January, I visited with my teammates about the preparation of other teams and went home happily. (I didn't buy any materials). Due to the epidemic, the provincial competition of sophomore year was postponed to junior year. Take advantage of the pressure of postgraduate entrance examination is not very big, rush.

The level is average. It took a lot of time to learn 51 before. Using 51, I made a obstacle avoidance and Bluetooth remote control smart car from 0. Learning 51 is an end. It has to be said that the experience of learning 51 is very helpful for getting started stm32. It took about ten days to read the contents of IO, serial port, timer, interrupt and PWM output. Just as there is a car in this year's bill of materials, it is planned to add an LCD screen to combine it.

Pit sharing

There are also some problems in the process of learning 32 routines. Most of them are very low-level. Simply mention it and remind yourself.
1. The clock initialization statement clockcmd of the IO port is configured incorrectly (several similar ones are used incorrectly)
2. With regard to the mode configuration of IO port, generally, the output port is the default push-pull output, such as the first running lantern experiment. However, if you can't map the PWM output to a port with the smallest system board (C8T6), you need to connect the IO port and PWM output port with an external DuPont line. At this time, the IO port should be set to floating to have input. Refer to the pin diagram and Chinese Manual of the corresponding chip in the manual for details

3. Note that the IO port is used as a peripheral and multiplexing needs to be turned on
4. The problem of external interruption is quite different between 51 and stm32. My PWM adjustment is realized by pressing the key into the interrupt. Remember to modify the interrupt source and interrupt service line when adjusting the key.

No longer list them one by one. Those who have made similar mistakes should understand.

design sketch

The problem of light flashing was later found that the frequency division coefficient of the timer was too large and the frequency was low. The effect of changing it was very good. (picture before change)


#include "delay.h"
#include  "sys.h"
#include "led.h"
#include "key.h"
#include "pwm.h"
#include "exit_x.h"
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"
u16 speed = 500;
 int main(void)

// 	u16 led0pwmval=0;
//	u8 dir=1;	
	LCD_Init();//LCD initialization
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 	 //Interrupt priority, NVIC response priority 2:2
 	PWM4_Init(999,7199);	 //No frequency division. PWM frequency = 72000000 / 900 = 80kHz 72000000 / 7200 = 10kHz 1000 / 10K = 0.1s
//		if(dir)led0pwmval++;
//		else led0pwmval--;

// 		if(led0pwmval>speed)dir=0;
//		if(led0pwmval==0)dir=1;										 
		LCD_ShowChinese(0,0,"Speed regulation monitoring display",WHITE,BLACK,16,0);

Tip: it seems that Bloc can't insert attachments. All the codes are uploaded in the download area. If necessary, you can get it yourself or leave comments in the email.

Welcome criticism and correction and make common progress!

Tags: Embedded system Single-Chip Microcomputer stm32

Posted by beeman000 on Sun, 15 May 2022 10:41:59 +0300