This repository contains the source code and documentation for a lab project on digital control. The project involves an STM32 microcontroller and a DC motor.
In Session 1, we wrote a simple program to toggle the state of an LED on the STM32 board. Additionally, we set up an external interrupt on pin PB3 to change the blinking rate of the LED.
During this session, we continued working with external interrupts and timers. We configured an interrupt on pin PB3 to start and stop a timer. We also set up another timer to generate an interrupt at a fixed frequency.
In the second phase of Session 2, we made modifications to the code to use a different GPIO pin and timer for generating the interrupt.
Session 3 focused on controlling the speed and direction of a DC motor using pulse-width modulation (PWM) and quadrature encoders. We implemented techniques to measure the speed and position of the motor.
In Session 4, we utilized the step response of the motor to determine the motor's parameters (k and tau) using a method called "system identification."
In the fifth session, we worked on controlling a DC motor using digital techniques. We used an STM32
microcontroller and implemented a digital control algorithm to regulate the motor's speed. The algorithm
involved proportional-integral (PI) control with a setpoint of 700 RPM. We calculated the control output based
on the error between the setpoint and the actual motor speed, and adjusted the motor's direction and PWM signal
accordingly. The control algorithm was executed at a sampling time of 7.62 ms. The code for this session can be
found in the main.c
file.
The DC motor was connected to the STM32 microcontroller as follows:
- Connect the motor's positive terminal to the STM32's PWM output pin (TIM11 Channel 1).
- Connect the motor's negative terminal to the GND pin of the STM32.
- Connect the direction control pin (pin PB4) of the STM32 to the motor's direction control pin.
- Connect the A signal pin (pin PE6) of the STM32 to the motor's quadrature encoder A signal pin.
- Connect the encoder's common ground to the GND pin of the STM32.
Please refer to the picture above to see the oscilloscope waveform captured during the DC motor control process.
- Saba Samadi
- Navid Dehban