You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old September 2nd, 2009, 03:37 PM   #1
juzeko
Member
Croatia

juzeko is offline
 
Join Date: Jun 2008
Location: Vrbovec
Posts: 47
timer issue in simatic step 7

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?
  Reply With Quote
Old September 2nd, 2009, 04:22 PM   #2
bara_hence
Member
Sweden

bara_hence is offline
 
Join Date: Aug 2007
Location: Ockelbo
Posts: 217
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..
  Reply With Quote
Old September 3rd, 2009, 02:27 AM   #3
erdemsvri
Member
Germany

erdemsvri is offline
 
Join Date: Jul 2009
Location: Germany
Posts: 172
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...
  Reply With Quote
Old September 3rd, 2009, 03:36 AM   #4
Jeebs
Member
Belgium

Jeebs is offline
 
Join Date: Feb 2007
Location: Leuven
Posts: 1,033
Quote:
Originally Posted by erdemsvri View Post
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?
  Reply With Quote
Old September 3rd, 2009, 05:08 AM   #5
erdemsvri
Member
Germany

erdemsvri is offline
 
Join Date: Jul 2009
Location: Germany
Posts: 172
Quote:
Originally Posted by Jeebs View Post
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...
  Reply With Quote
Old September 3rd, 2009, 09:13 AM   #6
juzeko
Member
Croatia

juzeko is offline
 
Join Date: Jun 2008
Location: Vrbovec
Posts: 47
thx!
  Reply With Quote
Old September 5th, 2009, 11:53 AM   #7
juzeko
Member
Croatia

juzeko is offline
 
Join Date: Jun 2008
Location: Vrbovec
Posts: 47
Quote:
Originally Posted by Jeebs View Post
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?
  Reply With Quote
Old September 6th, 2009, 01:00 AM   #8
erdemsvri
Member
Germany

erdemsvri is offline
 
Join Date: Jul 2009
Location: Germany
Posts: 172
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...
  Reply With Quote
Old September 6th, 2009, 01:57 AM   #9
erdemsvri
Member
Germany

erdemsvri is offline
 
Join Date: Jul 2009
Location: Germany
Posts: 172
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
  Reply With Quote
Old September 6th, 2009, 04:21 AM   #10
juzeko
Member
Croatia

juzeko is offline
 
Join Date: Jun 2008
Location: Vrbovec
Posts: 47
Quote:
Originally Posted by erdemsvri View Post
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!
  Reply With Quote
Old September 6th, 2009, 07:27 PM   #11
juzeko
Member
Croatia

juzeko is offline
 
Join Date: Jun 2008
Location: Vrbovec
Posts: 47
Problem solved. I'm so newbie!
Thanks everyone for helping me.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
System Self Diagnostic and Fault Prevention Favorites. Hester LIVE PLC Questions And Answers 14 August 2nd, 2012 07:25 AM
Simatic Step 7 V5.3 Upgrade sparkysliderz LIVE PLC Questions And Answers 11 March 21st, 2005 04:12 AM
Siemens Simatic Step 7 (IL,FBD,LAD) ErikSBE LIVE PLC Questions And Answers 7 February 28th, 2005 04:52 AM
PLC control of stage lights Thesis LIVE PLC Questions And Answers 3 June 21st, 2004 09:44 PM
STEP 5 Refresh issue JustTroItIn LIVE PLC Questions And Answers 0 November 21st, 2003 08:09 AM


All times are GMT -5. The time now is 11:24 PM.


.