Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Node 1: Safety System & Emergency Brake

This repository contains the source code, hardware simulation, and documentation for Node 1 (Safety System & TPMS) of the Smart Car project, developed on the STM32F401VE microcontroller.


📋 Project Objectives

Phase 1: Emergency Braking System

  • Instant Crash Detection: Utilizing External Interrupts (EXTI) on a falling edge to ensure the fastest possible response time.
  • Emergency Brake Activation: Instantly triggering a relay-based braking mechanism (Brake Actuator) the moment the sensor is activated.

Phase 2: Tire Pressure Monitoring System (TPMS)

  • Continuous Analog Monitoring: Utilizing the Analog-to-Digital Converter (ADC) to read real-time tire pressure values from an analog sensor.
  • Non-Blocking Logic: Implementing a timer-based polling system to check tire pressure every 500ms without halting the main CPU loop.
  • Low-Pressure Alert: Automatically activating a warning indicator when the pressure drops below a defined safety threshold.

Phase 3: Communication & Telemetry (UART)

  • Non-Blocking Data Transmission: Utilizing UART with Interrupts (IT) to transmit data without stalling the CPU or crashing the simulation.
  • Emergency Prioritization: Instantly broadcasting an emergency alert to the central system when the brake is activated, overriding standard telemetry.
  • Periodic Telemetry: Sending formatted, real-time tire pressure data to a monitoring console every 1000ms.

🛠️ Technical Specifications & Pinout

  • Development Environment: STM32CubeMX + Keil uVision v5
  • Simulation Environment: Proteus 9 Professional
  • Microcontroller Clock: 16MHz (Internal - HSI)

GPIO Mapping Table:

Pin Name Type (I/O) Circuit Role Initial State
PA0 Input (EXTI0 / Pull-up) Crash Sensor Button High (1)
PA2 Analog Input (ADC1_IN2) Tire Pressure Sensor (Analog) N/A
PA9 Alternate Function USART1_TX (Data Transmission) N/A
PD12 Output (Push-Pull) Normal Status (Green LED) High (1)
PD13 Output (Push-Pull) Emergency Status (Red LED) Low (0)
PD14 Output (Push-Pull) TPMS Warning (Blue LED) Low (0)
PC1 Output (Push-Pull) Brake Relay Actuator & Yellow LED Low (0)

⚙️ Development Phases & Implementation Details

1. STM32CubeMX Configuration

The hardware initialization was completely configured using STM32CubeMX:

  • System Core: Debug mode set to Serial Wire.
  • RCC (Clock): Configured to use the High-Speed Internal (HSI) clock for simulation stability.
  • EXTI Setup (Phase 1): PA0 configured as GPIO_EXTI0 with an internal Pull-up resistor and Falling Edge trigger detection. NVIC enabled for EXTI line0.
  • ADC1 Setup (Phase 2): * Configured PA2 as ADC1_IN2 in Independent Mode.
    • Stability Fix: Set Sampling Time to 480 Cycles to ensure proper capacitor charging and stable digital readings during Proteus simulation.
    • Trigger set to Software Start with 12-bit resolution.
  • USART1 Setup (Phase 3): Configured in Asynchronous mode with a Baud Rate of 9600. Crucially, the USART1 global interrupt is enabled in the NVIC settings to allow non-blocking transmission.
  • GPIO Setup: PD12, PD13, PD14, and PC1 configured as standard GPIO_Output with Push-Pull configuration.

2. Firmware Development (Keil uVision)

The application logic was written in C using the STM32 HAL Library:

  • Phase 1 (Interrupt Logic): Bypassed polling by utilizing the HAL_GPIO_EXTI_Callback(). Upon a crash (PA0 pulled to ground), the system immediately turns OFF the Green LED, turns ON the Red LED, and sets PC1 HIGH to activate the brake relay.
  • Phase 2 (TPMS Logic): * Introduced #define TPMS_THRESHOLD 2000 and #define TPMS_CHECK_PERIOD_MS 500 for modularity.
    • Implemented a Check_Tire_Pressure() function to start the ADC, poll for conversion, and compare the result against the threshold. If tire_pressure_adc < 2000, the Blue TPMS LED (PD14) turns ON.
    • Non-Blocking Architecture: Used HAL_GetTick() in the main while(1) loop to execute the TPMS check every 500ms, ensuring the microcontroller remains free for other potential tasks.
  • Phase 3 (Telemetry & Prioritization):
    • Replaced blocking UART functions with HAL_UART_Transmit_IT() to prevent system crashes caused by Proteus timing discrepancies.
    • Introduced a priority flag (brake_emergency_flag) triggered within the EXTI callback.
    • Formatted standard strings using sprintf to periodically transmit "Tire Pressure: [value]" every 1 second, while instantly overriding the UART buffer with "!!! EMERGENCY BRAKE ACTIVATED !!!" upon a crash event.

3. Hardware Simulation (Proteus)

The physical behavior of the system was validated using Proteus 9 Professional:

  • MCU Setup: The STM32F401VE component is loaded with the compiled .hex file.
  • Analog Power Requirements (Crucial): To ensure proper ADC functionality in Proteus, the VDDA and VREF+ pins must be explicitly connected to the +5V power rail, and VSSA/VREF- connected to Ground. Without this reference voltage, the ADC outputs zero.
  • TPMS Sensor (Phase 2): A Potentiometer is connected to PA2 to simulate varying tire pressures.
  • Serial Terminal (Phase 3): Added a Virtual Terminal connected to the MCU's TX pin (PA9). The terminal baud rate is strictly matched to 9600 to verify real-time monitoring of sensor data and emergency alerts.
  • Relay & Actuator Circuit (Phase 1): * The PC1 pin drives an NPN Transistor (BC547) through a 1kΩ base resistor to safely switch the relay.
    • A 12V Relay acts as the mechanical brake actuator.
    • A Flyback Diode (1N4007) is placed in parallel with the relay coil to protect the transistor from inductive voltage spikes.

📂 Project Structure

├── 1_Firmware/      # Keil project files, CubeMX .ioc config, and source codes (.c/.h)
├── 2_Simulation/    # Proteus simulation file (.pdsprj)
└── 3_Docs/          # Project documentation, datasheets, and PDF reports

About

The crash detection and emergency braking module developed for the Smart Car organization project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages