STL – Tia Portal 14 – Start On Delay Timers

Hello everyone!

Today I’m presenting you to an example of how to use Start on delay timers in STL.

These two pdf sheets with the instructions of the STL may be of use for you:

Sheet 1– Sorted by category.

Sheet 2 – Sorted alphabetically.

However I would strongly recommend using F1 on your IDE to find out more about the particular function you want to use.

For my particular case and following the thread of the last post I’ve decided to model a tank with its respective High alarm, high warning, low warning and low alarm.

So, in STL how do I initialize a timer comparing values?

Let’s start by writing the High level alarm

We have must compare values, to do so we’ll use the function Load, L.

L #CV // We load the current value read from an analog input to the Accumulator 1.

L #HAlarmSP //We load the Set point when we’ll see an alarm to the accumulator 1, deplacing #CV to accumulator 2

>=R // We compare whether The accumulator 2 (#CV) is greater than the accumulator 1( #HAlarmSP) if this is true then the program continues its execution downwards.
L #AlarmDelay // We load the time to delay the alarm.
SD “TimerHAlarm” // We put the loaded time in the timer initializing it in case the condition mentioned above is true. (This has been declared in a TagList within the TIA Portal IDE.
A “TimerHAlarm” // This is the output of the timer (TMR.Q for those who use . notation)
= #HAlarm // This will be the bool that will be true once the time has elapsed.

So far, so good? I hope so, if not I’ll let the example I’ve programmed here.

And as an exercise I encourage you to program the rest of the code to get a High warning , Low warning  and Low alarm.

Here is the video of what I’ve programmed:

Plant Modeling (I) – Tanks

Hello everyone!

Somehow I miss being around tanks, pumps, sterilizers, filling machines, VSDs and so on. Because of the price of PLCs being that expensive I’m toying with arduino to simulate somehow a little plant and today we’re going to start by the tanks by using OOP in arduino and exchange data with the application I’ve developed for that very purpose in Visual C#.
Through this interface we’ll be able to:

  • Monitor the level of the tanks.
  • Receive the alarms and warnings of the tanks.
  • Establish the setpoints for giving either the alarms or the warnings.

The level of the tanks is controlled by two knobs which are the variable resistors that are wired to the analog inputs of the arduino board. It is needed yet some filtering of the signal, but I still have things that I don’t see clearly. Experimentally, supposedly saved values in an array changed, which may be because I had to pass values with their reference and so on but I was incapable of getting the result I wanted even using references and pointers the values still changed, I have to look into a bit else about this particular matter.

The code source of both, the arduino and the interface can be downloaded in the following links:

Arduino and interface source code:

Reading and writing in Arduino’s EEPROM with Visual C#

Hello everyone!

Today I have ended the interface with Visual C# to read and write the EEPROM of the Arduino. It has been funny, as using the methods of the Serialport in Visual C# seemed as though it added some characters to the stream of characters I was sending. I thought that maybe those ones were obviously constant and I decided to set a beginning ” : ” and an end “/” as sending the stream of characters, taking it into account in the arduino program.

I realized about this as sending the read command which I wanted it to be a simple 20. It would have been far easier sending a string or whatever but well, I’m stubborn sometimes and I wanted it to work in that way, just for the shake of the challenge and after some changes here it goes:

Visual C# code source:

Arduino code source:

Persistent variables and Arduino

Hi everyone!

Have you ever thought of storing some paraters in your arduino board? Maybe you have not even wonder about this, but after tuning a PID for example or after having set some time parameters, storing data sometimes is of the essence, not just for adjusting parameters but to store alarm signals that could precent a pump to start because of having suffered from high temperatura, the data also could be retrieved to a log text for maintenance or tracking some faults.

This is part of a series of posts where my aim is to interface with arduino through Visual C#, for now, if we are thinking of storing variables, a way to do it is through the EEPROM of Arduino.

Since you stop providing with energy to your arduino board I’m sure you’ve already noticed that your variables get their initial values. So what to do then?

You should include this library in your project:

#include <EEPROM.h>

And now, by simply using:

EEPROM.write(addr,dR); // you can write in your EEPROM to the address addr the data dR; // you can read from your arduino EEPROM from the address addr

For more information about the methods .write() or .read()

In my example I’ve written only in an address because my purpose is to write down parameters to the EEPROM to particular addresses from Visual C#. However, this could be changed from Visual C# itself.

The program can be downloaded here.

Automatic Block Signaling

Hello everyone!

What led me to publish this post is the following video:

As I could clearly see some arrays entailed I put myself to work to produce this with TwinCAT3, there is a bit of delay during the changing of the stage but this is due to the visualization refreshing time:

The project can be downloaded from this link:

Toying with the MPU6050

Hello everyone!

It has been long since I bought the MPU6050 I did some things and there are many to do yet but today I programmed something to control a unipolar stepper motor with a configuration of 5 wires using the ypr array of the MPU 6050 turning it accordingly to the movement of the sensor, here’s the video:

There are very few lines to do this. To begin with I started with the MPU6050 example to get the ypr array, then I defined these variables:

int k;
int memInt;
byte selector[8]={128,192,64,96,32,48,16,144};
int i;

128,192 and so on are the numbers for the sequence of the unipolar stepper motor with 5 wires.

The sequence is:

  1. 10000000 – 128
  2. 11000000 – 192
  3. 10010000 – 144.

This sequence (Selector maps to the PORTD outputs)

So in the setup() function will be writing this:


And about our loop() we’ll be adding this to the end of the code:

Movement of stepper unipolar motor

If we wanted to control the motor with the pitch the only thing to do is to replace the ypr[0] for ypr[1] and the same for using the roll (ypr[2]).

This array returns the values of Yaw Pitch and Roll of the MPU6050 module.

The TOF class for Arduino.

Hello everyone!

Today I’ll be presenting you to the TOF class. Using delay() is great but when things get more complex is far too better to use TON and TOF timers, chiefly because in the meantime your controller can do other things. However, as using delay, the controller gets like frozen so this is why I do not recommend the use of the delay function when programming things related to delays and so on.

First I would like you to see how is the working principle of this timer:


As you can see, as long as our IN condition is true the output of our TOF timer will be high as well (Q=true); Once the IN condition is false the output of our TOF timer will be maintained high for a period of time of PT.

There is another condition to pay attention to, in the second time that IN turns into true, if we turn to false the IN condition for a period of time lower than PT and we turn IN into true again the TOF timer will be somehow “rebooted” so as turning the IN to false again afterwards will be seeing Q as high during a period of time of PT (miliseconds, seconds or whatever our management in the interruption block).

The resulting TOF class is the following:


The rest of the code to make the the use of the class possible is described below:Rest_Of_TOFFThe video of the working principle with the two conditions:

From the following link you will be able to download the code of this program: