ATmega32A · Induction Balance Coil · Bare-Metal AVR C
Mechatronics & Robotics Engineering — Alexandria University | 2025
Ahmed Mohamed Hammad · Omar Mohab Mansour · Eyad Ahmed Sakr
Supervised by Dr. Hossam Abdelbaky
A metal discriminator that classifies metals by measuring the phase shift between a transmitted and received signal through an Induction Balance (IB) coil pair. When metal enters the field, it breaks the null balance between the two coils, producing a phase deviation characteristic of the metal type. All firmware runs bare-metal on an ATmega32A with no external libraries or frameworks.
12V Supply → 7805 (+5V) + MAX660 (-5V)
↓
IRF9540N/IRF540N CMOS Oscillator (50 kHz)
↓
TX Coil (100 µH) ──── drives field
↓ ↓
DC Bias + LM339N RX Coil (100 µH, opposite winding)
↓ ↓
TX Square Wave TL082C Op-Amp → LM339N Comparator
↓ ↓
INT0 (PD2) INT1 (PD3)
↘ ↙
ATmega32A
Timer1 Phase Measurement
↓
100-Sample Median
↓
USART @ 115200
| Material | Phase Reading (°) | Type |
|---|---|---|
| Air (Baseline) | 353.5° | Reference |
| Aluminium | 160° – 180° | Non-ferrous |
| Copper | 130° – 150° | Non-ferrous |
| Iron / Steel | 20° – 40° | Ferrous |
| Stainless Steel | 215° – 230° | Partially ferrous |
Readings are before baseline subtraction. Values vary between builds — calibrate before use.
| Component | Part | Role |
|---|---|---|
| Microcontroller | ATmega32A | Phase measurement, median filter, USART |
| P-ch MOSFET | IRF9540N | CMOS oscillator high-side |
| N-ch MOSFET | IRF540N | CMOS oscillator low-side |
| Op-Amp | TL082C | RX signal amplification |
| Comparator | LM339N | TX and RX analog → digital conversion |
| Voltage Inverter | MAX660 | Generates −5V rail for TL082C |
| TX / RX Coils | 2× 100 µH | IB null coil pair (10cm, 13 turns, 0.5mm) |
| Tank Capacitors | 2× 330 nF | LC tank with TX coil |
| Power Supply | 12V 2A | Main input |
Written in bare-metal AVR C (no Arduino, no HAL).
Key constants:
#define PERIOD_TICKS 320.0f // ticks per TX cycle @ 16MHz / 50kHz
#define DEAD_TIME_TICKS 240 // 15µs debounce guard
#define NUM_SAMPLES 100 // median filter buffer
#define BASELINE_DEG 126.0f // air reading offsetPhase calculation:
int16_t diff = (int16_t)(rxCount - txCount);
diff = ((diff % (int16_t)PERIOD_TICKS) + (int16_t)PERIOD_TICKS) % (int16_t)PERIOD_TICKS;
float phase = ((float)diff / PERIOD_TICKS) * 360.0f;
float corrected = phase - BASELINE_DEG;
if (corrected < 0.0f) corrected += 360.0f;Resolution: ~1.125° per tick
Requirements: MPLAB X IDE + AVR-GCC toolchain + ProgISP
- Open project in MPLAB X, set device to
ATmega32A, toolchain toAVR-GCC - Ensure
F_CPUis defined as16000000UL - Click Clean and Build → generates
.hexindist/ - Open ProgISP → select
ATmega32→ Load Flash → navigate to.hex→ Auto
- Proximity dampening — metal too close to the coil can dampen the oscillator, freezing the serial output until removed
- Settling time — readings take 3–4 seconds to stabilize due to the 100-sample buffer; wait between tests
- Thermal drift — continuous power draw warms the circuit over time, shifting the baseline
- Sleep mode — shut down oscillator during idle to reduce heat and baseline drift
- LCD + LED output — standalone display without needing a PC terminal
- Tare switch — on-demand baseline re-zero without reflashing
📄 Metal Discriminator Report.pdf
The full report covers theory of operation, complete hardware design, firmware architecture, schematic diagrams, coil winding procedure, step-by-step recreation guide, and test results.
├── Code/ # Firmware source files
├── Schematic/ # Circuit schematics
├── Metal Discriminator Report.pdf # Full project report
└── README.md
Academic project — Alexandria University, 2025.