Reliable delayed FOR loop

alex87
2013-05-27
2013-05-28
  • alex87 - 2013-05-27

    Hello!

    Can anyone share me/us the code for reliable delayed for loop. I'm trying with TON delayed CASE loop, but it is really painfull and not reliable. In my example I'm parametrizig CAN device over SDO protocol, with expedited SDO transfer. So i have eg. index 16#5000 and 20-25 subindexes. Every sub index have to be delayed and sent because of the SDO request-response protocol. My code snipet:

    ton_sdo_param(IN:= xTonStepEnable , PT:=T#3MS , Q=>xDelayStep , ET=> );

    CASE int1 OF
    19: xTonStepEnable:=TRUE;
    IF xDelayStep THEN
    int1:=20;
    END_IF

        20:   xTonStepEnable:=FALSE;
            windex:= 16#5000;
            bySubIndex:=bySubIndex+1;               
            xSDOEnable:=TRUE;
            IF bySubIndex=100 AND xSDOError1=FALSE THEN
                int1:=27;               
            ELSE int1:=21;
            END_IF
    
        21: IF xSDOError1=FALSE THEN
                int1:=19;
            ELSE int1:=22;
            END_IF
    
        22: xSDOEnable:=TRUE;       
            xErrorCounter:= xErrorCounter+1;
            IF xErrorCounter=10 THEN
                int1:=199;
                ELSE int1:=24;
            END_IF
    
        24:    IF   xSDOEnable=FALSE THEN
            int1:=22;
            END_IF
    

    END_CASE

    My task for this is 3ms. And I'll be happy to solve this with delayed FOR loop solution, based on buscyle time.

    Any ideas?

    regards,
    Alex

     
  • t.lundahl - 2013-05-28

    You have a timer as long as your scantime?

    Try 'xDelay := xDelay + 1;'

    If xDelay is '2' then it has made one more scan rotation.

    Check out GETSYSTEMTIME, usaully there is a systemtimer in u-seconds on the system.

    /TorbjΓΆrn

     

Log in to post a comment.