What you will build
A 24-hour clock, HH:MM:SS, on six 7-segment displays. Plan about 2 hours. You should know the Counter, ROM and the 7-segment display. The files are saved in the 5.0.0 format; we did not verify a classic 2.7.1 file. The self-test uses --tty table, which works in 5.0.0.
Design: counters, not clocks
The Clock component only produces ticks. Time is however many ticks you count: the seconds counter counts ticks, the minutes counter counts every 60th, the hours counter every 3600th. Each value then goes through a ROM that turns it into two digits for two displays. See clock and simulation for ticks and frequency.
Mod-60 and mod-24 counters
- Seconds: a Counter with Data Bits 6, Maximum Value 59 and Action On Overflow set to Wrap around.
- Minutes: the same.
- Hours: Data Bits 5, Maximum Value 23, Wrap around.
- One Clock on every counter, rising edge.
Chain the enables, never the clocks. Minutes count when the seconds carry output is 1; hours count when the seconds carry and the minutes carry are both 1. The carry output is 1 while the value equals its maximum (Counter page). A halt pin on the AND of the three carry outputs stops a command-line run at 23:59:59.
Describe this circuit
Components: Clock 1; Counter ss; Constant 1; Counter mm; Constant 2; Counter hh; Constant 3; Buffer 1; AND Gate 1; AND Gate 2; Output pin hh; Output pin mm; Output pin ss; Output pin halt.
- Clock 1 connects to Counter ss, Counter mm, Counter hh (net clk).
- Counter ss connects to Output pin ss (net ss), 6 bits wide.
- Counter ss connects to Constant 1, 6 bits wide.
- Counter ss connects to Buffer 1, AND Gate 1, AND Gate 2 (net ss_max).
- Counter mm connects to Output pin mm (net mm), 6 bits wide.
- Counter mm connects to Constant 2, 6 bits wide.
- Counter mm connects to Buffer 1 (net mm_en).
- Counter mm connects to AND Gate 1, AND Gate 2 (net mm_max).
- Counter hh connects to Output pin hh (net hh), 5 bits wide.
- Counter hh connects to Constant 3, 5 bits wide.
- Counter hh connects to AND Gate 1 (net hh_en).
- Counter hh connects to AND Gate 2 (net hh_max).
- AND Gate 2 connects to Output pin halt (net halt).
Test it: a whole day
Run --tty table on the file. It prints one line per tick (hours, minutes, seconds in binary) and stops at the halt pin.
java -jar logisim-evolution-5.0.0-all.jar --tty table circ-digital-clock-counters.circ
0 0000 00 0000 00 0000
0 0000 00 0000 00 0001
0 0000 00 0000 00 0010
...
1 0111 11 1011 11 1001
1 0111 11 1011 11 1010
1 0111 11 1011 11 1011
Download circ-digital-clock-counters.circ and its descriptor (line count and SHA-256 of the expected output).
The mistake to avoid: a ripple clock
Do not clock the minutes counter from the seconds carry. In circ-digital-clock-broken-ripple-clock.circ we did exactly that.
7-segment displays from a ROM
loc Logisim storesPorts as a table
| # | Port | Direction | Width | Offset from anchor |
|---|---|---|---|---|
| 1 | Segment A | in | 1 | (20, 0) |
| 2 | Segment B | in | 1 | (30, 0) |
| 3 | Segment C | in | 1 | (20, 60) |
| 4 | Segment D | in | 1 | (10, 60) |
| 5 | Segment E | in | 1 | (0, 60) |
| 6 | Segment F | in | 1 | (10, 0) |
| 7 | Segment G | in | 1 | (0, 0) |
| 8 | Decimal point | in | 1 | (30, 60) |
The display’s eight inputs are the segments a to g and the decimal point; see the 7-segment page for the pin map. In the file, the Splitter ends map to a through g in order: the first end is bit 0, segment a.
The decoder ROM
A ROM with Address Bit Width 6 and Data Bit Width 16. For an address v from 0 to 59 the word holds the tens digit’s segments in bits 8 to 14 and the units digit’s segments in bits 0 to 6, with a = bit 0 and g = bit 6. Bits 7 and 15 are 0 (decimal points off). The patterns are 0 = 3F, 1 = 06, 2 = 5B, 3 = 4F, 4 = 66, 5 = 6D, 6 = 7D, 7 = 07, 8 = 7F, 9 = 6F. Addresses 60 to 63 are 0.
| # | V | Word |
|---|---|---|
| 0x0 | 0x3f3f | |
| 0x1 | 0x3f06 | |
| 0x2 | 0x3f5b | |
| 0x3 | 0x3f4f | |
| 0x4 | 0x3f66 | |
| 0x5 | 0x3f6d | |
| 0x6 | 0x3f7d | |
| 0x7 | 0x3f07 | |
| 0x8 | 0x3f7f | |
| 0x9 | 0x3f6f | |
| 0xa | 0x063f | |
| 0xb | 0x0606 | |
| 0xc | 0x065b | |
| 0xd | 0x064f | |
| 0xe | 0x0666 | |
| 0xf | 0x066d | |
| 0x10 | 0x067d | |
| 0x11 | 0x0607 | |
| 0x12 | 0x067f | |
| 0x13 | 0x066f | |
| 0x14 | 0x5b3f | |
| 0x15 | 0x5b06 | |
| 0x16 | 0x5b5b | |
| 0x17 | 0x5b4f | |
| 0x18 | 0x5b66 | |
| 0x19 | 0x5b6d | |
| 0x1a | 0x5b7d | |
| 0x1b | 0x5b07 | |
| 0x1c | 0x5b7f | |
| 0x1d | 0x5b6f | |
| 0x1e | 0x4f3f | |
| 0x1f | 0x4f06 | |
| 0x20 | 0x4f5b | |
| 0x21 | 0x4f4f | |
| 0x22 | 0x4f66 | |
| 0x23 | 0x4f6d | |
| 0x24 | 0x4f7d | |
| 0x25 | 0x4f07 | |
| 0x26 | 0x4f7f | |
| 0x27 | 0x4f6f | |
| 0x28 | 0x663f | |
| 0x29 | 0x6606 | |
| 0x2a | 0x665b | |
| 0x2b | 0x664f | |
| 0x2c | 0x6666 | |
| 0x2d | 0x666d | |
| 0x2e | 0x667d | |
| 0x2f | 0x6607 | |
| 0x30 | 0x667f | |
| 0x31 | 0x666f | |
| 0x32 | 0x6d3f | |
| 0x33 | 0x6d06 | |
| 0x34 | 0x6d5b | |
| 0x35 | 0x6d4f | |
| 0x36 | 0x6d66 | |
| 0x37 | 0x6d6d | |
| 0x38 | 0x6d7d | |
| 0x39 | 0x6d07 | |
| 0x3a | 0x6d7f | |
| 0x3b | 0x6d6f | |
| 0x3c | 0x0000 | |
| 0x3d | 0x0000 | |
| 0x3e | 0x0000 | |
| 0x3f | 0x0000 |
Describe this circuit
Components: Input pin V; ROM seg2; Splitter 1; Splitter 2; Splitter 3; 7-Segment Display u_digit; 7-Segment Display t_digit; Output pin W.
- Input pin V connects to ROM seg2 (net V, v), 8 bits wide.
- ROM seg2 connects to Splitter 1, Output pin W (net w, W), 16 bits wide.
- Splitter 1 connects to Splitter 2 (net u8), 8 bits wide.
- Splitter 1 connects to Splitter 3 (net t8), 8 bits wide.
- Splitter 2 connects to 7-Segment Display u_digit (net u0).
- Splitter 2 connects to 7-Segment Display u_digit (net u1).
- Splitter 2 connects to 7-Segment Display u_digit (net u2).
- Splitter 2 connects to 7-Segment Display u_digit (net u3).
- Splitter 2 connects to 7-Segment Display u_digit (net u4).
- Splitter 2 connects to 7-Segment Display u_digit (net u5).
- Splitter 2 connects to 7-Segment Display u_digit (net u6).
- Splitter 2 connects to 7-Segment Display u_digit (net u7).
- Splitter 3 connects to 7-Segment Display t_digit (net t0).
- Splitter 3 connects to 7-Segment Display t_digit (net t1).
- Splitter 3 connects to 7-Segment Display t_digit (net t2).
- Splitter 3 connects to 7-Segment Display t_digit (net t3).
- Splitter 3 connects to 7-Segment Display t_digit (net t4).
- Splitter 3 connects to 7-Segment Display t_digit (net t5).
- Splitter 3 connects to 7-Segment Display t_digit (net t6).
- Splitter 3 connects to 7-Segment Display t_digit (net t7).
Download circ-digital-clock-decoder.circ and the memory image circ-digital-clock-seg2.txt (a v2.0 raw file). The ROM contents are also stored in the .circ, so they load with the file (ROM page). To make a table for your own bit order, use the memory image generator or the 7-segment decoder generator.
Put the clock together
The whole clock is the counters, three identical ROMs (the hours counter’s 5 bits are widened to 6 with a constant 0), the splitters and six 7-segment displays, hours tens first. The three ROM words are also output pins, so the self-test can check the decoding.
Download circ-digital-clock-24h.circ. The displays are laid out in one row at the top of the sheet.
Tick rate, run switch, set buttons, colon and stopwatch
Tick rate. In the window, Simulate, Auto-Tick Enabled (Ctrl+K) starts the ticks, and Auto-Tick Frequency lists 0.25 Hz to 2048 kHz with 1.0 Hz checked on a fresh start. The Clock component is high for one tick and low for one, so one rising edge takes two ticks. At 1.0 Hz our seconds Counter gained one count about every 2 s; at 2.0 Hz it gained one about every second and wrapped from 59 to 0.
Run switch, reset, set buttons and colon. Give the seconds Counter a run input on its Enable pin. The minutes enable is the seconds carry gated by run, ORed with a set-minutes button, and the hours enable is the minutes carry gated the same way, ORed with a set-hours button. Reset goes to the Clear pin of the three Counters. A button only advances its Counter on the next rising clock edge. The colon is the Clock signal ANDed with run, so it blinks while the clock runs and stays dark when it is paused.
Describe this circuit
Components: Input pin clk; Input pin run; Input pin reset; Input pin set_m; Input pin set_h; Counter cnt_ss; Constant 1; AND Gate 1; OR Gate 1; Counter cnt_mm; Constant 2; AND Gate 2; OR Gate 2; Counter cnt_hh; Constant 3; AND Gate 3; Output pin hh; Output pin mm; Output pin ss; Output pin colon.
- Input pin clk connects to Counter cnt_ss, Counter cnt_mm, Counter cnt_hh, AND Gate 3 (net clk).
- Input pin run connects to Counter cnt_ss, AND Gate 1, AND Gate 3 (net run).
- Input pin reset connects to Counter cnt_ss, Counter cnt_mm, Counter cnt_hh (net reset).
- Input pin set_m connects to OR Gate 1 (net set_m).
- Input pin set_h connects to OR Gate 2 (net set_h).
- Counter cnt_ss connects to Output pin ss (net ss), 6 bits wide.
- Counter cnt_ss connects to Constant 1, 6 bits wide.
- Counter cnt_ss connects to AND Gate 1 (net ss_max).
- AND Gate 1 connects to OR Gate 1, AND Gate 2 (net ss_carry).
- OR Gate 1 connects to Counter cnt_mm (net mm_en).
- Counter cnt_mm connects to Output pin mm (net mm), 6 bits wide.
- Counter cnt_mm connects to Constant 2, 6 bits wide.
- Counter cnt_mm connects to AND Gate 2 (net mm_max).
- AND Gate 2 connects to OR Gate 2 (net mm_carry).
- OR Gate 2 connects to Counter cnt_hh (net hh_en).
- Counter cnt_hh connects to Output pin hh (net hh), 5 bits wide.
- Counter cnt_hh connects to Constant 3, 5 bits wide.
- AND Gate 3 connects to Output pin colon (net colon).
Stopwatch. A mod-100 Counter counts hundredths when run is high, its carry (gated by run) enables a mod-60 seconds Counter, and that carry enables a mod-60 minutes Counter. Reset clears all three.
Describe this circuit
Components: Input pin clk; Input pin run; Input pin reset; Counter cnt_cs; Constant 1; AND Gate 1; Counter cnt_ss; Constant 2; AND Gate 2; Counter cnt_mm; Constant 3; Output pin mm; Output pin ss; Output pin cs.
- Input pin clk connects to Counter cnt_cs, Counter cnt_ss, Counter cnt_mm (net clk).
- Input pin run connects to Counter cnt_cs, AND Gate 1 (net run).
- Input pin reset connects to Counter cnt_cs, Counter cnt_ss, Counter cnt_mm (net reset).
- Counter cnt_cs connects to Output pin cs (net cs), 7 bits wide.
- Counter cnt_cs connects to Constant 1, 7 bits wide.
- Counter cnt_cs connects to AND Gate 1 (net cs_max).
- AND Gate 1 connects to Counter cnt_ss, AND Gate 2 (net cs_carry).
- Counter cnt_ss connects to Output pin ss (net ss), 6 bits wide.
- Counter cnt_ss connects to Constant 2, 6 bits wide.
- Counter cnt_ss connects to AND Gate 2 (net ss_max).
- AND Gate 2 connects to Counter cnt_mm (net ss_carry).
- Counter cnt_mm connects to Output pin mm (net mm), 6 bits wide.
- Counter cnt_mm connects to Constant 3, 6 bits wide.
Not tested
We checked the counting and decoding headlessly, and ran the counters in the window at 1 Hz and 2 Hz (F130). We did not read the six displays as digits in the window, did not run minutes and hours at tick rate, did not try tick frequencies above 2 Hz, and did not build a lap function. After opening a file in the window, click the canvas or press Ctrl+R, or the wires stay grey and the displays dark (F45).
Common mistakes
- Ripple clocking. See above.
- Maximum Value 60 instead of 59. The counter then has 61 states.
- Hours with Maximum Value 24. It counts 23 to 24.
- An hours counter with 4 data bits. It can only hold 0 to 15.
- A ROM without its header line. A memory image needs
v2.0 rawon the first line, or the load fails. - Overflow set to anything but Wrap around.
Downloads
Circuits: controls, stopwatch, counters, decoder, 24h clock, broken ripple clock. Memory image: seg2. Descriptors: the .vec.txt file next to each circuit. All are 5.0.0 files. To run a design like this on a real board, see the FPGA guide. Next: the traffic light controller, another state machine, or all projects.