Skip to content

truong92cdv/VERILOG_tm1638_leds_and_keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vietnamese version here!

VERILOG_tm1638_leds_and_keys

Interfacing with the Led&Key module via the TM1638 IC

I. Author

II. Result

667182019075250538.mp4
  • The 7-segment LED simulates a time counter in the hh-mm-ss format.
  • The 8 LEDs in the top row have left and right shifting effects.
  • Pressing the buttons will turn off the corresponding 7-segment LED display.

III. Hardware

  • ZUBoard 1CG model XCZU1CG-1SBVA484E
  • Led&Key control module MDU1093 with integrated TM1638 IC.
  • Three signal lines: STB, CLK, DIO; power lines: VCC +5V and GND.

module Led&Key TM1638

IV. TM1638

Refer to the TM1638 Datasheet.

The TM1638 IC efficiently controls LEDs and scans keys using only three signal lines: STB, CLK, and DIO. Internally, the TM1638 has 16 8-bit registers, addressed from 00h to 0Fh.

There are three communication modes with TM1638:

  1. Data transmission with automatic address increment.
  2. Data transmission with a fixed address.
  3. Reading key scan data.

The required data transmission frames are as follows:

TM1638 3 transmission modes

Data is written to the TM1638 via the DIO pin on the rising edge of the CLK signal, and data is read from the TM1638 on the falling edge of the CLK signal.

Schematic diagram of the Led&Key TM1638 module:

TM1638_schematic

V. Source Code

  • Generates a 1 Hz (1s) clock from the 100 MHz clock of ZUBoard.
  • Displays 8 digits on the 7-segment LED in hh-mm-ss format. The counter increments on each rising edge of the 1Hz clock (1s).
  • The 7-segment LED in this project is of the common cathode type. The input is a 4-bit BCD digit, and the output is an 8-bit encoded signal for the LED segments DP, G, F, E, D, C, B, A.

This module creates the data transmission and reception frames for communication with TM1638. The rw flag indicates whether data is being sent or received.

The output CLK signal has a period of T(CLK) = 2^7 * 10 ns = 1.28 µs.

Testbench code

Waveform of tm1638_tb

waveform_tm1638_tb

The data transmission and reception process in the top module occurs as follows:

  1. Send command 0x42 to indicate readiness to receive key scan data.
  2. TM1638 sends 4 bytes of data. Decode to determine which key was pressed.
  3. Send command 0x40 to indicate readiness to transmit data, with automatic address increment mode.
  4. Send command 0xc0 to specify that the first register address is 00h.
  5. Send 16 bytes of data to write to the internal registers of TM1638, controlling the LEDs.
  6. Send command 0x8f to set the maximum display brightness.

Testbench code

Waveform of top_tb

waveform_top_tb

VI. References

  1. TM1638 Datasheet
  2. Module Led&Key TM1638 schematic
  3. TM1638 project - alangarf

About

Control leds and keys with TM1638 - Verilog

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published