yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
ROS Robot Expansion Board📖
1.Expansion board STM32 driver
  • 0. Precautions
  • 1.1Expansion Board Introduction_V4.0
  • 1.1 Expansion Board Introduction_V3.0
  • 1.1 Expansion Board Introduction_V1.0
  • 1.2 STM32 Development environment
  • 1.3 Button to control the buzzer to whistle
  • 1.4 FreeRTOS application
  • 1.5 Serial communication
  • 1.6 SBUS model aircraft remote control
  • 1.7 CAN bus communication
  • 1.8 RGB colorful light bar
  • 1.9 Timer interrupt to control PWM servo
  • 1.10 Control serial port servos
  • 1.11 Nine-axis attitude sensor to obtain data
  • 1.12 Control the forward and reverse rotation of the motor
  • 1.13 The timer captures the encoder data
  • 1.14.1 Robot kinematics analysis theory
  • 1.14.2 Mecanum wheel kinematics analysis
  • 1.15 PID control robot movement
  • 1.16 OLED character display
  • 1.17Host computer use
2.Python basic control
  • 2.0 Bind PCB port devices
  • 2.1 Update the firmware of the expansion board
  • 2.2 Turn off the self-starting large program at startup
  • 2.3 Install the Rosmaster driver library
  • 2.4 Buzzer whistle
  • 2.5 Control PWM servo
  • 2.6 RGB colorful light bar special effects display
  • 2.7 Control the forward and reverse rotation of the motor
  • 2.8 Control the movement of the robot
  • 2.9 Control Serial Servo
3.ROS1 Basic Course
  • 1.ROS introduction
  • 2.ROS installation
  • 3.ROS common command tools
  • 4.ROS workspace
  • 5.ROS function package
  • 6.ROS node
  • 7.ROS topic publisher
  • 8.ROS topic subscribers
  • 9.ROS service client
  • 10.ROS service server
  • 11.ROS action client
  • 12.ROS action server
  • 13.ROS custom message reception
  • 14.ROS-launch file
  • 15.ROS-TF transformation
  • 16.ROS parameter service
  • 17.ROS-rviz use
  • 18.ROS-rqt tool usage
  • 19.Topic message recording and playback
  • 20.urdf model introduction
  • 21.gazebo introduction
  • 22.ROS distributed communication
4.ROS1 robot control
  • 0. Bind PCB port devices
  • 1. Package Use the tutorial
  • 2. Package Description
  • 3. Robot keyboard control
  • 4. Robot state estimation
  • 5. Robot imu calibration
  • 6. Robot URDF Model
5.ROS2 Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
6.ROS2 robot control
  • 0. Bind PCB port devices
  • 1. Package Use the tutorial
  • 2. Robot information release
  • 3. Robot keyboard control
  • 4. Robot state estimation
  • 5. Robot calibration
  • 6. URDF model
7.RDK X3 course
  • 1. Update the firmware of the expansion board
  • 2. Turn off the self-starting large program at startup
  • 3. Install the Rosmaster driver library
  • 4. Buzzer whistle
  • 5. Control PWM servo
  • 6. RGB colorful light bar special effects
  • 7. Control motor forward reverse
  • 8. Control robot movement
  • 9. Control Serial Servo
Download
  • Rules_File
  • Hardware Info
  • Code
  • 3D Model File
  • RDK Code
  • ROS2_Basic_VM
  • PC_Software
Download ZIP

Welcome to ROS Robot Expansion Board repository

1.9 Timer interrupt to control PWM servo

9. Timer interrupt to control PWM servo

9. Timer interrupt to control PWM servo 9.1. Purpose of the experiment 9.2, configuration pin information 9.3. Analysis of the experimental flow chart 9.4. core code explanation 9.5. Hardware connection 9.6. Experimental effect

9.1. Purpose of the experiment

Use the basic timer interrupt function of STM32 to simulate the output PWM signal and control the PWM servo.

9.2, configuration pin information

  1. Import the ioc file from the Beep project and name it PwmServo.

According to the schematic diagram, the servos S1 S2 S3 S4 are connected to the PC3 PC2 PC1 PC0 pins of the STM32 respectively.

image-20220311092423330

Set the PC0 PC1 PC2 PC3 pins as output mode, the specific parameters are shown in the following figure:

image-20220311093207893

  1. Next, we need to configure timer 7. The specific configuration parameters are shown in the figure below.

image-20220311093320238

Turn on the timer global interrupt setting.

image-20220311093358063

9.3. Analysis of the experimental flow chart

image-20220519102718568

9.4. core code explanation

  1. Create new bsp_pwmServo.h and bsp_pwmServo.c, and add the following content in pwmServo.h:

image-20220311094400800

Among them, SERVO_X_HIGH() means output high level, SERVO_X_LOW() means output low level.

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

The PwmServo_Init() function initializes the PWM position to 90 degrees.

image-20220311094947794

The PwmServo_Angle_To_Pulse() function converts the angle into a PWM duty cycle value.

image-20220311095419820

  1. The PwmServo_Set_Angle() function sets the pwm servo angle, index=0~3, and angle is 0-180.

image-20220311095059758

  1. The PwmServo_Set_Angle_All() function sets the angle of all pwm servos, angle_s1 corresponds to the angle of S1, the range is 1-180, and the other three parameters correspond to the angle values of S2, S3 and S4 respectively.

image-20220311095205303

  1. The PwmServo_Handle() function needs to be called in the interrupt of the timer to simulate the output PWM signal and control the servo according to the angle value of the servo set above.

image-20220311095845165

  1. Create a new HAL_TIM_PeriodElapsedCallback() function. The name of this function cannot be changed, otherwise the function will be found. The PwmServo_Handle() function is called by the timer 7 interrupt to generate the PWM signal.

image-20220311100301329

  1. Add the following content to the Bsp_Loop() function and press the button to control the PWM servo.

image-20220311102019612

9.5. Hardware connection

Since the PWM servos have different voltage drive values, the expansion board has added a voltage switching function. According to the jumper cap on the expansion board, the PWM output voltage can be modified to 5V or 6.8V. To use the PWM servo, the corresponding voltage must be selected with a jumper cap to avoid burning the servo. The PWM servos cannot be controlled without the jumper caps inserted. The pins of the PWM servo are: yellow->signal, red->power positive, black->power negative.

image-20220311101252607

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

9.6. Experimental effect

After the program is programmed, the LED light flashes every 200 milliseconds. Press the button multiple times, the PWM servo will go back and forth between 50 degrees and 150 degrees.

RGB colorful light bar
Control serial port servos

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/中文