TRIM5: Configuring a Power-Fail-Safe Trend Graph Guide

Karen Mitchell3 min read
Application NoteHMI ProgrammingOther Manufacturer
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A multi-day, scrollable trend on TRIM5 requires a custom history buffer and custom point rendering. The built-in real-time graph component does not provide the required retained-history display. Read the process variable over Modbus TCP/IP, sample it at a defined interval, store the samples in a circular buffer backed by nonvolatile memory, and redraw the selected time window from stored data.

Define the retention and storage model

Select the sampling interval and required retention period before allocating memory. Calculate the required capacity as N = retention period / sampling interval, rounding up to a whole sample. Include any timestamp or sequence metadata needed to reconstruct sample order after power restoration; the evidence does not define a timestamp format or record layout.

Function Supported implementation Design decision
Acquire data Read the variable through Modbus TCP/IP Choose the sampling interval
Retain history Circular buffer using EEPROM() Size records and buffer capacity
Render history Clear with clrscr; draw with PutPixel Map samples to screen coordinates
Navigate history Redraw a selected buffer window Define scroll position and window length

Implement acquisition and circular buffering

  1. Read the variable already available through Modbus TCP/IP when the sampling interval expires.
  2. Write the sample to the current EEPROM() buffer position.
  3. Advance the write position and wrap it to the start when it reaches the allocated capacity.
  4. Maintain enough persistent state to identify the newest sample and whether the buffer has wrapped.

The stated minimum implementation uses two counters, an EEPROM block, PutPixel, and clrscr. The exact roles and persistence of the two counters are not specified, so define them explicitly—for example, separate write-position and display-position state—then verify restoration after a power cycle.

Render and scroll the stored trend

Clear the plot area and draw the retained samples point by point with PutPixel. Convert each buffer position to an X coordinate and each measured value to a Y coordinate. Define the X-axis time window, Y-axis range, clipping behavior, and treatment of invalid samples before implementing the coordinate mapping. Scrolling changes the first displayed buffer position and triggers a redraw; it does not change the circular-buffer write position.

If scaling is required, apply it while converting stored values to display coordinates rather than altering the retained measurements. Draw the X and Y axes consistently with the active scale so the displayed time span and engineering-value range remain unambiguous.

Protect EEPROM life and verify recovery

Calculate EEPROM wear before commissioning. Use the documented endurance of the actual memory, the sampling interval, the number of physical locations used by the circular buffer, and every additional persistent write performed for counters or metadata. No endurance rating is supplied here, so a safe service life cannot be calculated without the device documentation. Avoid rewriting persistent indexes more often than the design requires.

Verify the completed implementation by filling and wrapping the buffer, scrolling across old and new samples, checking both axis scales, interrupting power, and confirming that sample order and the latest valid position recover correctly. Also confirm that the projected write count for every repeatedly written EEPROM location remains within the documented endurance for the required service life.

FAQ

Can the TRIM5 real-time graph retain several days of data?

The required retained, scrollable history is not provided by the real-time graph component described in the evidence. Implement a custom circular buffer with EEPROM() and render its samples with PutPixel.

How do I calculate the number of samples for a multi-day trend?

Use N = retention period / sampling interval and round up to a whole sample. Multiply that count by the complete stored-record size when determining the required memory capacity.

How do I prevent the TRIM5 EEPROM from wearing out?

Use a circular buffer to distribute sample writes, then calculate writes per physical location from the selected sampling interval and buffer size. Include writes to persistent counters or metadata and compare the result with the documented endurance of the actual memory.

Back to blog