TM1115 - STM32F103ZE - Chapter 7-8 (MOTOR - SERVO - ADC)
TM1115 - STM32F103ZE - Chapter 7-8 (MOTOR - SERVO - ADC)
TM1115 - STM32F103ZE - Chapter 7-8 (MOTOR - SERVO - ADC)
Chapter 8 ADC
8.0 Exercise 08 ADC as voltmeter, and/or ADC as dimmer
7.1 Servo motors
Servo motors are used to control the position of rotate objects, arms or hands of robot
and R/C car etc.
PWM
Common GND
SDASDASD
4
7.2 DC motors
• Used in DC powered cars and robots
• Wheels and movable joints
7.2 DC Motor Control
- A DC motor will rotate clockwise or anti-clockwise with respect to the
polarity of the motor power supply.
By using four switches, we can control the polarity of the motor power
supply. We call this as “H-Bridge”.
Anti-clockwise Clockwise
6
7.2 DC Motor Control
- Motor driver with DC motor
IN1(PE2), IN2(PE6)
Encoder Encoder
Feedback
DC motor
7
7.2 DC Motor Control
- Motor driver (L298N)
DC motor
7.2 DC Motor Control
- Motor Encoder O/P signal
PA6 – TIM3(ch1)
Encoder Aout
Encoder Bout
PA7 – TIM3(ch2)
https://howtomechatronics.com/tutorials/arduino/rotary-encoder-works-use-arduino/
Demonstration – PWM Generation
STEP 1 – Set TIM1_CH2(PE11), PB6 & PB7 as I2C1_SCL & I2C1_SDA pins
1. Channel 2
2. Prescaler and period to get
50Hz @72Mhz
• Prescaler:144-1(/144)
• Period:10000-1(/10000)
Demonstration – 07-Servo_step
Hints
1. Find out capture compare reload
value(CCR) to control the rotation
angle of servo motor
Demonstration – 07-Servo_step
STEP 2 – build project in STM32CubeMX and add code in uVision
KEY IN
Double-click
GENERATE CODE
Demo only 07a-Servo_linear
SDASDASD
- Back to the original position with faster speed
(clockwise direction)
15
Demo 07a-Servo_linear
Press reset button to start
IN1-PE2
IN2-PE6
ENA-
PE9(TIM1_CH1)
Encoder signal A
-PA6(TIM3_CH1)
Encoder signal B
-PA7(TIM3_CH2)
Exercise 08a-DC_motor-encoder
- Use Timer counter value to turn on LED
Encoder
24
8.1 Analog To Digital Converter with Direct Memory Address
– ADC DMA
25
8.1 Analog To Digital Converter with Direct Memory Address – ADC DMA
SDASDASD
Analog To Digital Converter with DMA
Loop
26
8.1 Analog To Digital Converter with Direct Memory Address – ADC DMA
SDASDASD
27
Exercise 8.1 – ADC as voltage Meter
- Add code
28
Exercise 8.1 – ADC as voltage Meter
- Analog To Digital Converter - ADC channel10
𝐴𝐷𝐶 𝑅𝑒𝑔𝑖𝑠𝑡𝑒𝑟
𝑉𝑖𝑛 = × 3.3
212
SDASDASD
~END~ 29