Digital Electronics and Microcontrollers
Domain 4: Digital Electronics and Microcontrollers
This section covers number systems, logic gates, combinational and sequential blocks, and microcontroller basics: GPIO, ADC, PWM, serial interfaces, and debouncing. Questions often combine a truth table with a small calculation.
Core rules
- Binary weights 8-4-2-1; hex digits 0–9,A–F. Convert by grouping binary in fours: 1011 0110 = 0xB6 = 182.
- Gates: AND outputs 1 only when all inputs are 1; OR when any is 1; XOR when inputs differ; NAND and NOR are inverted versions. De Morgan: A·B bar = A bar + B bar.
- Combinational logic has no memory; flip-flops and counters are sequential and need clock, setup, and hold timing.
- Microcontroller GPIO pins have current limits; use a driver for relays, motors, and high-current LEDs. Configure unused inputs with pull-up or pull-down, not floating.
- ADC: code = Vin × (2^n − 1)/Vref, approximately. PWM duty cycle sets average voltage; frequency must suit the load.
Worked example
An 8-bit ADC has Vref = 5.0 V and outputs code 128. Resolution = 5.0/255 = 19.6 mV per count. Vin ≈ 128 × 19.6 mV = 2.51 V. If the input is actually 2.50 V, the expected code is 2.50/0.0196 = 127.5, which rounds to 128, so the reading is consistent. For a 10-bit ADC the same 2.50 V would give 2.50 × 1023/5 = 511.5, about 512.
Traps
- Forgetting that 8-bit full scale is 255, not 256, when converting code to volts.
- Treating active-low signals as active-high; a reset pin with a bar or asterisk is asserted at 0 V.
- Leaving CMOS inputs floating, causing random switching and excess current.
- Driving a relay coil directly from a port pin.
- Assuming a 5 V tolerant pin survives 5 V when the supply is off.