yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
310 Motor📖
1.Hardware parameter
  • Hardware parameter
2.ROS robot control board tutorials
  • 3.0 ReadMe
  • 3.1 Control motor
  • 3.2 Timer got encoder data
  • 3.3 PID control robot movement
  • 3.4 4WD Robot kinematics analysis
  • 3.5 Ackerman Robot kinematics analysis
  • 3.6 Mecanum wheel kinematics analysis
3.STM32 smart car tutorials
0. Get started quickly
  • 14.Infrared sensor obstacle avoidance
  • 0. Installation Instructions
  • 1. Version configuration
  • 2. Smart car installation video
  • 3. Precautions for use
1. Introduction to STM32 board
  • 1. Learn about STM32
  • 2. Introduction to STM32 development board
  • 3. Development board pin assignment
  • 4. Introduction to HAL library and LL library
2. 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
3. Car expansion tutorial
  • 1.Servo control
  • 2.Basic use ultrasonic servo PTZ
  • 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 PTZ version)
  • 15.Infrared remote control
  • 16.PS2 handle remote control
4.2-channel motor drive module tutorial
  • 2.1 Introduction of Module
  • 2.2 For STM32
  • 2.3 For Arduino
  • 2.4 For RaspberryPi
  • 2.5 For RaspberryPi Pico
  • 2.6 For jetson nano
  • 2.7 For MSPM0G3507
  • 2.8 For MSPM0G3519new
5.4-channel motor drive tutorials
Introduction and debugging
  • 0.Motor introduction and usage
  • 1.Introduction to 4-channel motor drive board
  • 2.Control command
  • 3.PC host
USART communication
  • For Arduino
  • For Jetson NANO
  • For MSPM0G3507
  • For MSPM0G3519new
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
IIC communication
  • For Arduino
  • For ESP32
  • For ESP32
  • For Jetson NANO
  • For MSPM0G3507
  • For MSPM0G3519new
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
Download
  • Motor_3D_Model_File
  • Annex_ROSRobotControlBoard
  • Annex_STM3RobotCar
  • Annex_2-channelMotorDriveModule
  • Annex_4-channelMotorDriveModule
Download ZIP

Welcome to 310 Motor repository

3.Motor control

Motor control

Motor control1、software-hardware2、Brief principle2.1、Hardware schematic diagram2.2、Physical connection diagram2.3、Principle of control3、Engineering configuration3.1、Notes3.2、Pin configuration4、Main FunctionMain Function4.1、User function4.2、HAL library functions5、Experimental phenomenon

This tutorial demonstrates how to control 4 310 motors using timers and print the encoder values via the serial port, where the KEY button controls the rotation mode of the motors.

1、software-hardware

  • STM32F103CubeIDE

  • STM32 robot expansion board

  • 310 motor * 4

  • Type-C cable or ST-Link

    Download or simulate the program of the development board

2、Brief principle

2.1、Hardware schematic diagram

image-20231023153314195

2.2、Physical connection diagram

image-20231106171200505

image-20231111121447919

2.3、Principle of control

Motor speed and steering control: configure timer (TIM1 and TIM8) PWM output mode, change the duty cycle of PWM signal;

Motor encoder reading: Configure the encoder interface mode of timers (TIM2, TIM3, TIM4 and TIM5) to count the motor encoder signal.

  • 310 motor
Type of motor310 motor
Rated voltage of moto7.4V
Encoder supply voltage3.3-5V
Gear set reduction ratio1:20
Number of magnetic ring lines13 line
encoder typeIncremental Hall encoder with phase AB

Count value

Maximum count value={Reduction ratio*Number of encoder lines*4}=20*13*4=1040
xxxxxxxxxx
4: Represents the encoder frequency doubling
The rotation speed of the car can be calculated according to the count of rotation. This tutorial does not cover the conversion of speed
  • Motor drive

The STM32F103ZET6 integrates four AT8236 single-channel brush DC motor driver chips.

The input pins IN1 and IN2 control the output state of the H-bridge. The following table is the logical relationship between the input and output:

IN1IN2OUT1OUT2feature
00ZZGlide and sleep
10HLForward direction
01LHReverse direction
11LLbrake

When PWM control is used to implement the speed regulation function, the H-bridge can be operated in two different states: fast decay or slow decay.

IN1IN2feature
PWM0Forward PWM, fast attenuation
1PWMForward PWM, slow decay
0PWMReverse PWM, fast decay
PWM1Reverse PWM, slow decay

PWM period:T = 50us → f = 20KHz

T(s)=(ARR+1)∗(PSC+1)TIM_CLK(Hz)=(3599+1)∗(0+1)72000000(Hz)=0.00005s=50us
  • Encoder reading

    The count value is obtained by reading the timer CNT register value directly.

image-20231201152036621

The tutorial setup is count on TI1 and TI2 , set the encoder mode to 4x frequency, and the input signal is not reversed;

image-20231201152123515

xxxxxxxxxx
Whether the counter counts up or down depends on the AB trust sign

3、Engineering configuration

3.1、Notes

Omitted project configuration: New project, chip selection, project configuration, SYS for pin configuration, RCC configuration, clock configuration, and project configuration content

The project cofiguration part, which is not omitted, is the key point to configure in this tutorial.

xxxxxxxxxx
Please refer to [2, development environment construction and use: STM32CubeIDE installation - Use] to understand how to configure the omitted part of the project

3.2、Pin configuration

  • GPIO

image-20231024120011541

  • USART

image-20231023185117375

  • Same configuration for TIM2, TIM3, TIM4, TIM5:TIM4 configuration is demonstrated here

image-20231023185540186

image-20231023185607400

  • TIM1 and TIM8 configuration are the same:TIM8 configuration is demonstrated here

image-20231023185708756

image-20231023185754680

4、Main Function

Detailed code can open the project file we provide, into the Bsp folder to view the source code.

Main Function

featureCorresponding tutorial
key3. Development board basic tutorial: Key control
Serial port3, development board basic tutorial: serial communication

4.1、User function

function:Motor_Ignore_Dead_Zone

Function prototypesint16_t Motor_Ignore_Dead_Zone(int16_t pulse)
Functional DescriptionThe PWM signal dead zone is ignored
Input parameterspulse:Value of pulse
Return valueValue of pulse

function:Motor_Stop

Function prototypesvoid Motor_Stop(uint8_t brake)
Functional DescriptionAll motors stopped
Input parametersbrake:The value is 0 or 1
Return valueNone

function:Motor_Set_Pwm

Function prototypesvoid Motor_Set_Pwm(uint8_t id, int16_t speed)
Functional DescriptionSet motor speed
Input parameters1id:Motor ID
Input parameters2speed:Motor speed
Return valueNone

function:Encoder_Read_CNT

Function prototypesint16_t Encoder_Read_CNT(uint8_t Motor_id)
Functional DescriptionRead the encoder count
Input parametersMotor_id:Motor ID
Return valueCount value

function:Encoder_Get_Count_Now

Function prototypesint Encoder_Get_Count_Now(uint8_t Motor_id)
Functional DescriptionReturns the total count of encoders counted since boot up (single way)
Input parametersMotor_id:Motor ID
Return valueCount value

function:Encoder_Get_ALL

Function prototypesvoid Encoder_Get_ALL(int *Encoder_all)
Functional DescriptionReturns the total count of encoders counted since boot up (single way)
Input parametersEncoder_all:Points to the head of the encoder array
Return valueNone

function:Encoder_Update_Count

Function prototypesvoid Encoder_Update_Count(void)
Functional DescriptionUpdate the total count of the encoder
Input parametersNone
Return valueNone

4.2、HAL library functions

The HAL library functions that were covered in the previous tutorial will not be covered

xxxxxxxxxx
For information on how to parse the HAL and LL libraries that are covered throughout this tutorial, check out the documentation under the STM32 Manual: STM32F1_HAL and LL Library_ User Manual

function:HAL_TIM_Encoder_Init

Function prototypesHAL_StatusTypeDef HAL_TIM_Encoder_Init
(TIM_HandleTypeDef *htim, const TIM_Encoder_InitTypeDef *sConfig)
Functional DescriptionInitialize the encoder mode for the timer
Input parameters1htim:Timer handle address
Input parameters2sConfig:The encoder initializes the configuration structure
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

function:HAL_TIM_Encoder_MspInit

Function prototypesvoid HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
Functional DescriptionInitialize the peripheral clock and GPIO for the timer encoder interface
Input parametershtim:Timer handle address
Return valueNone

function:HAL_TIM_Encoder_MspDeInit

Function prototypesvoid HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
Functional DescriptionCancel peripheral clock and GPIO initialization for the timer encoder interface
Input parametershtim:Timer handle address
Return valueNone

function:HAL_TIM_Encoder_Start

Function prototypesHAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Functional DescriptionStart timer encoder mode
Input parameters1htim:Timer handle address
Input parameters2Channel:The timer channel
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

5、Experimental phenomenon

After downloading the program successfully, press the RESET button of the development board to open the serial debugging assistant to observe the phenomenon

xxxxxxxxxx
Program download can refer to [2, development environment construction and use: program download and simulation]

phenomenon:

Press KEY1:You can manually turn the four motors to observe the value of the encoder printed by the serial port;

Press KEY2:The motor turns forward and prints the encoder value on the serial port;

Press KEY3:The motor reverses and prints the encoder value on the serial port.

xxxxxxxxxx
The experimental phenomenon can be seen [Motor control _ Experimental Phenomenon.MP4]

 

Basic use ultrasonic servo PTZ
OLED display light sensitivity value

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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文