Simple program with one second delay

Hello! I want to make a simple program that turns on all the LEDs on a digital output with a delay of one second, but I’m having problems creating the delay, in the attached pictures I’ll show you how I tried to do it.



Here I tried to make a start loop only for DO1, but I get an error even on END_IF.

Hello, I had an issue similar to yours recently where I meant to add a structured text file but I added an automation basic file by mistake. It looks like yours is an Automation Basic file based on the error and green semicolons. The END_IF is structured text whereas ENDIF is used in Automation Basic.

Hello,

Here is an example you can use to understand how to use timers.
The program below will turn on LEDs with a delay of one second between each, assuming you have multiple LEDs connected to digital outputs.

//Declaration
VAR
    DO_1 : BOOL;
    DO_2 : BOOL;
    DO_3 : BOOL;

    timer_1 : TON;
    timer_2 : TON;
    timer_3 : TON;
END_VAR

PROGRAM _INIT
    //Set timers
    Timer_1(IN := NOT Timer_1.Q, PT := T#1s); // 1 second delay for LED1
    Timer_2(IN := Timer_1.Q AND NOT Timer_2.Q, PT := T#1s); // 1 second delay for LED2
    Timer_3(IN := Timer_2.Q AND NOT Timer_3.Q, PT := T#1s); // 1 second delay for LED3

    // Output
    IF Timer_1.Q THEN
        DO_1 := TRUE;
    END_IF;

    IF Timer_2.Q THEN
        DO_2 := TRUE;
    END_IF;

    IF Timer_3.Q THEN
        DO_3 := TRUE;
    END_IF;
PROGRAM _EXIT

You can adapt the program by adding more outputs (LEDs), and by changing the condition in the IN := … of the timer. You can change the time delay in the PT := …

For more details about TON() function, check B&R help → B&R Online Help (br-automation.com)

Best regards,
Mohammed Ali

I have error on the var.
image

The VAR part must not be part of your program! It’s the content of the .var file!

PROGRAM _INIT

DO_1 := FALSE;
DO_2 := FALSE;
DO_3 := FALSE;
DO_4 := FALSE;
DO_5 := FALSE;
DO_6 := FALSE;
DO_7 := FALSE;
DO_8 := FALSE;
DO_9 := FALSE;
DO_10 := FALSE;
DO_11 := FALSE;
DO_12 := FALSE;

END_PROGRAM

PROGRAM _CYCLIC

//Set timers
Timer_1(IN := NOT Timer_1.Q, PT := T#1s); // 1 second delay for LED1
Timer_2(IN := Timer_1.Q AND NOT Timer_2.Q, PT := T#1s); // 1 second delay for LED2
Timer_3(IN := Timer_2.Q AND NOT Timer_3.Q, PT := T#1s); // 1 second delay for LED3

// Output
IF Timer_1.Q THEN
	DO_1 := TRUE;
	ENDIF;

	IF Timer_2.Q THEN
		DO_2 := TRUE;
		ENDIF;

		IF Timer_3.Q THEN
			DO_3 := TRUE;
			ENDIF;

END_PROGRAM

PROGRAM _EXIT
// Cod pentru ie?ire
END_PROGRAM

You need to add the library standard to your project to be able to Build your program.
Take a look at this sample

Note : this program was made with StructuredText.

ledDelay.zip (55.7 KB)

your ENDIF looks like Automation Basic but the fb call like Structured Text. So which language do you prefer ?

find the syntax for AB here:
https://help.br-automation.com/#/en/4/libraries%2Fstandard%2Fsamples%2Fab%2Fex_ab_ton.html