-
Notifications
You must be signed in to change notification settings - Fork 0
Software
The STM32F401RE microcontroller is configured using the STM32CubeIDE. The configuration includes setting up the clock, GPIO pins, timers, and other peripherals. The configuration files are generated by the STM32CubeMX tool and are included in the project. We are using FreeRTOS for task scheduling and management.
The software for the Ultrasonic Security System is written in C and uses the STM32CubeIDE for development. The code is organized into the following directories:
-
Core - Contains the main application code, including the initialization and configuration of peripherals.
- Inc - Contains the header files for the application code.
- Src - Contains the source files for the application code.
- Drivers - Contains the device drivers for the STM32F401RE microcontroller.
- Middlewares - Contains the middleware libraries used in the project.
We can trigger this timer using __HAL_TIM_ENABLE(&htim1).
- Purpose: Used for generating the 10 us trigger pulse for the HC-SR04 Ultrasonic Sensor. Pin PA8 (TIM1_CH1) is used as the trigger output.
- Mode: One Pulse Mode (OPM).
- Prescaler: 84 - 1.
- Period: 10 - 1.
- Clock Source: Internal Clock (84 MHz).
-
Channel 1: PWM Generation CH1.
- Mode: PWM Mode 2.
- Pulse: 1.
The timer elapsed interrupt is used to move the stepper motor by one step.
- Purpose: Used for controlling the 28BYJ-48 Stepper Motor. The interrupt calls the library function to move the stepper motor by one step.
- Mode: Interrupt Mode.
- Prescaler: 84 - 1.
- Period: 10000 - 1.
- Clock Source: Internal Clock (84 MHz).
- Interrupt: ON (update).
The timer interrupt is used to update the start and end times for the echo pulse duration measurement.
- Purpose: Used for measuring the echo pulse duration from the HC-SR04 Ultrasonic Sensor. Pin PA1 (TIM5_CH2) is used as the echo input.
- Mode: Input Capture Direct Mode.
- Prescaler: 84 - 1.
- Period: 0xFFFFFFFF.
- Clock Source: Internal Clock (84 MHz).
-
Channel 2: Input Capture CH2.
- Polarity: Both Edges.
- Interrupt: ON (input capture).
The TIM4 interrupt is used to move the stepper motor by one step. The interrupt handler calls the stepper motor library function to move the motor by one step.
The TIM5 interrupt is used to capture the rising and falling edges of the echo pulse from the HC-SR04 Ultrasonic Sensor. The interrupt handler updates the start and end time variables for the echo pulse duration measurement.
The ultrasonic.h library provides functions to interface with the HC-SR04 Ultrasonic Sensor. It requires a one pulse mode timer to be set for the trigger pulse generation and an input capture mode timer to measure the echo pulse duration. It also requires the input capture interrupt to be set up correctly to capture the rising and falling edges of the echo pulse and set the start and end time variables.
Check ultrasonic.h for the complete function definitions.
-
ultrasonic_init- Initializes the library by getting the timer handle, echo duration variable pointers, and the os thread flag. -
ultrasonic_get_distance- Returns the distance measured by the sensor in centimeters. Will return -1 if out of range.
The stepper.h library provides functions to interface with the 28BYJ-48 Stepper Motor using the ULN2003 Stepper Driver. It requires a timer interrupt to be set up to move the stepper motor by one step at a time.