Q:

Learning Structured Text, function block to controll a "pusher"

I come from a background in PC-programming (VB/C# .Net and PHP) and am learning PLC programming in school. At a recent test we had we where to create a function block that would push an element of a production line and into a container. 
Now, that is pretty simple, so I have added an Alarm to my code if the "pusher" (for lack of a better word) that will activate if the maneuver is not complete within 10 seconds.
My problem is that the pusher goes into an Alarm state immediately and it seems to be rather buggy :( So any answer would give some direction of how to structure my code better, or figure out why it goes into an alarm so fast...
(* INIT *)
(* Drive the pusher back if its out on init *)

IF M8002 THEN
        SkyvTilbake := TRUE; (* My "Function"/Step to retract the pusher *)
        Ferdig := FALSE; (*Let other components know that the pushers operation has completed *)
        SkyverUtMotor := FALSE; (*This is the engine output for driving the pusher out *)
        SkyverInnMotor := FALSE; (* This is the engine output for driving the pusher in *)
END_IF;

(* "Aktiver" is a input to activate the pusher *)
IF Aktiver THEN
    SkyvTilbake := FALSE;
    SkyvUt := TRUE; (* My "Function"/Step" to push the pusher out *)
    Ferdig := FALSE;
END_IF;

(* Push out step *)
IF SkyvUt AND NOT SkyvTilbake  AND NOT Alarm  THEN
    TON_1(IN:= SkyvUt ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
    SkyverUtMotor := TRUE;

    (* When sensor out activates (input), retract the pusher *)
    IF SensorUte THEN
        SkyvUt := FALSE;
        SkyvTilbake := TRUE;    
        SkyverUtMotor := FALSE;
    END_IF;

(* retract the pusher as long as there are no alarms *)
ELSIF SkyvTilbake AND NOT Alarm THEN
    TON_2(IN:= SkyvTilbake  ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
    SkyverInnMotor := TRUE;

     (* When it reach the normal position, activate "Ferdig" *)
     IF SensorInne THEN 
            SkyverInnMotor := FALSE;
            SkyvTilbake := FALSE;
            Ferdig := TRUE;
    END_IF;
END_IF;

(* When the alarm activates, stop all the engines *)
IF Alarm THEN
    SkyverUtMotor := FALSE;
    SkyverInnMotor := FALSE;
END_IF;

(* RESET ALARM *)
IF Reset THEN
    Alarm := 0;
    SkyvTilbake := TRUE;
END_IF;

PS. The test was in the middle of december, but I'm looking to learn more about structured text and designing PLC programs. Also the code is designed in to run in a Mitsubishi FXCPU, and written in GX Works 2

A:

I don't see where you are actually setting the time duration for your timer ( PT:= AlarmTid ).
Also, as I am not familiar with Mitsubishi PLC's, do timers automatically reset? It looks like once your timer is on, it never turns off.
You nay also want to look into using 'CASE . . . WHERE', it tends to clean up the code.

