Gamepad design based on SLH89F5162 microcontroller

I. Overview of the project background

Today, smartphones are everywhere, and a wide variety of apps are emerging. Since the mobile phone has gravity sensing function, mobile games naturally will not miss this. Compared to the small games of the 1980s and 1990s, today's games are no longer just to see with your eyes, with your fingers, and more to let players use their bodies. Go and experience the game. Games such as racing, airplanes, and yachts can control the game object by controlling the posture of the mobile phone. This experience has fascinated many people.

However, while the gaming experience has been greatly improved, there are also some problems. The gravity sensor is integrated with the mobile phone, and the mobile phone screen is also part of the mobile phone. When the enemy aircraft quickly rushes toward us, we will tilt the mobile phone to avoid the enemy aircraft. But at this time, because the phone is tilted, we either can't see the screen content, or the head tilts with the phone.

To solve this problem, I want to separate the sensor from the screen, even if the control is independent of the display. As the "Shenzhen Lianhua Cup MCU Application Design Competition" is in full swing, I will take this opportunity to implement my plan. Create a gamepad with gravity sensing.

Although the gamepad with gravity sensing is also available in the market, the price of hundreds of dollars is not for everyone to buy. Deep Lianhua SLH89F5162 MCU is an enhanced 51 MCU, compatible with the traditional 51 MCU, and added a number of practical peripheral modules, making the MCU truly become a "single-chip microcomputer." At the same time, because of its low price, the cost of the produced gravity game Controller is also very low, belonging to civilian-level consumer electronics, and the market competitiveness is self-evident.

Second, the project design principle

1, an overview of the principle

The SLH89F5162 MCU obtains the real-time 2-axis acceleration value of the game controller from the sensor MPU6050. After the operation, the tilt angle of the game controller can be obtained. The angle information is sent to the receiving program on the computer through the serial port, and the receiving program can be packaged through simple data. Pass the gesture of the gamepad to the game object to achieve the same game effect as the smartphone gravity sensor game.

2, the hardware design principle

The SLH89F5162 microcontroller has an internal 16.6MHz oscillator, so it can work normally without an external crystal. It uses 115200 baud rate, fast communication speed, very small error, negligible, tested tens of thousands of data, and found no error data. At the same time, the smaller the baud rate generated, the greater the error. There is a reset circuit inside the microcontroller, which can save the external reset circuit, so a single chip is a minimum system.

The controller SLH89F5162 is the main controller, which is responsible for sensor control, sensor information reading, matrix keyboard scanning, independent key input, and serial communication with the computer.

The sensor MPU6050 integrates a 3-axis gyroscope, a 3-axis accelerometer, a temperature sensor and a digital motion processor, and supports other auxiliary sensors. I2C communication interface, digital output, small size.

The division ratio of 115200 baud rate = 16.6M / 16 / 115200 = 9.00608

The division ratio of 38400 baud rate = 16.6M / 16 / 38400 = 27.0182

The division ratio of 19200 baud rate = 16.6M / 16 / 19200 = 54.0365

The division ratio of 9600 baud rate = 16.6M / 16 / 9600 = 108.073

3, software design principles

The software development environment uses Keil3, and the programming language uses assembly. Using the modular method, the I2C read/write function, the MPU6050 operation function, the keyboard scan function, the mathematical operation, and the table are separated into different files, and then linked together at compile time.

The MPU6050 only supports I2C communication. The maximum I2C clock is 400KHz. It is written in assembly language and can meet the clock requirements to the maximum extent. This is not possible with high-level languages. The gravity sensor outputs the acceleration of a certain axis. The ratio of this value to the gravitational acceleration g is the sine of the angle between the axis and the vertical direction of the sensor. Only the inverse sine is required to obtain the corresponding angle.

angleX = arcsin(accelX / g)

angleY ​​= arcsin(accelY / g)

The collected data is noisy, and the digital low-pass filter can effectively reduce noise interference. There is not only a component of gravity acceleration on a certain axis, but also a component of motion acceleration, which brings errors in the calculation of the inclination angle. The component of motion acceleration is much smaller than the gravitational acceleration, and the duration is also very short. The low-pass filtering algorithm can also bring errors caused by small motion.

Low-pass filtering algorithm: y = a * y + (1 - a) * x; x: input, y: output, a: coefficient

Due to the insufficiency of the 8-bit 51 MCU, the support for floating-point data operations is very poor, especially involving trigonometric functions and inverse trigonometric functions. So I used the space-for-time method, which is to get the value of arcsin(accel) by looking up the table, so the operation is very fast, and the precision is not discounted. The SLH89F5162 has an on-chip 62K Flash ROM, and accel = -8192 ~ 8192. It requires 8192 * 4 = 32K bytes to store 8192 floating-point data. There is no pressure on the SLH89F5162 microcontroller.

We are a leading company name in between the most trusted companies in this business, engaged in providing Polycrystalline Solar Panel. Our Polycrystalline Solar Panel is manufactured by using quality tested components at our vendors end. Our product range is known for its high quality, less maintenance and optimum functionality.

Polycrystalline Solar Panel

Polycrystalline Solar Panel,Polycrystalline Silicon Solar Panel,Polycrystalline Pv Solar Panel,Polycrystalline Flexiable Solar Panel

Delight Eco Energy Supplies Co., Ltd. , https://www.cndelight.com