Exercises - Part 1

Basic exercises on Codesys

In the following exercises, consider declaring the variables as follows.

Variable type
Data type
Variable declaration
Remarks

Input, Output

Bool

xStart, xStop, xReset, xInput, xSensor, xInductiveSensor, xMotor, xSolenoid etc.

Value

Int or Int16

iCount, iLevel, iSpeed etc.

Value

DInt or Int32

diCount, diLevel, diOrderID etc.

Value

Real

rSpeed, rLevel, rHeight etc.

Name

String

sID, sRecipe, sPassword etc.

Parameter

Time

tDelay, tTimeout etc.

Solve the following exercises in the following programming languages: - Ladder Diagram - FBD (Funcitonal Block Diagram)

Section 1 - Series & Parallel logics

  1. Write a program when bStart is TRUE, bMotor should be TRUE, and when bStart is False, bMotor should be FALSE.

  2. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xStartB :BOOL (Input)
xOutputX : BOOL (Output)

FALSE

FALSE

FALSE

FALSE

TRUE

FALSE

TRUE

FALSE

FALSE

TRUE

TRUE

TRUE

  1. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xStartB :BOOL (Input)
xOutputX : BOOL (Output)

FALSE

FALSE

FALSE

FALSE

TRUE

TRUE

TRUE

FALSE

TRUE

TRUE

TRUE

TRUE

  1. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xOutputX : BOOL (Output)

FALSE

TRUE

TRUE

FALSE

  1. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xOutputX :BOOL (OUTPUT)
xOutputY : BOOL (Output)

FALSE

TRUE

TRUE

TRUE

FALSE

FALSE

  1. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xOutputX :BOOL (OUTPUT)
xOutputY : BOOL (Output)

FALSE

TRUE

FALSE

TRUE

FALSE

TRUE

  1. Write a program to fulfill the following boolean table:

xStartA :BOOL (Input)
xStartB :BOOL (Input)
xOutputY : BOOL (Output)

FALSE

FALSE

FALSE

TRUE

FALSE

TRUE

FALSE

TRUE

TRUE

TRUE

TRUE

FALSE

Section 2 - Latching and Interlocking logics using contacts

  1. Write a program when xStart (Input) is pressed, xMotor (output) should be latched & when xStop is Pressed, xMotor (output) should be unlatched. In this case, consider xStart and xStop as NO Push Button.

  2. Write a program when xStart (Input) is pressed, xMotor (output) should be latched & when xStop is Pressed, xMotor (output) should be unlatched. In this case, consider xStart and xStop as NC Push Button.

  3. Write a program to interlock xSolenoidA (Output) and xSolenoidB (output). - When xStartA (Input) is pressed, xSolenoidA (output) should be latched, and xSolenoidB should be unlatched - When xStartB (Input) is pressed, xSolenoidB (output) should be latched, and xSolenoidA should be unlatched - When xStop (Input) is pressed, both solenoids should be unlatched Consider xStartA, xStartB as NO push button, and xStop as NC Push Button.

Section 3 - RS and SR flip-flops

  1. Using RS flipflop write a program when xStart (Input) is pressed, xMotor (output) should be latched & when xStop is Pressed, xMotor (output) should be unlatched.

  2. Using SR flipflop write a program when xStart (Input) is pressed, xMotor (output) should be latched & when xStop is Pressed, xMotor (output) should be unlatched.

  3. Realize the difference in operations when both the inputs xStart and xStop are TRUE. Which type of flipflop should be used ideally in this situation?

Section 4- Use of Timers

TON: On-delay timer; TOF: Off-delay timer

  1. Write a program such that when xStart (Input) is TRUE, xMotor (Output) gets TRUE after a delay of 5 secs. When xStart is FALSE, xMotor should be FALSE.

  2. Write a program when xStart (Input) is TRUE, xMotorA (Output) gets TRUE after 3 seconds delay, and then after a delay of 3 more seconds, xMotorB (Output) should get TRUE & after a delay of 3 more seconds, xMotorC (Output) should get TRUE.

  3. Write a program if xStart (Input) is TRUE xMotor (Output) is TRUE for 10 seconds, then gets FALSE.

  4. Write a program such that: - xStart (Input) latches xMotorA (Output) - After a delay of 10 seconds, xMotorB (Output) latches - xStop (Input) unlatches xMotorA - After a delay of 10 seconds, xMotorB should get unlatched.

  5. Write a program in which xMotorA (Output) latches only when xStartB (Input) is TRUE within 10 seconds just after the xStartA (Input) gets TRUE. Otherwise, if xStartB is TRUE after 10 seconds, nothing should happen. Unlatch xMotorA when xStartA is FALSE.

Section 5- Use of Timers with Comparators

EQ: Equal NE: Not equal LT: Less than LE: Less than or equals GT: Greater than GE: Greater or equals

  1. Use one push button xStart (Input) actuate xMotor (Output) in the following sequence: xMotor is TRUE for 2 seconds, then FALSE for 2 seconds, then TRUE for 3 seconds, then continuously FALSE.

  2. Use xStartA (Input) to blink xLamp (Output) such that the On-time is 0.5 seconds and Off-time is 1 second.

  3. Write a program such that: - When xStartA (Input) is TRUE, xLampA (Output) and xLampB should blink continuously with a delay of 1 second. - When xStartB (Input) is TRUE, xLampA (Output) and xLampB should blink continuously with a delay of 2 seconds.

  4. Write a simple traffic light program to fulfill the following conditions. The Timer should reset, and the cycle should repeat when the time is above 25 seconds.

Time (in seconds)
bRed (Output)
bOrange (Output)
bGreen (Output)

0 ~ 10

TRUE

FALSE

FALSE

11 ~ 12

TRUE

TRUE

FALSE

13 ~ 23

FALSE

FALSE

TRUE

24 ~ 25

FALSE

TRUE

TRUE

Section 6- Use of Counters with Comparators

CTU: Count Up CTD: Count Down

  1. Write a program such that when xStart is pressed three times, xOutput should get TRUE. And when xReset is TRUE once, the xOutput should be FALSE, and the counter should RESET.

  2. Write a program to fulfill the following conditions: - When xStart is pressed once -xOutputA should be TRUE, xOutputB and xOutputC should be FALSE - When xStart is pressed again -xOutputB should be TRUE, xOutputA and xOutputC should be FALSE - When xStart is pressed again -xOutputC should be TRUE, xOutputA and xOutputB should be FALSE - When xStart is pressed again - all the outputs should be FALSE, and the cycle should repeat itself

Section 7- Use of variables with Math Operators

ADD: Addition SUB: Subtraction MUL: Multiplication DIV: Division MOV: Move

  1. Write a program to fulfill the following conditions: - xStart (Input) should latch the lamp xLamp (output) after five seconds delay. - xStop (Input) should unlatch the xLamp - Use xTimeA (Input) to change the delay time to 10 seconds. - Use xTimeB (Input) to change the delay time to 5 seconds.

Use the Conversion command if necessary.

  1. Write the same program as the above but instead of moving the constant time of 5 and 10 seconds. Use xInc (Input) to increment the time by 100ms and xDec (Input) to decrement the time by 100ms.

  2. Add a program to the solution of Exercise 7.2 to limit the minimum and maximum time to 1 second and 3 seconds, respectively.

  3. Write a program to blink the output xLamp with a delay of 1 second when xStart is TRUE.

Section 8- Other operators

SEL: Bitwise selection MUX: Multiplexer LIMIT: Limit Conversion:

  1. Write a program using SEL such that the xAlarm (Output) should be TRUE if the iLevel (variable) is more than 80%. Take iLevel as an integer with the range of 0 to 100%. .

  2. Use the operand LIMIT in exercise 7.3 to define the limits and realize the result.

Last updated