# Exercises - Part 1

{% hint style="warning" %}
In the following exercises, consider declaring the variables as follows.
{% endhint %}

<table><thead><tr><th width="157">Variable type</th><th width="121">Data type</th><th width="233">Variable declaration</th><th>Remarks</th></tr></thead><tbody><tr><td>Input, Output</td><td>Bool</td><td>xStart, xStop, xReset, xInput, xSensor, xInductiveSensor, xMotor, xSolenoid etc.</td><td></td></tr><tr><td>Value</td><td>Int or Int16</td><td>iCount, iLevel, iSpeed etc.</td><td></td></tr><tr><td>Value</td><td>DInt or Int32</td><td>diCount, diLevel, diOrderID etc.</td><td></td></tr><tr><td>Value</td><td>Real</td><td>rSpeed, rLevel, rHeight etc.</td><td></td></tr><tr><td>Name</td><td>String</td><td>sID, sRecipe, sPassword etc.</td><td></td></tr><tr><td>Parameter</td><td>Time</td><td>tDelay, tTimeout etc.</td><td></td></tr></tbody></table>

{% hint style="success" %}
**Solve the following exercises in the following programming languages:**\
\- Ladder Diagram\
\- FBD (Funcitonal Block Diagram)
{% endhint %}

## 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)        |
| :------------------------------------: | :------------------------------------: | :------------------------------------: |
|  <mark style="color:red;">FALSE</mark> |  <mark style="color:red;">FALSE</mark> |  <mark style="color:red;">FALSE</mark> |
|  <mark style="color:red;">FALSE</mark> | <mark style="color:green;">TRUE</mark> |  <mark style="color:red;">FALSE</mark> |
| <mark style="color:green;">TRUE</mark> |  <mark style="color:red;">FALSE</mark> |  <mark style="color:red;">FALSE</mark> |
| <mark style="color:green;">TRUE</mark> | <mark style="color:green;">TRUE</mark> | <mark style="color:green;">TRUE</mark> |

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

|          xStartA :BOOL (Input)         |          xStartB :BOOL (Input)         |        xOutputX : BOOL (Output)        |
| :------------------------------------: | :------------------------------------: | :------------------------------------: |
|  <mark style="color:red;">FALSE</mark> |  <mark style="color:red;">FALSE</mark> |  <mark style="color:red;">FALSE</mark> |
|  <mark style="color:red;">FALSE</mark> | <mark style="color:green;">TRUE</mark> | <mark style="color:green;">TRUE</mark> |
| <mark style="color:green;">TRUE</mark> |  <mark style="color:red;">FALSE</mark> | <mark style="color:green;">TRUE</mark> |
| <mark style="color:green;">TRUE</mark> | <mark style="color:green;">TRUE</mark> | <mark style="color:green;">TRUE</mark> |

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

|          xStartA :BOOL (Input)         |        xOutputX : BOOL (Output)        |
| :------------------------------------: | :------------------------------------: |
|  <mark style="color:red;">FALSE</mark> | <mark style="color:green;">TRUE</mark> |
| <mark style="color:green;">TRUE</mark> |  <mark style="color:red;">FALSE</mark> |

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

<table><thead><tr><th align="center">xStartA :BOOL (Input)</th><th width="251.33333333333331" align="center">xOutputX :BOOL (OUTPUT)</th><th align="center">xOutputY : BOOL (Output)</th></tr></thead><tbody><tr><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr><tr><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr></tbody></table>

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

<table><thead><tr><th align="center">xStartA :BOOL (Input)</th><th width="246.33333333333331" align="center">xOutputX :BOOL (OUTPUT)</th><th align="center">xOutputY : BOOL (Output)</th></tr></thead><tbody><tr><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr><tr><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr></tbody></table>

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

<table><thead><tr><th align="center">xStartA :BOOL (Input)</th><th width="246.33333333333331" align="center">xStartB :BOOL (Input)</th><th align="center">xOutputY : BOOL (Output)</th></tr></thead><tbody><tr><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr><tr><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr><tr><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr><tr><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr></tbody></table>

## 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.&#x20;
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.&#x20;
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

{% hint style="info" %}
TON: On-delay timer; TOF: Off-delay timer
{% endhint %}

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.&#x20;
3. Write a program if xStart (Input) is TRUE xMotor (Output) is TRUE for 10 seconds, then gets FALSE.&#x20;
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&#x20;

{% hint style="info" %}
EQ: Equal\
NE: Not equal\
LT: Less than\
LE: Less than or equals\
GT: Greater than\
GE: Greater or equals &#x20;
{% endhint %}

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.

<table><thead><tr><th align="center">Time (in seconds)</th><th width="163" align="center">bRed (Output)</th><th width="175" align="center">bOrange (Output)</th><th align="center">bGreen (Output)</th></tr></thead><tbody><tr><td align="center">0 ~ 10</td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr><tr><td align="center">11 ~ 12</td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td></tr><tr><td align="center">13 ~ 23 </td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr><tr><td align="center">24 ~ 25</td><td align="center"><mark style="color:red;">FALSE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td><td align="center"><mark style="color:green;">TRUE</mark></td></tr></tbody></table>

## Section 6- Use of Counters with Comparators&#x20;

{% hint style="info" %}
CTU: Count Up\
CTD: Count Down
{% endhint %}

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.&#x20;
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&#x20;

{% hint style="info" %}
ADD: Addition\
SUB: Subtraction\
MUL: Multiplication\
DIV: Division\
MOV: Move
{% endhint %}

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.

{% hint style="warning" %}
Use the Conversion command if necessary.
{% endhint %}

2. 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.&#x20;
3. Add a program to the solution of Exercise 7.2 to limit the minimum and maximum time to 1 second and 3 seconds, respectively.&#x20;
4. Write a program to blink the output xLamp with a delay of 1 second when xStart is TRUE.

## Section 8- Other operators&#x20;

{% hint style="info" %}
SEL: Bitwise selection\
MUX: Multiplexer\
LIMIT: Limit\
Conversion:&#x20;
{% endhint %}

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%. <mark style="color:red;">.</mark>
2. Use the operand LIMIT in exercise 7.3 to define the limits and realize the result.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.codeandcompile.com/factory-automation/plc/codesys/exercises-part-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
