Node 2: Engine System & Vehicle Speed Simulation
This repository contains the source code, hardware simulation, and documentation for Node 2 (Engine System) of the Smart Car project, developed on the STM32F401RE microcontroller.
📋 Project Objectives Phase 1: Engine Speed Simulation Accelerator Pedal Monitoring: Reading accelerator pedal position using the Analog-to-Digital Converter (ADC). Vehicle Speed Calculation: Converting accelerator position into vehicle speed percentage. Visual Speed Simulation: Simulating vehicle speed by changing the LED blinking frequency according to accelerator input. Phase 2: PWM Engine Output PWM Generation: Generating PWM output using TIM2 Channel 1. Dynamic Duty Cycle: Updating PWM duty cycle proportionally to engine speed. Timer Interrupt: Using TIM2 periodic interrupts for timing-related events. Phase 3: Telemetry Communication Binary Packet Transmission to the Central Controller. Battery Voltage Estimation from ADC measurements. UART Interrupt Transmission for efficient non-blocking communication. Debug UART Mode for validating transmitted data through Proteus Virtual Terminal. 🛠 Technical Specifications MCU: STM32F401RE Clock Source: Internal HSI (16 MHz) Development: STM32CubeMX + Keil uVision 5 Simulation: Proteus 9 Professional GPIO Mapping Pin Function Description PA1 ADC1_IN1 Accelerator Pedal / Battery Divider PA5 TIM2_CH1 PWM Output PA2 USART2_TX Telemetry Transmission PA3 USART2_RX UART Receive PB0 GPIO Output Vehicle Speed Indicator LED Firmware Overview Phase 1
The accelerator pedal is simulated using an analog voltage connected to PA1.
The firmware:
Reads ADC value Converts ADC to speed percentage (0–100%) Changes LED blinking delay according to calculated speed
Result:
Higher pedal position → Faster LED blinking.
Phase 2
TIM2 Channel 1 generates a PWM waveform.
The duty cycle is updated continuously:
ADC ↓ Speed (%) ↓ PWM Duty Cycle
This PWM output can later drive a real motor driver without firmware modification.
Phase 3
Node 2 periodically prepares a telemetry packet containing:
Vehicle Speed Battery Voltage Checksum
Packet format:
Field Size Header 1 Byte Speed 1 Byte Battery Voltage 2 Bytes Checksum 1 Byte Footer 1 Byte
Packet Layout
+---------+--------+-------------+-----------+---------+ | 0xAA | Speed | Battery(mV) | Checksum | 0x55 | +---------+--------+-------------+-----------+---------+
Checksum calculation:
Checksum = Header ^ Speed ^ Battery_LSB ^ Battery_MSB ^ Footer UART Communication
USART2 is configured as:
Baud Rate: 115200 8 Data Bits No Parity 1 Stop Bit Interrupt-Based Transmission
During development, the firmware supports two operating modes:
Debug Mode
Human-readable messages are transmitted to the Proteus Virtual Terminal:
Speed=25% Battery=10230mV Speed=48% Battery=10410mV Speed=76% Battery=10650mV Normal Mode
Binary telemetry packets are transmitted to the Central Controller using:
HAL_UART_Transmit_IT()
This mode is intended for final multi-node integration.
Proteus Simulation
Simulation components include:
STM32F401RE Potentiometer (Accelerator Pedal) LED Speed Indicator PWM Output Virtual Terminal Battery Divider
Simulation behavior:
Increasing accelerator input increases LED blinking frequency. PWM duty cycle increases proportionally. Battery voltage is calculated from ADC input. Telemetry packets are transmitted over USART2. Project Structure ├── 1_Firmware │ ├── Core │ ├── Drivers │ ├── Startup │ ├── Node2-EngineSystem.ioc │ └── Node2-EngineSystem.uvprojx │ ├── 2_Simulation │ ├── Node2_EngineSystem.pdsprj │ └── Node2_EngineSystem.hex │ └── 3_Docs ├── README.md ├── Project_Report.pdf └── Block_Diagram.pdf Current Features ✅ ADC Accelerator Reading ✅ Vehicle Speed Calculation ✅ Variable LED Blinking Simulation ✅ PWM Generation (TIM2) ✅ Battery Voltage Estimation ✅ Binary UART Packet Generation ✅ UART Interrupt Transmission ✅ Debug UART Mode for Virtual Terminal ✅ Ready for Central Controller Integration Future Improvements Multi-node Integration Central Controller Communication CAN Bus Migration Real Motor Driver Interface Closed-Loop Speed Control Dashboard Visualization