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 December 29th, 2017, 06:09 AM   #1
dezuiper
Member
Belgium

dezuiper is offline
 
Join Date: Dec 2017
Location: Belgium
Posts: 6
TWINCAT V3 : timers in function block

Hi,

I have just started programming in TWINCAT to get some experience in structured text. I have just finished my first function block but I have hit a problem. My timers do not count inside a function block. What am I doing wrong?


The block is manipulated via a visualization.

Code:
PROGRAM MAIN
VAR
    myValve : FB_PNUEMATICVALVE;
    setOpen : BOOL;
END_VAR


myValve(bSetOpen:=setOpen);
Code:
FUNCTION_BLOCK FB_PNUEMATICVALVE
VAR_INPUT
    bSetOpen : BOOL := FALSE;
END_VAR
VAR_OUTPUT
    uiWarning : UINT := 0; //b1: valve sensor error
    bIsOpen : BOOL := FALSE;
END_VAR
VAR
    fbTimerValve : TON;
    fbTimerFeedBack : TON;
    
    usiState : USINT := 0;
    usiLoopAttempts : USINT := 0;
    
    bSensorOpen : BOOL := FALSE;
    bSensorClosed : BOOL := TRUE;
    
    bValve : BOOL := FALSE;
    bFeedBack : BOOL := FALSE;
    
END_VAR


CASE usiState OF
    0: // STATIC
        IF bSetOpen <> bIsOpen THEN
            fbTimerValve(IN:=TRUE, PT:=T#100S);
            
            //fbTimerFeedBack(IN:=TRUE, PT:=T#50S);
            
            usiState := 10;
            bValve := bSetOpen;
        END_IF 
    10: // MOVING
        IF fbTimerValve.Q THEN
            fbTimerValve(IN:=FALSE);
            IF bSensorOpen OR bSensorClosed THEN
                uiWarning := uiWarning OR E_BIT_MASKS.b1;
            ELSE
                uiWarning := uiWarning OR E_BIT_MASKS.b2;
            END_IF
            usiState := 20;
            RETURN;
        END_IF
            
        IF fbTimerFeedBack.Q THEN
            fbTimerFeedBack(IN:=FALSE);
            uiWarning := uiWarning OR E_BIT_MASKS.b5;
            usiState := 30;
            RETURN;
        END_IF;
    
        IF (bSensorClosed AND NOT bSetOpen) OR (bSensorOpen AND bSetOpen) THEN
            fbTimerValve(IN:=FALSE);
            
            fbTimerFeedBack(IN:=FALSE);
            usiState := 0;
            bIsOpen := bValve;
        END_IF
        
        IF bFeedBack = bValve THEN
            fbTimerFeedBack(IN:=FALSE);
        END_IF
    
    20: //ERROR, try looping
        
    
    30: //Crititcal ERROR, do nothing
        
END_CASE
  Reply With Quote
Old December 29th, 2017, 06:34 AM   #2
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,568
The is no call to fbTimerValve in state 10 to allow the timer to timeout.
  Reply With Quote
Old December 29th, 2017, 06:52 AM   #3
dezuiper
Member
Belgium

dezuiper is offline
 
Join Date: Dec 2017
Location: Belgium
Posts: 6
Is this the proper way to handle timers?

Code:
fbTimerValve();
fbTimerFeedBack();

CASE usiState OF
    
    0: // STATIC
        IF bSetOpen <> bIsOpen THEN
            fbTimerValve(IN:=TRUE, PT:=T#100S);
            fbTimerFeedBack(IN:=TRUE, PT:=T#50S);
            
            usiState := 10;
            bValve := bSetOpen;
        END_IF 
    10: // MOVING
        IF fbTimerValve.Q THEN
            fbTimerValve(IN:=FALSE);
            IF bSensorOpen OR bSensorClosed THEN
                uiWarning := uiWarning OR E_BIT_MASKS.b1;
            ELSE
                uiWarning := uiWarning OR E_BIT_MASKS.b2;
            END_IF
            usiState := 20;
            RETURN;
        END_IF
            
        IF fbTimerFeedBack.Q THEN
            fbTimerFeedBack(IN:=FALSE);
            uiWarning := uiWarning OR E_BIT_MASKS.b5;
            usiState := 30;
            RETURN;
        END_IF;
    
        IF (bSensorClosed AND NOT bSetOpen) OR (bSensorOpen AND bSetOpen) THEN
            fbTimerValve(IN:=FALSE);
            fbTimerFeedBack(IN:=FALSE);

            usiState := 0;
            bIsOpen := bValve;
        END_IF
        
        IF bFeedBack = bValve THEN
            fbTimerFeedBack(IN:=FALSE);
        END_IF
    
    20: //ERROR, try looping
        
    
    30: //Crititcal ERROR, do nothing
        
END_CASE
  Reply With Quote
Old December 29th, 2017, 08:13 AM   #4
kolyur
Lifetime Supporting Member + Moderator
United States

kolyur is offline
 
kolyur's Avatar
 
Join Date: Oct 2004
Location: Wooster, Ohio
Posts: 1,409
You have the calls to the timers on the outside of the Case statement, which is correct--they need to run every scan. The preset value can be specified in the call since it never changes. You shouldn't try to re-execute the timer inside the Case; instead just change the IN parameter to enable or disable the timer.

Code:
fbTimerValve(PT:=T#100S);
fbTimerFeedBack(PT:=T#50S);

CASE usiState OF
    
    0: // STATIC
        IF bSetOpen <> bIsOpen THEN
            fbTimerValve.IN:=TRUE;
            fbTimerFeedBack.IN:=TRUE;
            
            usiState := 10;
            bValve := bSetOpen;
        END_IF 
    10: // MOVING
        IF fbTimerValve.Q THEN
            fbTimerValve.IN:=FALSE;
            IF bSensorOpen OR bSensorClosed THEN
                uiWarning := uiWarning OR E_BIT_MASKS.b1;
            ELSE
                uiWarning := uiWarning OR E_BIT_MASKS.b2;
            END_IF
            usiState := 20;
            RETURN;
        END_IF
            
        IF fbTimerFeedBack.Q THEN
            fbTimerFeedBack.IN:=FALSE;
            uiWarning := uiWarning OR E_BIT_MASKS.b5;
            usiState := 30;
            RETURN;
        END_IF;
    
        IF (bSensorClosed AND NOT bSetOpen) OR (bSensorOpen AND bSetOpen) THEN
            fbTimerValve.IN:=FALSE;
            fbTimerFeedBack.IN:=FALSE;

            usiState := 0;
            bIsOpen := bValve;
        END_IF
        
        IF bFeedBack = bValve THEN
            fbTimerFeedBack.IN:=FALSE;
        END_IF
    
    20: //ERROR, try looping
        
    
    30: //Crititcal ERROR, do nothing
        
END_CASE
__________________
John
  Reply With Quote
Old December 30th, 2017, 04:17 PM   #5
paraffin power
Member
England

paraffin power is offline
 
paraffin power's Avatar
 
Join Date: Aug 2002
Location: Manchester
Posts: 470
I put TON in CASE statements like this..
Code:
Case Seq OF
    10:
    IF fbMyTimer.Q THEN //advance
        Seq := 20;
    END_IF;

    fbMyTimer(
              IN := <Your Condition> AND (Seq = 10),
              PT := T#2s
              );

    20:
    //next step....
This keeps everything to do with the timer in one place.
Putting the (Seq = 10) clause in tidies up behind itself.
I also use ENUMs for the Sequencer rather than an INT type variable, but that doesn't change the functionality.
Pp
__________________
Whatever hits the fan will not be evenly distributed.

Last edited by paraffin power; December 30th, 2017 at 04:19 PM.
  Reply With Quote
Old January 4th, 2018, 02:16 PM   #6
shooter
Member
Netherlands

shooter is offline
 
shooter's Avatar
 
Join Date: Sep 2002
Location: duketown
Posts: 2,653
Be sure the timers are running, outside of any case, as they have to be called to see if the time is elapsed.
__________________
shooter@home.nl
skype shooter paul.deelen
Computer Shooter
Paul Deelen
J. Wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
+31653300739
  Reply With Quote
Old January 4th, 2018, 02:17 PM   #7
shooter
Member
Netherlands

shooter is offline
 
shooter's Avatar
 
Join Date: Sep 2002
Location: duketown
Posts: 2,653
and call them only one time to start.
__________________
shooter@home.nl
skype shooter paul.deelen
Computer Shooter
Paul Deelen
J. Wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
+31653300739
  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
Function Block Memory Allocation in Omron CJ1M PLC scrambled LIVE PLC Questions And Answers 0 September 1st, 2015 10:50 PM
"Function block call requires a function instance" when calling action in Codesys standeven LIVE PLC Questions And Answers 9 April 27th, 2015 05:11 AM
TWINCAT make function block persistent nachovr LIVE PLC Questions And Answers 4 August 22nd, 2014 06:34 AM
RS5000 function block g7283jl LIVE PLC Questions And Answers 9 October 24th, 2012 11:12 PM
how to assign a data block to function block usman LIVE PLC Questions And Answers 4 April 13th, 2009 10:55 AM


All times are GMT -5. The time now is 12:08 AM.


.