📖 Scenario: You are programming a simple machine that counts down from a starting number to zero. This is useful in factories to track how many items are left to process.
🎯 Goal: Build a count-down counter (CTD) program that starts from a preset value and decreases the count each time a button is pressed until it reaches zero.
📋 What You'll Learn
Create a variable called preset_value with the starting count.
Create a variable called current_count initialized to preset_value.
Create a variable called button_pressed to simulate the button input.
Write logic to decrease current_count by 1 each time button_pressed is True and current_count is greater than zero.
Print the current_count after each button press.
💡 Why This Matters
🌍 Real World
Count-down counters are used in machines to track how many items remain to be processed or produced.
💼 Career
Understanding count-down counters is important for programming industrial controllers and automation systems.
Progress0 / 4 steps
1
Set up the initial count variables
Create a variable called preset_value and set it to 10. Then create a variable called current_count and set it equal to preset_value.
PLC Programming
Hint
Think of preset_value as the starting number on the counter. current_count should start the same as preset_value.
2
Add the button press simulation variable
Create a variable called button_pressed and set it to True to simulate the button being pressed.
PLC Programming
Hint
This variable will act like the button being pressed to count down.
3
Write the count-down logic
Write an if statement that checks if button_pressed is True and current_count is greater than zero. Inside the if, decrease current_count by 1.
PLC Programming
Hint
Use and to check both conditions before subtracting.
4
Display the current count
Write a print statement to display the value of current_count.
PLC Programming
Hint
Use print(current_count) to show the count after the button press.
Practice
(1/5)
1. What does a Count-down counter (CTD) do in a PLC program?
easy
A. It resets the count value to zero automatically.
B. It increases a count value each time an input signal is active.
C. It decreases a count value each time an input signal is active.
D. It counts the number of times a timer has finished.
Solution
Step 1: Understand CTD basic function
A Count-down counter decreases its count value when triggered by an input signal.
Step 2: Compare options with CTD behavior
Only It decreases a count value each time an input signal is active. describes decreasing the count on input signal activation, matching CTD behavior.
Final Answer:
It decreases a count value each time an input signal is active. -> Option C
Quick Check:
CTD decreases count on input = C [OK]
Hint: CTD always counts down, not up or reset automatically [OK]
Common Mistakes:
Confusing CTD with count-up counter
Thinking CTD resets count automatically
Assuming CTD counts timer completions
2. Which of the following is the correct syntax to declare a CTD counter named CTD1 with a preset value of 10 in a typical PLC program?
easy
A. CTD1.CNT := 10;
B. CTD1.PV = 10;
C. CTD1.PRESET = 10;
D. CTD1.PRE := 10;
Solution
Step 1: Identify correct preset syntax
In PLCs, the preset value for counters is often set with the .PRE property using := for assignment.
Step 2: Check each option
CTD1.PRE := 10; uses CTD1.PRE := 10; which is correct syntax. Others use incorrect property names or assignment operators.
Final Answer:
CTD1.PRE := 10; -> Option D
Quick Check:
Preset uses .PRE and := assignment = A [OK]
Hint: Preset value uses .PRE and := in PLC counters [OK]
Common Mistakes:
Using wrong property names like PV or PRESET
Using = instead of := for assignment
Assigning count value instead of preset
3. Given a CTD counter with preset 5 and current count 3, what will be the count after one input pulse activates the count-down input?
medium
A. 2
B. 5
C. 3
D. 4
Solution
Step 1: Understand CTD count behavior on input pulse
Each input pulse decreases the current count by 1, but never below zero.
Step 2: Calculate new count
Starting from 3, after one pulse, count becomes 3 - 1 = 2.
Final Answer:
2 -> Option A
Quick Check:
3 - 1 = 2 [OK]
Hint: Count decreases by one per input pulse, never below zero [OK]
Common Mistakes:
Adding instead of subtracting count
Not changing count on input pulse
Resetting count to preset incorrectly
4. A CTD counter is not decreasing its count when the input signal is active. Which of the following is the most likely cause?
medium
A. The preset value is set to zero.
B. The input signal is connected to the count-up input instead of count-down.
C. The count value is already zero.
D. The counter is not enabled.
Solution
Step 1: Analyze why count does not decrease
If the input signal is connected to the wrong input (count-up instead of count-down), the count will not decrease as expected.
Step 2: Evaluate other options
Preset zero or count zero would not prevent counting down if input is correct. Counter enable is usually implicit or separate.
Final Answer:
The input signal is connected to the count-up input instead of count-down. -> Option B
Quick Check:
Wrong input connection stops count down = B [OK]
Hint: Check input wiring: count-down input must receive signal [OK]
Common Mistakes:
Assuming preset zero stops counting
Ignoring input wiring errors
Confusing enable with input signal
5. You have a CTD counter with preset 8 and current count 1. If the count-down input activates twice quickly before the PLC scans again, what will be the count value after the scan?
hard
A. 0
B. -1
C. 1
D. 2
Solution
Step 1: Understand count-down behavior with rapid inputs
The CTD counter decreases count by 1 per input pulse but never below zero.
Step 2: Calculate count after two pulses from 1
First pulse: 1 - 1 = 0; second pulse: cannot go below 0, so remains 0.
Final Answer:
0 -> Option A
Quick Check:
Count never negative, min is zero = A [OK]
Hint: Count never goes below zero, even with multiple pulses [OK]
Common Mistakes:
Allowing count to go negative
Ignoring multiple pulses before scan
Assuming count resets automatically
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.