timer issue in simatic step 7

juzeko

Member
Join Date
Jun 2008
Location
Vrbovec
Posts
47
Hello

I'm programming something in STEP 7 package for S7-300 PLC and I'm having some problems with timers. One of my function blocks (written in SCL) has to calculate one REAL variable and then put that result as initial value (specify runtime) in timer.

runtime is in S5TIME format and my variable is REAL

e.g. my variable is calculated as 7.41 (means seconds)

and I need to put those 7410 miliseconds as the initial value in timer and then in every cycle multiply new value of timer with
a constant and sending that as an output.

e.g.
1st cycle
-value of the TIMER is 7410 miliseconds
-output is = const*7.41

2nd cycle
-value of the TIMER is 7400 miliseconds
-output is = const*7.40

3rd cycle
-value of the TIMER is 7390 miliseconds
-output is = const*7.39

(so, I also have to put somehow "time base" bits in "00" (for 10 ms timebase)).

Can You please give me some instructions how to do that?
 
If possible use SFB4 -- TON instead..

Then you could use a real and if you have 7,41 for 7s 410ms then just


time_for_timer:=dint_to_time(real_to_dint(your calculated real*1000));

If it isnt possible using a SFB4 TON then you could do as i say anyways and then use the SFC that converts time to s5time wich you could find in standard library -- iec i think..
 
First you should look at the S5-Time consept :

not used | time format | timer content

2 bits | 2 bits | 12 bits
00 xx xxxxxxxxxxxx (BCD)

So you should change the real type to word because S5 timer is in word format:

I think this STL code will give you better idea:

L Timer_Real /real format
L 1000
*R
RND
T Timer_Word / word format

L Timer_Word
ITB
AW W#16#0FFF
T_Timer_S5_Time / s5_time format in ms...

you can easily do this with STL if you want to go on with the SCL later on. Write this function in STL and call it in SCL...
 
L Timer_Real /real format
L 1000
*R
RND
T Timer_Word / word format

L Timer_Word
ITB
AW W#16#0FFF
T_Timer_S5_Time / s5_time format in ms...

Correct me if I'm wrong, but won't that give him a value of 410 for T_Timer_S5_Time??
And isn't the lowest resolution of the S5timers 10ms?
Thus you should devide by 100, not 1000.

I have to ask, are you intending to change the initial value of the timer 'on-the-fly' or are you going to set the initial value once, then use the actual timer value during the cycles?
 
Correct me if I'm wrong, but won't that give him a value of 410 for T_Timer_S5_Time??
And isn't the lowest resolution of the S5timers 10ms?
Thus you should devide by 100, not 1000.

I have to ask, are you intending to change the initial value of the timer 'on-the-fly' or are you going to set the initial value once, then use the actual timer value during the cycles?


Yes you are right. I just typed wrong...

Should be:


L Timer_Real /real format
L 100
*R
RND
T Timer_Word / word format

L Timer_Word
ITB
AW W#16#0FFF
T_Timer_S5_Time / s5_time format in ms...
 
I have to ask, are you intending to change the initial value of the timer 'on-the-fly' or are you going to set the initial value once, then use the actual timer value during the cycles?

I am going to to set the initial value once and then use the actual value during cycles.

After I did everything you said, it goes:

bcdvalue:= S_PULSE(T_NO := T10,
S:=0,
TV:=initialvalue,
R:=0,
BI:=binvalue,
Q:=status);


bcdvalue:= S_PULSE(T_NO := T10,
S:=1,
TV:=initialvalue,
R:=0,
BI:=binvalue,
Q:=status);

When I run the program, I can see next in the variable table:

T10 is moving from 2s 700ms to 0,
initial value is W#16#0270 //(BCD)
Q is true
binvalue is W#16#010E // which is binary for 270
bcdvalue is W#16#0270

If binvalue stands for "time remaining (binary)" in manual, why it doesn't change every cycle, why is allways W#16#010E?
 
Hi

Now I understand what you are trying to accomplish ,it is easier than I thought.

First of all 0 and 1 in SCL are regarded as type of int as far as I know for boolean type you should use TRUE or FALSE

And your code wont work because a PLC program runs in cycles which you first reset you timer and set your timer each cycle so your timer never counts anything and bcd value is the same...

So you should use a bit type in the S of the timer and you should change its value from 0 to 1 or 1 to 0 in runtime and bcdvalue is your timer output which gives you the remaining time as you wanted in BCD format. You can convert it to int to see the time remaining easier...
 
Here is a code working

TIME_REMAIN gives you the time remaingn in base of 10ms like for 7s it gives 700 and each 10ms it counts down...:


FUNCTION FC2 :VOID

VAR_INPUT
TIMER_NO:TIMER;
START:BOOL;
TIMER_VALUE:S5TIME;
RESET:BOOL;
END_VAR

VAR_OUTPUT
TIME_REMAIN:INT;
TIMER_STATUS:BOOL;
END_VAR

VAR_TEMP
T:S5TIME;
BIN_VAL:WORD;

END_VAR
BEGIN

T:= S_PULSE(T_NO := TIMER_NO,
S:=START,
TV:=TIMER_VALUE,
R:=RESET,
BI:=BIN_VAL,
Q:=TIMER_STATUS);

TIME_REMAIN := WORD_TO_INT(BIN_VAL);


END_FUNCTION

You triger the timer with the START input, reset it with RESET
and TIMER_STATUS gives you it is working or not...

Take care
 
And your code wont work because a PLC program runs in cycles which you first reset you timer and set your timer each cycle so your timer never counts anything and bcd value is the same...

Actually, it doesn't. Sorry for my lousy explanation of the problem - I don't reset and set my timer each cycle, because that part is under IF condition.
And IF condition is FALSE until timer reaches 0.
When timer reaches 0, then IF becomes TRUE and program sets the new timer value and again starts the timer.

I still can't realize what is wrong with my code, but I'll try it your way when I reach the office in 2 hours.

Thank you!
 

Similar Topics

So I'm assuming this is a rounding issue somewhere, but I don't know for sure so I figured someone else would. Made an AOI that just gives me a...
Replies
12
Views
3,931
dear friend, I am working on project where i have used two timer one for actual counting and other is for the display meaning. i am displaying...
Replies
3
Views
2,330
Hi! I have a strange problem I can't come up with a solution to. I have a TONR in my program set at 7 minutes. When the timer reaches 7 minutes...
Replies
7
Views
2,315
I am programming a Mitsubishi fx3u-48m PLC. I am trying to move different times into my timers. how would I go about doing this.
Replies
4
Views
1,550
A few days ago I got a callout to a customer that has a Mollers Stretch hooding machine. After the stretch hooder is a weigh check station after...
Replies
8
Views
1,948
Back
Top Bottom