A simple digital clock implemented in an FPGA

I am learning FPGA together with two of my students.

We started by making different ‘hello world’ projects like blinking LEDs, counters, and playing music with a buzzer.

This is one of our FPGA helloworlds – a digital clock:

Six seven-segment displays show hours (in 24-hour format), minutes and seconds.

The number on each display can be set by a pushbutton switch.

Instead of doing it on a breadboard, as it is customary for electronic helloworlds, we decided that soldering is a more pleasant task than fiddling with innumerous jumper wires.

My student, Aktolkyn Oteuova, soldering

Actually, there are two independent circuits on the board: one for the displays and the other one for the buttons.

The common anode seven-segment displays, LDD5122­20M, are organized in a multiplexed wiring.

The BC549 transistors are used as switches activating only one digit at a time (see, for example, the following tutorial: http://www.electronics-tutorials.ws/transistor/tran_1.html ).

We programmed the logic for the clock in Verilog on an Altera Cyclone IV (EP4CE6E22C8N).

If you are not familiar with Verilog, you can start here: http://wiki.opengraphics.org/tiki-index.php?page=Introduction+to+Verilog

My student, Alexandr Nigay, programming

The code is in three files:

1) SevenSegment_HHMMSS_WithButtons.v (link) contains the top-level module `SevenSegment_HHMMSS_WithButtons` and the module `FrequencyDivider_Mux` that takes a 50MHz clock signal of the FPGA and produces a square wave with the frequency of switching between the displays.

In our case it is approximately 1200Hz.

Each of our six seven-segment displays is lit for 1/1200 of a second, and then the signal switches to the next one.

Because of high frequency of multiplexing, it appears to the eye that all displays are lit all the time.

2) BCDto7Seg.v (link) contains the module `BCDto7Seg` that takes a 4-bit binary input signal corresponding to the numbers 0 – 9, and converts it to an 8-bit binary output signal that turns on LEDs for showing this number on a seven-segment display.

3) PushButtonDebouncer.v (link) contains the module `PushButtonDebouncer` that generates a pulse when a button is pressed.

As the raw input signal that you get by simply pressing a button is noisy, it should be cleaned before being used by the rest of the circuit.

The push-button output created by the `PushButtonDebouncer` module is glitch free and synchronous to the clock.

This is a screenshot of the pin planner in Altera Quartus II, where you can see the pin assignments.

***

Connecting the wires, compiling the code, programming the FPGA… and finally, it works!

Celebrating our success by eating oranges

So we had fun. Now we want to move from helloworlds to something more serious (or funnier, I don’t know)

Happy kids enjoying their electronic toys

Future plans for playing with the FPGA (tentative):

a) To do some cool digital signal processing.

c) To run some scientific computations on an FPGA 1000 times faster than on a laptop.

d) To write some cool parallel algorithms for cellular automata and see their beautiful animations on a computer screen.

e) Maybe some neural network… maybe to predict something… maybe the next global crisis…

….

z) To conquer the World 🙂