News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Many thanks Les for Scale.inc

Started by TimB, Jun 12, 2023, 08:16 AM

Previous topic - Next topic

TimB

In another post Les pointed out that if I wanted to do scaling there is a inc called scale.inc in the INCLUDES folder

When I got to implementing the bit of code I have that needed the scaling, I though I will check it out before I write my own.

Totally did not need to try and code it myself. Its only a 1 line Proc but boy does it work great.

You saved me hours. Really appreciated Les THANKS

BTW example of what I'm doing

Output in all cases is to a 12 bit DAC set to make 0% = 5% of the 4095 (819) and 100% = 95% of the 4095 (3276)

Inputs are 3 different types
0.0 to 12.0 (float)
-5.0 to +30.0 (float)
0 to 6000 (word)


Here is an example

             for fInput = -5.0 to 12.0 step 0.1

                swInput =  fInput * 100

                wScaledResult = wScale(swInput, -500, 3000, 819, 3276)


            Next



joesaliba

Tim,

I remember I had to change a variable to Dword instead of Word, as with some numbers it was exceeding the 65535 of Word when doing the multiplication. Otherwise it works great.

Regards

Joe

Maxi

Thank you tim and les ofcourse
tim, could you give a another real life example pls?

how can I use this for example:
10bit adc
input: volt 1.0 to 4.0 volt
display scale is: 10 to 50 ?

TimB

#3
You would want something like this


The variable prefixes indicate the var type e.g. BScaledResult is a byte and fInput is a float change as required
     Do

             for fInput = 1 to 4 step 0.1


                BScaledResult = fScale(fInput, 1.0, 4.0, 10, 50)


            Next



     Loop

Maxi

This is very usefull code, i love it.
Thank you les and tim