Skip to content

dungducphan/TM4C123-Clock2UART

Repository files navigation

β°πŸ”— Clock2UART: Microsecond Timestamp Logger for TM4C123 πŸš€βœ¨


✨ Overview

Welcome to Clock2UART! This project transforms your TM4C123 microcontroller into a high-precision event logger, outputting microsecond timestamps over UART every time a clock pulse is detected on PC4. Perfect for timing, debugging, and embedded experiments! πŸ˜ŽπŸ”¬


⚑ Features

  • πŸ•’ Microsecond Precision: Hardware timer maintains a 64-bit microsecond counter.
  • 🎯 Event Triggered: Each rising edge on PC4 sends the current timestamp over UART0.
  • πŸ“¨ UART Output: Timestamps are sent as ASCII decimal numbers, followed by CR+LF (\r\n) for easy logging or parsing.
  • πŸ’€ Minimal CPU Usage: All timing and event handling is interrupt-driven for efficiency.
  • πŸ–₯️ LCD Display: Real-time visualization of timestamps and trigger counts on a 2004A LCD.

πŸ› οΈ Hardware Requirements

  • πŸ§‘β€πŸ’» TI TM4C123 microcontroller (e.g., EK-TM4C123GXL LaunchPad)
  • ⏲️ External clock or signal source (0.01 Hz to 10Hz) connected to PC4
  • πŸ”Œ UART-to-USB adapter or onboard debugger for serial output
  • πŸ’‘ Optional: 2004A LCD module with PCF8574 I2C backpack for real-time display

🧩 Pinout

Pin Function Notes
🟒 PC4 Clock input (rising edge) Triggers timestamp output
🟑 PA0 UART0 RX Connect to serial monitor
🟠 PA1 UART0 TX Connect to serial monitor
🟣 PB2 I2C0 SCL Connect to LCD PCF8574 SCL
🟑 PB3 I2C0 SDA Connect to LCD PCF8574 SDA

🚦 Usage

  1. πŸ› οΈ Build and flash the firmware to your TM4C123 board.
  2. πŸ”— Connect your clock signal to PC4.
  3. πŸ–₯️ Open a serial terminal (115200 baud, 8N1, no flow control) on your PC.
  4. ⏱️ Watch the magic! Each rising edge on PC4 prints the current microsecond count on a new line.
  5. πŸ–₯️ Connect an LCD as per the hardware setup to view timestamps and trigger counts in real-time.

πŸ’‘ Tip: Use any serial terminal (e.g., PuTTY, Tera Term, minicom) to view the output.


πŸ“ Code Structure

  • clock2uart.c β€” Main application source. All initialization, interrupt handlers, and UART output routines.
  • startup_ccs.c β€” Startup and vector table (ensure the GPIOC interrupt points to GPIOCIntHandler).
  • clock2uart_ccs.cmd β€” Linker script for Code Composer Studio.

πŸ“œ License

MIT License. See the top of clock2uart.c for details.


πŸ‘¨β€πŸ’» Author

Dung Duc Phan, August 2025


Made with ❀️ for embedded developers and tinkerers everywhere! πŸ› οΈβœ¨

πŸ–₯️ New Feature: LCD Display

Overview

This feature adds support for displaying timestamps and trigger counts on a 2004A LCD module with a PCF8574 I2C controller. The LCD provides a real-time view of the microsecond counter and the number of rising edges detected on PC4. πŸŽ‰

Hardware Setup

  • LCD Module: 2004A with PCF8574 I2C backpack.
  • Connections:
    • PB2 (I2C0 SCL) -> SCL on PCF8574
    • PB3 (I2C0 SDA) -> SDA on PCF8574
    • Ensure the I2C address matches the default 0x27 or update the code if different.

Usage

  1. Connect the LCD module to the TM4C123 board as described above.
  2. Build and flash the firmware.
  3. Power on the system. The LCD will initialize and display:
    • The current microsecond counter value.
    • The total number of rising edges detected on PC4.

Note: The LCD backlight is enabled by default. Adjust the PCF8574_BL definition in the code to disable it if needed.


πŸ†• New Features

Enhanced UART Output

  • The firmware now prints both the timestamp and the trigger count to the UART. πŸ–¨οΈ
  • Example output:
    12345678 42 12345679 43 ... 

Reset Trigger Count via UART

  • The firmware can now receive a string via UART to reset the trigger count. πŸ”„
  • To reset the trigger count, send the string reset to the board.

🐍 Python Client

A Python client script (control_client.py) is included to interact with the firmware. This script allows you to:

  • Read UART Output: Continuously read and display data from the board. πŸ“‘
  • Send Commands: Send strings to the board, such as reset to reset the trigger count. πŸ–‹οΈ

Usage Instructions

  1. Install Python:

    • Ensure Python 3.x is installed on your system. 🐍
    • Install the pyserial library if not already installed:
      pip install pyserial 
  2. Run the Script:

    • Navigate to the PythonClient directory. πŸ“‚
    • Run the script:
      python control_client.py 
  3. Interact with the Board:

    • View the UART output in real-time. πŸ–₯️
    • Type reset to reset the trigger count or any other string to send it to the board. ✍️

πŸ’‘ Tip: Update the PORT variable in the script to match your board's COM port.

About

πŸš€ Easily log high-precision event timestamps from your TM4C123 microcontroller!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published