Electronic Circuit Design

Where the behavior lives

Every circuit keeps its behavior somewhere. It can sit in the wiring, in which part feeds which and what a gate does with a signal, or it can sit in a program that a processor runs. The five circuits on this page, which I built between 2022 and 2024, move from one place to the other.

An eight-way quiz buzzer in 74-series logic, a running-light music circuit and a sound-and-light alarm hold everything they do in their wiring. An AT89C51 countdown timer moves the behavior into firmware that polls its inputs, and an STM32 interrupt study moves it into firmware driven by interrupts. Each one went the whole way, from a first sketch to a schematic, a simulation and a board.

A quiz buzzer that hears only the first press

Eight contestants each have a button, and the host has a control switch. When a question is read, the circuit has to find out who pressed first, show that contestant's number, sound a short tone and ignore every other button until the host clears the round. A countdown runs alongside and ends the round if nobody answers in time.

Two block chains. The answering path: eight active-low buttons into a 74LS148 priority encoder, into a 74LS279 latch holding three bits plus CTR, into a 74LS48 display decoder, into a seven-segment display, with CTR fed back to lock the encoder out. The timing path: an NE555 astable clock into a pair of 74LS192 down counters, into a 74LS48, into a seven-segment display, with CE raised when the count reaches zero.
The answering path and the timing path meet at the CTR signal, which is what makes the first press the only one.

The circuit has two paths, and they meet at a single signal. On the answering path, each button is debounced and then reaches a 74LS148 priority encoder, which turns many lines into one binary number. Priority matters here: if two contestants press at the same instant, the encoder still produces one valid answer instead of a garbled code.

A 74LS279 latch then holds that number, and alongside it a flag called CTR that says a number is being held. CTR is the heart of the design. It feeds back to the encoder's enable, so the moment a number is latched the encoder stops listening and no later press can reach it. The number stays on the seven-segment display, through a 74LS48 decoder, until the host's reset clears the latch and opens the encoder again.

The answering module in Multisim: eight bus lines through 10 kilohm pull-ups into a 74LS148N priority encoder, two 74LS279N latches holding the three-bit code and the CTR flag, a 74LS48N driving the display bus, and a 74LS00N and 74LS04N producing the encoder enable.
In the answering module, the CTR flag leaves the latch on the right and a few small gates at the bottom turn it back into the encoder's enable.

The timing path is a countdown. An NE555 running as an oscillator ticks a pair of 74LS192 down counters, which the host's start signal presets, and the count shows on its own pair of digits. When it reaches zero, the counters raise CE.

CE and CTR meet at one gate in front of the clock. Either a contestant's press or an expired countdown stops the clock, so the two ways a round can end are handled by the same piece of logic.

The timing module in Multisim: two 74LS192N down counters preset from STA, their outputs on a bus, with a 74LS04N and a 74LS11N combining CTR and CE to gate the clock CP.
In the timing module, CTR and CE meet at the AND gate, so either a successful press or a finished countdown stops the clock.
The pulse generation module in Multisim: a 555 timer with two 10 kilohm resistors, a 0.47 microfarad timing capacitor and a 0.01 microfarad control capacitor, producing the clock CLK.
The pulse generation module, where two resistors and a capacitor around the 555 set the countdown's tick.
The countdown display in Multisim: two 74LS192N down counters into two 74LS48N decoders into a pair of seven-segment displays, with a preset button and a function generator standing in for the clock.
The countdown and its display, with a function generator standing in for the 555 so that the count can be stepped by hand in simulation.

A successful press is also something you can hear. Any of the contestant keys starts the same 555 tone circuit, which drives a small buzzer. The whole circuit runs from a battery pack regulated down to the supply the logic expects.

The tone circuit in Multisim: eight contestant keys, each with a 3.1 kilohm resistor, feeding a 555 timer with a 1 kilohm resistor and two 0.1 microfarad capacitors into a 200 hertz buzzer.
In the tone circuit, any contestant key starts the same 555, so a successful press is heard as well as seen.

I drew the design hierarchically. The answering circuit, the timing circuit and the pulse generator are each a sheet of their own, and the buses between them carry the entire interface. Each sheet was simulated on its own before the full circuit was assembled, and only then was it built and tested on a board. Because the design was split this way, a fault found during assembly could be traced to a single sheet rather than to the whole schematic.

The top-level Multisim sheet: three hierarchical blocks named answering circuit module, timing circuit module and pulse generation circuit module, wired to eight contestant buttons, a host button and two seven-segment displays.
At the top level, the answering, timing and pulse modules are each a sheet of their own, joined by the buses that carry their whole interface.

One clock, a row of lights and a tone

The running-light music circuit is a 555 oscillator with a CD4017 decade counter behind it. Each pulse moves the counter to its next output, so exactly one LED in a row is lit at any moment, and the lit one walks along the row. The same pulse train also drives a speaker.

A 6 V cell and switch into an NE555 astable, into a CD4017 decade counter, into ten LEDs lit one at a time, with the 555 also driving a speaker.
One clock with two outputs: the counter walks the LEDs while the same pulses reach the speaker.

The rate is set in one place. The 555 charges its timing capacitor through two resistors and discharges it through one, so those three parts fix both the period and the duty cycle, and nothing else in the circuit has a say. The counter does the only other job on the board: it advances one step per rising edge and always holds exactly one output high. One light at a time, in order, forever, is a property of the part, not something the circuit has to arrange.

This is also why the light and the sound stay in step. A microcontroller version would keep one variable for the light and another for the tone, and the firmware would have to keep them in step. Here they are one signal taken from one node, so they can never disagree.

The same oscillator, split in two

The sound-and-light alarm uses the same oscillator to do something different. The 555's output goes to a complementary pair of transistors instead of a counter. An 8050 NPN sits below the buzzer and conducts during the high half of each cycle, while an 8550 PNP sits above a pair of indicator LEDs and conducts during the low half. Sound and light alternate, driven by a single oscillator, and no second timing element is needed.

A 6 V cell and switch into an NE555 astable, whose output drives an 8050 transistor into a buzzer and an 8550 transistor into two LEDs.
A single oscillator whose high and low halves are split between a buzzer and a pair of indicator LEDs.

The transistors are there because the 555 can decide whether a load is on, but it cannot supply that load's current. Each transistor only switches, and each is matched to the half of the cycle that turns it on.

I took both this circuit and the music circuit all the way to finished boards: schematic, layout, and a symbol and footprint library of my own for the parts the stock libraries lacked, drawn from the datasheet dimensions so that the pads fit the parts that would actually be soldered to them.

A countdown timer in firmware

The fourth circuit takes the same kind of problem and solves it in firmware. An AT89C51 microcontroller runs a settable countdown timer. Its buttons set it, start it, pause it and reset it, a character LCD shows the time, and a buzzer sounds when the count reaches zero. What the quiz buzzer needed a whole sheet of logic for takes a few lines of firmware here. The hardware's job is to give that firmware a clean interface.

The timer schematic in four blocks: an LCD1602 display, a buzzer circuit with a transistor, the AT89C51 minimum system with its crystal and reset network, and six buttons labeled increase, decrease, select, start, pause and reset.
The timer is drawn as four blocks, with the microcontroller between a display the user reads and the buttons it has to debounce.

The schematic has four blocks: display, buzzer, minimum system and buttons. The minimum system is the part every 8051 board shares, a crystal, a reset network and the supply, so drawing it as its own block lets it carry over unchanged into the next project. The buzzer hangs off a port pin through a transistor, because the pin can switch the buzzer but cannot drive it.

The firmware is split the same way as the hardware. One of the chip's hardware timers owns the second: it interrupts at a fixed rate, and its handler does nothing but count down. The main loop owns the display and the buttons. As a result, nothing in the main loop can stretch a second, and the interrupt never waits for a character to finish writing.

What remains is a small amount of state: whether the timer is running, what the count is, and which field the setting buttons act on. Select chooses the field, increase and decrease change it, start and pause flip the running flag, and reset restores the set value. Mechanical contacts bounce, so a press is accepted only after its line has stayed stable over successive passes of the loop, the same discipline my FPGA password lock applies in hardware, done here in software because that is the cheaper place for it. The display is rewritten only when the value it shows changes, which keeps the LCD's slow character writes out of the path that has to notice the next press.

Buttons that interrupt

The fifth circuit changes both the processor and the mechanism. An STM32F103C8 drives a row of LEDs and reads a few buttons, and it never polls those buttons. Each one is wired to an external interrupt line, and the interrupt controller arbitrates among them by priority.

An STM32F103C8 with twelve blue LEDs on PA1 to PA12, each through a 100 ohm resistor, and three buttons on PB0 to PB2 with 10 kilohm pull-ups.
The LEDs sit on output pins and the buttons on interrupt inputs, each LED with its own limiting resistor and each button with its own pull-up.

One button steps through a set of blink patterns, another changes the interval between steps, and a third chooses which single LED blinks. The hardware around them is the minimum the mechanism needs. Each LED's pin sets its state, and a series resistor sets its current. Each button pulls its line to ground against a pull-up, which gives the interrupt a clean falling edge to trigger on.

The firmware keeps the interrupt handlers short. Each one changes a single variable, the pattern, the interval or the chosen LED, and returns. Everything that takes time, the pattern itself and the delay between its steps, stays in the main loop, which reads those variables at its next step. A press therefore takes effect at the next boundary of the pattern rather than in the middle of one.

What the design gains is independence. The inputs do not depend on one another or on the output, and the code that draws the light pattern never has to ask whether a button was pressed. With polling, how quickly a press took effect would depend on how long the current blink step happened to be, and removing that coupling is what this study set out to do.