Open NicoSeia opened 1 week ago
It controls the overall flow of the processes done by the embedded system we are using, the stm32f103T8c
, and acts as the entry point of the system.
16x2 LCD display
, the HCSR04
ultrasonic sensor, the Motor
motor control and the Speedometer
.Controls the LCD display
via I2C using a PCF8574 pin expander using these functions:
lcd_init
: Initialises the display in 4-bit mode and configures the I2C protocol.lcd_print_string
: Displays a string on the screen, useful for displaying distance information or status messages.lcd_clear
: Clears the contents of the display and repositions the cursor in the upper left corner.lcd_set_cursor
: Controls the position on the screen for writing content at specific locations.We use I2C to communicate with the PCF8574
I2C I/O Expander, which in turn controls the LCD. This module receives the data to be displayed from the main.
Drives the HC-SR04 ultrasonic sensor to measure distances.
hcsr04_init
: Configures the trigger (TRIG_PIN) and echo (ECHO_PIN) pins, and sets the timers needed to measure the time of flight of the ultrasonic pulse.hcsr04_trigger
: Sends a 10-microsecond pulse to the TRIG_PIN, which initiates the measurement on the sensor.hcsr04_get_distance
: Measures the time it takes to receive the return pulse at the ECHO_PIN, and calculates the distance based on that time.Uses GPIO and timers to control the TRIG and ECHO pins and measure the flight time. The hcsr04_get_distance function returns the calculated distance to main.
Control the motor using PWM. This module allows you to initialise the GPIO and timer to generate a PWM signal, adjust the motor power by varying the PWM duty cycle, and enable/disable the motor output.
motor_init()
: Initialises the GPIO and timer for the PWM.motor_set_power(uint8_t percentage)
: Sets the motor power to the specified percentage.motor_enable()
and motor_disable()
: Enables or disables the motor.Implement a PID controller to adjust the motor power based on a measured value (such as speed or position) and a reference value.
pid_init(PID_Controller *pid)
: Initialises the PID structure with the desired gains and reference.pid_update(PID_Controller *pid, float measured_value)
: Calculates the PID output value, adjusting the motor power.pid_setpoint(PID_Controller *pid, float setpoint)
: Sets the reference value for the controller.Measure the motor speed in RPM using a sensor or pulse counter.
speedometer_init()
: Initialises the speed sensor.speedometer_getRPM()
: Calculates and returns the current motor speed in RPM.Module in charge of reading the value of a potentiometer through the ADC and DMA in the microcontroller.
This module manages the button inputs (START/STOP) to control the activation and deactivation of the motor, as well as object detection
It controls the periodic update logic for the system, including PID control, measurement acquisition, and LCD data display.
Each module in the system has its own communication with the peripherals and sensors of the STM32 microcontroller, optimising the use of resources through I2C, GPIOs, timers, and ADCs. Each of these communications and how they interact with each other is detailed below:
Motor Control using PWM
Setpoint reading by the ADC
Milestone Description:
In this issue: