yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
L-Type Motor📖
1.About motor
  • About motor
2.ROS robot control board drive
  • 0. Notes (Must read!!)
  • 1. Control motor
  • 2. Timer captures encoder data
  • 3. PID control robot car
  • 4. Kinematic Analysis-Mecanum wheel structure
  • 5. Kinematic Analysis-Ackerman structure
  • 6. Kinematic Analysis-4WD structure
3.STM32 board car tutorials
0. Notes (Must read!!)
  • Notes
1. Get started quickly
  • 0. Installation Instructions
  • 1. Version configuration
  • 2. Smart car installation video
  • 3. Precautions for use
2. Introduction to STM32 development board
  • 0. Notes (must read)
  • 1. Learn about STM32
  • 2. Introduction to STM32 development board
  • 3. Development board pin assignment
  • 4. Introduction to HAL library and LL library
3. Setting up and using the development environment
  • 1. Common development tools
  • 2. STM32CubeMX Install - Use
  • 3. STM32CubeIDE Install - Use
  • 4. Common Driver Installation
  • 5. Program download and simulation
  • 6. Engineering experience and migration
4. Car expansion tutorial
  • 1. Servo control
  • 2. Basic use of ultrasonic steering gear gimbal
  • 3. Motor control
  • 4. OLED display light sensitivity value
  • 5. Infrared sensor
  • 6. Four-way tracking module
  • 7. Infrared remote control
  • 8. Ultrasonic ranging
  • 9. PS2 controller test
  • 10. Car line patrol
  • 11. Ultrasonic follow
  • 12. Ultrasonic obstacle avoidance
  • 13. Ultrasonic obstacle avoidance (servo gimbal version)
  • 14. Infrared sensor obstacle avoidance
  • 15. Infrared remote control
  • 16. PS2 handle remote control
4. 2-channel motor drive module
For MSPM0G3507
  • 1.AT8236 drive tutorials
  • 2.TB6612 drive tutorials
For MSPM0G3519
  • 1.AT8236 drive tutorialsnew
  • 2.TB6612 drive tutorialsnew
5. 4-channel motor drive module
Introduction and Debug
  • 1.Introduction to 4-channel motor drive board
  • 2. Control command
  • 3. 520 motor introduction and usage
  • 4. PC host
IIC communication
  • For MSPM0G3507
  • For MSPM0G3519new
  • For STM32
  • For ESP32
  • For Arduino
  • For PICO2
  • For Jetson NANO
  • For RPi5
  • For RDK X5
USART communication
  • For MSPM0G3507
  • For MSPM0G3519new
  • For STM32
  • For ESP32
  • For Arduino
  • For PICO2
  • For Jetson NANO
  • For RPi5
  • For RDK X5
Download
  • 3D-Model-File
  • Code
Download ZIP

Welcome to L-Type Motor repository

2. Timer captures encoder data

13. The timer captures the encoder data

13. The timer captures the encoder data 13.1. Experimental purpose 13.2. Configuration pin information 13.3. Analysis of the experimental flow chart 13.4. core code explanation 13.5. Hardware connection 13.6. Experimental effect

13.1. Experimental purpose

Use the timer encoder mode function of STM32 to capture the encoder data.

13.2. Configuration pin information

  1. Import the ioc file from the Motor project, name it Encoder, and then the related driver of serial port 1.

According to the schematic diagram, the two encoders of the four motors are respectively connected to channel 1 and channel 2 of timer 2 3 4 5. The motor M1 corresponds to the timer TIM2, M2 corresponds to TIM4, M3 corresponds to TIM5, and M4 corresponds to TIM3.

image-20220311152029633

  1. Taking the timer TIM2 as an example, the setting methods for TIM3, TIM4, and TIM5 are the same. Select Combined Channels mode as Encoder Mode encoder mode.

image-20220311154406375

  1. In the settings, change the Encoder Mode to Encoder Mode TI1 and TI2, set it to quadruple frequency, and other parameters are shown in the figure below.

image-20220311154534666

The final chip configuration pins are shown in the figure below:

image-20220311154742986

13.3. Analysis of the experimental flow chart

image-20220519105917493

13.4. core code explanation

  1. Create new bsp_encoder.h and bsp_encoder.c, and add the following content to bsp_encoder.h:

image-20220311154905298

  1. Create the following content in the bsp_encoder.c file:

Encoder timer initialization.

image-20220311155015828

  1. Read the data from the encoder.

image-20220311155118686

  1. Update the count value of the encoder. It needs to be called every 10 milliseconds.

image-20220311155203831

  1. Return the count of encoders that have been counted up to now, Encoder_Get_Count_Now returns one way, and Encoder_Get_ALL returns four ways.

image-20220311155324653

  1. Add the content of encoder initialization in the Bsp_Init() function.

image-20220311160927305

  1. The new encoder array is used to save the data of the encoder, and show_encoder is used to print the count of the encoder.

image-20220311161423196

  1. On the basis of the original control motor, the function of printing encoder data every 100 milliseconds is added.

image-20220311161403382

13.5. Hardware connection

The motor connecting line needs to be connected to the corresponding motor as shown in the figure below, otherwise it may cause the problem that the program does not match the phenomenon. Motor 1 corresponds to the motor in the upper left corner of the body, Motor 2 corresponds to the motor in the lower left corner, Motor 3 corresponds to the motor in the upper right corner, and Motor 4 corresponds to the motor in the lower right corner.

image-20220311143208773

Since the power of the motor is relatively large, the expansion board should not be powered by USB 5V directly, but must be powered by DC 12V.

Then connect the micro-USB cable to the expansion board and computer.

13.6. Experimental effect

Since the motor will turn when started, please stand up the trolley before the experiment, and the motor wheels are suspended in the air to avoid rampage.

After the program is programmed, the LED light flashes every 200 milliseconds. Open the serial port assistant, you can see the data of the encoder. Press the first forward, the second free stop, the third backward, and the fourth brake to stop.

image-20220519110046762

Control motor
PID control robot car

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文