Bird
Raised Fist0
PLC Programmingscripting~10 mins

Scaling analog values in PLC Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Scaling analog values
Read raw analog input
↓
Apply scaling formula
↓
Calculate scaled value
↓
Use scaled value in program
↓
Output scaled value
The flow reads a raw analog input, applies a scaling formula to convert it to a useful range, then outputs the scaled value for use.
Execution Sample
PLC Programming
raw_input = 512
scaled = (raw_input / 1023.0) * 100
output = scaled
This code converts a raw 10-bit analog input (0-1023) to a percentage scale (0-100).
Execution Table
StepVariableValueCalculationResult
1raw_input512Read raw analog input512
2scaled(512 / 1023.0) * 100Divide and multiply50.05
3outputscaledAssign scaled to output50.05
4--End of scaling process-
💡 Scaling complete, output holds scaled value 50.05
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3
raw_inputundefined512512512
scaledundefinedundefined50.0550.05
outputundefinedundefinedundefined50.05
Key Moments - 3 Insights
Why do we divide raw_input by 1023?
Because 1023 is the maximum value of a 10-bit analog input, dividing by it normalizes the input to a 0-1 range as shown in step 2 of the execution_table.
Why multiply by 100 after dividing?
Multiplying by 100 converts the normalized value (0 to 1) into a percentage scale (0 to 100), as seen in the calculation in step 2.
What happens if raw_input is 0?
If raw_input is 0, scaled becomes 0 after step 2, so output will also be 0, meaning no signal or minimum value.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'scaled' at step 2?
A100
B512
C50.05
D0
💡 Hint
Check the 'Value' and 'Result' columns for 'scaled' at step 2 in the execution_table.
At which step is the raw analog input first read?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Calculation' column in the execution_table to find when raw_input is assigned.
If raw_input was 1023, what would 'scaled' be at step 2?
A0
B100
C50.05
D512
💡 Hint
Use the formula in step 2: (raw_input / 1023) * 100 and substitute raw_input = 1023.
Concept Snapshot
Scaling analog values:
- Read raw input (e.g., 0-1023 for 10-bit ADC)
- Normalize by dividing by max raw value (1023)
- Multiply by desired max scale (e.g., 100 for %)
- Use scaled value in program
- Output scaled value for control or display
Full Transcript
This lesson shows how to scale analog values in PLC programming. We start by reading a raw analog input, which is a number between 0 and 1023 for a 10-bit input. Then we divide this raw input by 1023 to normalize it between 0 and 1. Next, we multiply by 100 to convert it to a percentage scale from 0 to 100. Finally, we assign this scaled value to an output variable for use in the program. The execution table traces these steps with example values, showing how the variables change. Key moments clarify why we divide by 1023 and multiply by 100. The quiz tests understanding of these steps and values. This process helps convert raw sensor data into meaningful units for automation control.

Practice

(1/5)
1. What is the main purpose of scaling analog values in PLC programming?
easy
A. To reduce the size of the PLC program
B. To increase the speed of the PLC processor
C. To convert raw sensor signals into meaningful engineering units
D. To change digital signals into analog signals

Solution

  1. Step 1: Understand analog input signals

    Raw sensor signals are usually voltage or current values that need interpretation.
  2. Step 2: Purpose of scaling

    Scaling converts these raw signals into meaningful units like temperature or pressure.
  3. Final Answer:

    To convert raw sensor signals into meaningful engineering units -> Option C
  4. Quick Check:

    Scaling = Convert raw to useful units [OK]
Hint: Scaling means converting raw sensor data to real-world units [OK]
Common Mistakes:
  • Confusing scaling with speeding up the PLC
  • Thinking scaling reduces program size
  • Mixing analog and digital signal conversion
2. Which of the following is the correct formula to scale a raw analog input raw from range raw_min to raw_max into a scaled output range scale_min to scale_max?
easy
A. scaled = (raw - raw_min) * (scale_max - scale_min) / (raw_max - raw_min) + scale_min
B. scaled = raw * (scale_max - scale_min) / (raw_max + raw_min) + scale_min
C. scaled = (raw + raw_min) * (scale_max + scale_min) / (raw_max - raw_min)
D. scaled = (raw - raw_max) * (scale_min - scale_max) / (raw_min - raw_max) + scale_max

Solution

  1. Step 1: Recall the scaling formula

    The formula maps raw input linearly to the scaled range using subtraction and division.
  2. Step 2: Check each formula

    scaled = (raw - raw_min) * (scale_max - scale_min) / (raw_max - raw_min) + scale_min correctly subtracts raw_min, scales by ratio of output to input range, then adds scale_min.
  3. Final Answer:

    scaled = (raw - raw_min) * (scale_max - scale_min) / (raw_max - raw_min) + scale_min -> Option A
  4. Quick Check:

    Scaling formula = scaled = (raw - raw_min) * (scale_max - scale_min) / (raw_max - raw_min) + scale_min [OK]
Hint: Use (raw - raw_min) * output_range / input_range + scale_min [OK]
Common Mistakes:
  • Adding raw_min instead of subtracting
  • Using addition instead of subtraction in denominator
  • Mixing max and min values incorrectly
3. Given a raw input value of 2500 from a sensor with raw range 0-4095, scaled to temperature range 0-100°C using the formula scaled = (raw - 0) * (100 - 0) / (4095 - 0) + 0, what is the scaled temperature?
medium
A. 61.07°C
B. 25.00°C
C. 100.00°C
D. 0.61°C

Solution

  1. Step 1: Substitute values into formula

    scaled = (2500 - 0) * (100 - 0) / (4095 - 0) + 0 = 2500 * 100 / 4095
  2. Step 2: Calculate the scaled value

    scaled = 250000 / 4095 ≈ 61.07°C
  3. Final Answer:

    61.07°C -> Option A
  4. Quick Check:

    2500/4095 ≈ 0.61 * 100 = 61.07 [OK]
Hint: Divide raw by max raw, multiply by max scale [OK]
Common Mistakes:
  • Using raw_max as 2500 instead of 4095
  • Forgetting to subtract raw_min
  • Mixing up numerator and denominator
4. A PLC program uses this scaling code snippet:
scaled = (raw - 100) * (200 - 0) / (1000 - 0) + 0

What is the error in this scaling formula?
medium
A. The raw_min value should be 0, not 100
B. The denominator should be (1000 - 100) instead of (1000 - 0)
C. The formula should subtract scale_min, not raw_min
D. The scale_max value should be 100, not 200

Solution

  1. Step 1: Identify raw input range

    Raw input minimum is 100, maximum is 1000, so input range is 1000 - 100 = 900.
  2. Step 2: Check denominator in formula

    The formula uses (1000 - 0) = 1000, which is incorrect; it should be (1000 - 100) = 900.
  3. Final Answer:

    The denominator should be (1000 - 100) instead of (1000 - 0) -> Option B
  4. Quick Check:

    Input range = max - min = 900, not 1000 [OK]
Hint: Denominator = raw_max - raw_min, not raw_max - 0 [OK]
Common Mistakes:
  • Using wrong input range denominator
  • Confusing scale and raw min/max
  • Subtracting scale_min instead of adding
5. You have a sensor outputting raw values from 500 to 3500 representing pressure from 20 to 100 psi. Which formula correctly scales a raw input raw to pressure?
hard
A. pressure = (raw - 500) * (100 - 20) / (3500 - 500) + 0
B. pressure = (raw - 0) * (100 - 20) / (3500 - 500) + 20
C. pressure = (raw - 500) * (100 - 20) / (3500 - 0) + 20
D. pressure = (raw - 500) * (100 - 20) / (3500 - 500) + 20

Solution

  1. Step 1: Identify raw and scale ranges

    Raw range: 500 to 3500; pressure range: 20 to 100 psi.
  2. Step 2: Apply scaling formula

    Use (raw - raw_min) * (scale_max - scale_min) / (raw_max - raw_min) + scale_min.
  3. Step 3: Check each option

    pressure = (raw - 500) * (100 - 20) / (3500 - 500) + 20 correctly uses raw_min=500, raw_max=3500, scale_min=20, scale_max=100.
  4. Final Answer:

    pressure = (raw - 500) * (100 - 20) / (3500 - 500) + 20 -> Option D
  5. Quick Check:

    Correct raw and scale min/max used in formula [OK]
Hint: Always subtract raw_min and add scale_min in formula [OK]
Common Mistakes:
  • Using 0 instead of raw_min in subtraction
  • Adding 0 instead of scale_min at end
  • Mixing raw_max with 0 in denominator
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard