This project monitors real-time voltage levels from a potentiometer-driven divider network, utilizing both CPU polling and hardware interrupt methods to dynamically change a status LED's color when safety thresholds are crossed. It provides a foundational understanding of how embedded systems interface with mixed-signal environments, handle real-world hardware tolerances, and transition from processor-heavy loops to energy-efficient, interrupt-driven architectures.
Materials:To build this project, the following hardware components and software tools are required:
Hardware:RT-Thread RT-Spark Development Board: The core STM32 microcontroller board running our firmware and handling analog-to-digital monitoring.1M Potentiometer: Used to create a variable voltage divider circuit to simulate fluctuating power rails or battery discharge.
Resistors: Used to calibrate and shift physical reference voltage thresholds for custom hardware tests.
Resistors: Used to calibrate and shift physical reference voltage thresholds for custom hardware tests.
Digital Multimeter (DMM): Crucial for verifying exact rail voltages and validating the precise physical tripping points of the comparator.
Software:STM32CubeIDE & STM32CubeMX: The official integrated environments used for configuring the analog peripherals, GPIO pins, clock trees, and writing the underlying firmware.
1. Baseline Calibration
Before writing code, the system's power baseline must be established. Using a digital multimeter, the actual positive supply rail was measured:
Measured Supply Rail (V3v3): 3.319V
Initially, the firmware was configured to run a continuous polling loop. The MCU continuously checks the incoming analog data against a fixed internal reference.
Expected Theoretical Trip Point: 1.660VActual Measured Trip Point: 1.733V
NOTE:The slight variance between the theoretical 1.660V and the measured 1.733V is a normal characteristic of real-world hardware. It is caused by standard resistor tolerance variations and minor ambient noise on the breadboard layout.
To optimize performance, conditional compilation directives (#if blocks in main.c) were modified to switch execution to an interrupt-driven model.
Result: The threshold voltage remained perfectly stable at 1.733V, confirming that hardware accuracy is fully preserved.
The hardware voltage divider circuit was altered using different resistor values to target a 1.0V trip point. The code thresholds were updated accordingly, and successful validation was achieved using a multimeter, proving that it works.








Comments