Limiting routine

General questions about Firewing...

Limiting routine

Postby AndrewB » Tue May 09, 2017 9:15 am

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: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Limiting routine

Postby Jerry Messina » Tue May 09, 2017 12:31 pm

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

I think we need some more info.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Limiting routine

Postby AndrewB » Tue May 09, 2017 3:09 pm

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: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Limiting routine

Postby Jerry Messina » Tue May 09, 2017 5:03 pm

something like this?

Code: Select all
const LIMIT = 100

dim in1, in2 as ushort
dim out1, out2 as ushort
dim total as ushort

' set inputs
in1 = 0
in2 = 0

' check inputs for range
if (in1 > LIMIT) then
    in1 = LIMIT
endif
if (in2 > LIMIT) then
    in2 = LIMIT
endif

' assume outputs are ok
out1 = in1
out2 = in2

' see if outputs need to be limited
total = in1 + in2
if (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
    endif
endif
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Limiting routine

Postby AndrewB » Tue May 09, 2017 5:10 pm

Thanks Jerry I will try this out.
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x