Basic
8 min

Analog 00 — Raw reading to percent

analogscalingintegermathlevelbeginner

Ready to build this?

Sign up free — no credit card required. This scenario requires the Basic plan.

Sign up to play this scenario →

Already have an account? Log in

Analog 00 — Raw reading to percent

Briefing

A level transmitter gives LEVEL_RAW, a whole number from 0 (empty) to 32767 (full). The panel needs LEVEL_PCT, 0 to 100. A result within 1 of the true value is accepted. Whole-number maths throws away the fraction, so the order matters: a small number divided by 32767 is 0. SCALED is a larger (DINT) variable for the in-between result. Maths is written in the Code tab, one assignment per line, with the function names ADD, SUB, MUL and DIV. For example, TOTAL := ADD(A, B); stores A plus B in TOTAL.

Objectives

  • Raw 0 gives 0 percent
  • Raw 8192 gives about 25 and 16384 about 50
  • Raw 32767 gives 100
  • A small raw reading such as 1000 gives about 3, not 0

Hints

  • The input spans 0 to 32767 and the output spans 0 to 100. Write the scaling as a fraction: output = input x something / something.
  • Whole-number maths keeps no fraction. Which operation should come first so small readings do not collapse to zero?
  • Multiplying a reading by 100 can be bigger than a small integer holds. The SCALED variable is a DINT so the in-between value fits.
  • Check three readings in the input panel: 8192 should give about 25, 32767 gives 100, and 1000 gives about 3.

I/O Table

Inputs

LEVEL_RAW

Level transmitter raw value, 0-32767

INT · %IW0

Outputs

LEVEL_PCT

Tank level, 0-100 percent

INT · %QW0

Your program will be tested against:

All test cases run automatically when you submit. Assertions are hidden until you pass.

  1. #1Raw 0 → 0 percent

    An empty tank reads 0 percent

  2. #2Raw 8192 → about 25 percent

    A quarter of the raw range is a quarter of the scale

  3. #3Raw 16384 → about 50 percent

    Half of the raw range is half of the scale

  4. #4Raw 32767 → 100 percent

    The top of the raw range is the top of the scale

  5. #5Raw 1000 → about 3 percent

    A small reading must not collapse to zero

Ready to build this?

Sign up free — no credit card required. This scenario requires the Basic plan.

Sign up to play this scenario →

Already have an account? Log in