## Limiting routine

### Limiting routine

I am reading two analogue inputs (0-1023) and following these on two analogue outputs but would like to cap the two outputs so that the combined total of the two outputs does not exceed 1023.

e.g when both inputs are 1023 then both outputs would be 512.
if input 1 is 0 and input 2 is 1023 the output 1 is 0 and output 2 is 1023

Is there a way to do this without having a complex if then routine.
AndrewB

Posts: 71
Joined: Thu Jan 02, 2014 3:38 pm

### Re: Limiting routine

How would you want other cases handled, like input1=512 and input2=700?
What if both were 700?

Jerry Messina

Posts: 256
Joined: Thu Feb 14, 2013 10:16 am

### Re: Limiting routine

Hi Jerry, I want it to increment and decrement in steps of one.

The outputs limited to a percentage total. Say 50% of the total of in1 + in2 1023 +1023 / 2 = 1023

The outputs to follow the inputs.

e.g in percent of 1023

in1 in2 out1 out2
10 70 10 70
30 70 30 70
35 70 35 65
45 65 45 55
65 65 50 50
65 35 65 35
75 35 65 35
100 1 99 1

Hope that explains it
AndrewB

Posts: 71
Joined: Thu Jan 02, 2014 3:38 pm

### Re: Limiting routine

something like this?

Code: Select all
`const LIMIT = 100dim in1, in2 as ushortdim out1, out2 as ushortdim total as ushort' set inputsin1 = 0in2 = 0' check inputs for rangeif (in1 > LIMIT) then    in1 = LIMITendifif (in2 > LIMIT) then    in2 = LIMITendif' assume outputs are okout1 = in1out2 = in2' see if outputs need to be limitedtotal = in1 + in2if (total > LIMIT) then    if (in1 = in2) then         ' 50/50 split        out1 = LIMIT/2        out2 = LIMIT/2    elseif (in1 > in2) then     ' limit out1        out1 = LIMIT - in2    else                        ' limit out2        out2 = LIMIT - in1    endifendif`
Jerry Messina

Posts: 256
Joined: Thu Feb 14, 2013 10:16 am

### Re: Limiting routine

Thanks Jerry I will try this out.
AndrewB

Posts: 71
Joined: Thu Jan 02, 2014 3:38 pm