Explainer
Why a CODESYS TIME value shows as a STRING in EasyBuilder Pro
Short answer
An EasyBuilder Pro ASCII object displays text only, so a CODESYS TIME value has to become a STRING in the PLC program first: convert it with TO_STRING(), cut the characters you do not want with MID(), and map the trimmed STRING to the ASCII object. For a clock-style countdown under a day, converting the value to a time of day first gives fixed-width text that one MID call reduces to hours, minutes, seconds and milliseconds.

On this page
An EasyBuilder Pro ASCII object reads characters, not IEC datatypes, so a CODESYS TIME value will not appear on it until the PLC program has converted that value to a STRING. The path is short: convert the TIME variable with TO_STRING(), cut the characters you do not want with MID(), and map the finished STRING to an ASCII object. The worked setup here is a cMT3162X project in EasyBuilder Pro 6.08.02.322, with a TON or a TOF in the CODESYS program producing the countdown; the cMT3162X datasheet lists the model in EasyBuilder Pro V6.04.01 or later and names V6.07.02 as the minimum software requirement, so that project version sits above both.
Why the panel cannot show TIME as-is #
A TIME value in an IEC 61131-3 program is a duration counted in milliseconds. The driver between the CODESYS controller and the panel does not convert datatypes; it reads memory as words or as characters. Map the TIME variable to a numeric object and the screen shows the raw millisecond count. Map the same words to an ASCII object without converting first and the object reads them as characters, which is how a timer turns into symbols on the screen. Nothing on the HMI side knows the datatype, so the type-to-text conversion has to run where the datatype exists: in the CODESYS application.
Convert the value in the PLC program #
Declare the countdown and a STRING that will carry its text, then apply TO_STRING() to the TIME variable and store the result. The names in the snippet are illustrative; TO_STRING is the documented Standard library conversion.
VAR
tRemaining : TIME := T#0ms; // the countdown value, for example preset minus elapsed
sRaw : STRING := ''; // the text TO_STRING writes
END_VAR
sRaw := TO_STRING(tRemaining);
Expect the type's literal notation back: a type marker at the front and a length that changes with the value. That is why a trim step exists, and why the cut is measured on the live string rather than guessed.
Cut the text with MID #
MID is the Standard library string function for the job. Its documented signature is MID(STR, LEN, POS): it returns LEN characters of the string STR beginning at position POS, and positions count the first character as 1. Two counts decide the call:
- the characters to drop at the front, call that p
- the characters to keep, call that k
POS is p + 1 and LEN is k. As an illustration, if the raw text opens with a 2-character type marker and the useful text is the next 9 characters, the call is MID(sRaw, 9, 3), because 2 + 1 = 3. Those figures are a worked illustration, not a recipe; the count on your live string sets them.
A fixed-width readout through TOD #
For a countdown that finishes inside one day there is a cleaner route: copy the TIME value into a TOD first, then convert. TO_STRING applied to a TOD writes the time-of-day literal, TOD#hh:mm:ss.mmm, always the same width, so one MID call stays valid at every value the countdown reaches. CODESYS holds TIME and TOD as millisecond counts, so the copy between them is one conversion from the project's standard function set.
The literal is 16 characters: 4 for TOD#, 8 for hours, minutes and seconds, 4 for the milliseconds, and 4 + 8 + 4 = 16. Keep everything after the prefix: LEN is 16 - 4 = 12 and POS is 4 + 1 = 5, so the call is MID(sRaw, 12, 5).
Worked example: the process has 1 minute 23.456 seconds left. As a TIME that is 60,000 + 23,000 + 456 = 83,456 ms. Through TOD the string reads TOD#00:01:23.456; the first kept character sits at position 4 + 1 = 5, the last at 5 + 12 - 1 = 16, and the panel shows 00:01:23.456.
A TOD is a time of day, so it wraps after 24 hours; a countdown that can run past a day takes the plain TO_STRING route on the TIME value instead.
Map the STRING to the ASCII object #
In EasyBuilder Pro, place an ASCII object on the screen and point its address at the trimmed STRING variable through the same controller driver the project already uses for the timer's other tags. The object draws whatever characters the driver finds at that address, so the mapped read length must cover the trimmed text and its terminator; the fixed-width readout fills its width at every value, which makes it easy to size. Map the trimmed variable rather than the raw conversion, so only checked text reaches the operating screen.
Prove the result on line #
Run the TON or TOF sequence and watch three points at once: the TIME variable in the CODESYS watch window, the STRING beside it, and the panel. The string must change as the timer runs. The first kept character must be the one you meant to keep, because a cut one position early lets the prefix's last character through and one position late eats the first digit; the last kept character must not be chopped.
This article covers the datatype conversion only. Producing the countdown value, preset minus accumulated, is covered in how to display a time-until-closed countdown on an HMI, and choosing what a timer shows while it starts and stops is the subject of PLC timer value on an HMI: start, stop and show after a win.
Decision: for a countdown that finishes inside one day, take the TOD route with MID(sRaw, 12, 5); for a longer duration or a duration-style readout, take TO_STRING on the TIME value and set the cut from the count on the live string.
Questions asked
Does MID return exactly the characters I ask for?
The Standard library documents the return type of MID as STRING(255). Declare the variable that receives the result as STRING in the CODESYS program and assign the result directly; the function writes the requested characters into that variable, and the panel reads it through the mapped address.
Why does the countdown on the panel advance in visible steps?
The ASCII object redraws when the driver polls its address, so the text advances once per polling cycle of that connection, not once per PLC scan. The conversion in the controller runs every scan; what you see is the sampling. If the steps look coarse, the polling cycle configured for the mapped address is the number to shorten.
Can more than one screen show the same converted STRING?
Yes. Point every ASCII object that shows the countdown at the same trimmed STRING; each object reads the same mapped characters, so one conversion in the PLC program feeds every screen. Convert and trim once per scan rather than once per screen, and the readouts cannot disagree.
How do I measure the cut for the plain TO_STRING text?
Watch the STRING variable online in the CODESYS development environment while the timer runs, or map it to a temporary ASCII object on a test screen. At a typical countdown value, count the characters to drop at the front and at the back; POS is the front cut plus one and LEN is the number kept. Re-check the count near zero and near the full preset, where the text is shortest and longest, before the MID call goes live.
Does the fixed-width cut survive small countdown values?
Yes. The time-of-day literal always fills its fields with zeros, so a five-second remainder still reads 00:00:05.000 and the same MID call returns the whole readout. That zero-padded width is the reason to prefer the time-of-day route for a clock-style display: one cut stays valid from the full preset down to zero.


