News:

;) This forum is the property of Proton software developers

Main Menu

Cannot get the correct answer

Started by joesaliba, Nov 19, 2022, 09:32 PM

Previous topic - Next topic

joesaliba

Device 18F26K22

Latest compiler update.

I am trying to scale a value from 501 to 1000 input, to 87 to 322 as output.

For a trial, I put a fixed input od 550.

I tried the scale.inc but was having a result of 96 instead of 110.

I thought to convert it to a procedure and having the same result: -

proc wScale(pValueIn as word, pInMin as word, pInMax as word, pOutMin as word, pOutMax as word), wtemp

    Dim dResult   As Dword

    dresult = 0

    dResult = pValueIn - pInMin
    dResult = dResult * (pOutMax - pOutMin)
    dResult = dResult / (pInMax - pInMin)
    dResult = dResult + pOutMin

    result = dresult

 endproc

And to test: -

wScale(550, 501, 1000, 87, 322)
wTemp should return 110 not 96, and all values up to 1000, my maximum, are incorrect.

I did an excel sheet and tried it with a calculator.

Can someone please confirm this?

Thank you

Joe

RGV250

Hi Joe,
Did you use the correct scale, I have just tried it with the scale.inc and got 110

    MyWord = iScale(550,501,1000,87,322)

Bob

RGV250

#2
This is the test program, use the PIC16_ALCD VSM board

    Include "Proton_4.Inc"                  ' Use the Positron8 Development Board for Demo app
    Declare Reminders = Off

    Dim MyWord As Word                   
   
    Include "scale.inc"

    MyWord = iScale(550,501,1000,87,322)
   
    Print At 2,1,"MyWord ", Dec MyWord
    Stop

Also 1000 gives 322

joesaliba

Thanks Bob for trying that out.

Yesterday I did over 3 or 4 hours battling with this. After a so and so sleep, with a fresher mind, I did some tests.

The scale looks to be working good.

As a test I had this: -

EGT = 550
select egt
    case > 99
        egt = wScale(egt, 100, 500, 0, 86)
 
   case > 500
        egt = wScale(egt, 501, 1000, 87, 322)
 
    case < 100
        wtemp = 0
 endselect

I was expecting that Case > 500 will be chosen as 550 is greater than 500. However, and rightly so, it was always choosing the first comparison as 500 is greater than 99, STUPID me!!!!

I changed to the following and now everything is as expected: -

select egt
   case > 500
        egt = wScale(egt, 501, 1000, 87, 322)

    case > 99
        egt = wScale(egt, 100, 500, 0, 86)

    case < 100
        wtemp = 0
 endselect

This is not the first time that I am tired and make stupid mistakes. The worse thing is that I keep pushing to solve the problem, and I do not see the wood from the trees!

Joe