Page 1 of 1

Map Function for any target device.

Posted: Mon May 25, 2020 8:57 pm
by medelec35
I have created a Map function component for any target device, since using a formula may not give exact results required.
This will only work on Flowcode V8 (For component that works on both Flowcode V7 & V8 - See post Mon Jun 01, 2020)
1. Create a user component directory on your hard drive.
2. Within Flowcode select View, Global Options then select Location tab
3. Within Look for components in...box, enter the path you will be placing the attached component.
4. Save Flowchart & click on the reload icon
The Map Function component should now be found within User category.
For functions within the component, you can select different variable types.
This should to help to keep the space use on the target device as low as possible.
These are the functions:
Map component functions.png
Map component functions.png (3.59 KiB) Viewed 11530 times
The map function is intended to change one range of values into another range of values.
Example 1.
Output from a temperature sensor is in centigrade.
you can map it to give the result in Fahrenheit.
To do that set: InMin to 0, InMax 100, OutMin to 32 & OutMax to 212 & ClampMinMax as 0:
Map Function UInt -  C to F.png
Map Function UInt - C to F.png (69.49 KiB) Viewed 11530 times
With ClampMinMax = 0 then the input is allowed to go over 100.
For example if the temperature sensor is at 120 deg C the value of the variable going in to the map function will be 120.
The returned value will be 248.
If you don't want a higher value than OutMax then set ClampMinMax as 1.
E.g you could could a variable with a wide range and only a narrow range is required.

Example 2.
You have a pot which produces ADC from 0 to 255.
You want to convert it to 10 to 100 as you don't want PWM to drop below 10%
To do that set: InMin to 0, InMax 255, OutMin to 10 & OutMax to 100 & ClampMinMax as 0
You don't need ClampMinMax at 1 since the pot value will not be below 0 or above 255

A tip for using the analogue pot during simulation.
Select View, Analog InputsLeft click the Rough value required, keep mouse button pressed in.
While pressed in, press left and right arrow buttons on your keyboard to alter value by 1 at a time.

Re: Map Function - LM35

Posted: Wed May 27, 2020 5:26 pm
by medelec35
Thought of another application for the map component.
Thermometer using LM35
If you create a simple excel sheet, first column (A) being temperature e. 0 to 100.
Second column (B) can be the voltage on the ADC pin for given temperature.
For that the formula is

Code: Select all

=0.01*A1
Third column (C) is the ADC value for the given for the ADC voltage present on the ADC pin.
For that the formula is

Code: Select all

=ROUNDDOWN(1024/5*B1;0)
or

Code: Select all

=ROUNDDOWN(1024/5*B3,0)
depending on what spread sheet app you are using.
Now for the map component part.
Look on the spreadsheet for two temperature values, I will use 0 deg and 100deg as the example.
You will see the following:
LM35 1 to 100 deg C.png
LM35 1 to 100 deg C.png (3.54 KiB) Viewed 11531 times
This will require:
LM35 Map Funcrtion Properties.png
LM35 Map Funcrtion Properties.png (81.06 KiB) Viewed 11531 times
No need for any formulas used in any other flowcharts e.g

Code: Select all

Temp = Temp * 49 / 10

Re: Map Function for any target device.

Posted: Mon Jun 01, 2020 1:44 pm
by medelec35
Attached is a version that works in both Flowcode V7 & V8
Map component is not just for arduino, it works for any target device.
I'm currently using it on 8 bit PIC devices.

Re: Map Function for any target device.

Posted: Wed Jul 15, 2020 8:58 am
by panuj417
this function is only work in simulation.
this function does't work in real.

Re: Map Function for any target device.

Posted: Wed Jul 15, 2020 12:20 pm
by panuj417
i try but it does not work in pic16f1939

Re: Map Function for any target device.

Posted: Wed Jul 15, 2020 1:41 pm
by medelec35
So I can investigate the issue,
can you post you flowchart please?
What is the exact issue you are facing?
Is the result always the same as the input value?

Re: Map Function for any target device.

Posted: Wed Jul 15, 2020 5:08 pm
by AbhijitR
Hello! Martin

I am trying to view the pictures from the above post but unfortunately do not open, only a tiny box opens in the next tab, so not able to understand, any idea why I am not able to view.

Regards
Abhi

Re: Map Function for any target device.

Posted: Wed Jul 15, 2020 5:43 pm
by medelec35
Hi Abhi,
Thank you for your post.
I was just talking to Steve about this.
The images were viewable.
They have become corrupt since the server upgrade.
I will see if I have a backup of the images.

Edit:
Just restored all images.

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 4:45 am
by AbhijitR
Good morning Martin

Thanks for the restoration, yes now the pictures are visible.

Abhi

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 9:08 am
by panuj417
the problem is the result is always same as the input.

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 10:24 am
by medelec35
Can you check you have the variable showing outlined present:
Var Present.png
Var Present.png (83.34 KiB) Viewed 11500 times
AbhijitR wrote:
Thu Jul 16, 2020 4:45 am
Good morning Martin
Thanks for the restoration,
You're welcome.

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 10:52 am
by panuj417
yes i checked

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 11:43 am
by medelec35
Can you post your flowchart please,
I will look in to it.
I have just tested it and working for me:
Map Results.jpg
Map Results.jpg (127.13 KiB) Viewed 11483 times
I have attached my component just used, for a comparison.

The variable for Input Value is not showing the underscore.
That should not be allowed.
Unless its just the image not showing the underscore?

Edit: Not working correctly as ULong is required instead of UInt.

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 1:53 pm
by panuj417
i attached the file which i am working on

Re: Map Function for any target device.

Posted: Thu Jul 16, 2020 5:06 pm
by medelec35
Hi panuj417,
The component is working OK.
Can you try using the ULong rather than UInit
I did not test thoroughly enough earlier.
Sorry about that.

Re: Map Function for any target device.

Posted: Fri Jul 17, 2020 7:11 am
by panuj417
Hii medelec35,
it works now.
thank you for your help.

Re: Map Function for any target device.

Posted: Wed Jan 27, 2021 4:55 pm
by AbhijitR
Hello! Martin
good evening

Once again thanks for this post, it works wonderful, cheers...

May i request you to help me understand is it possible to add the function like "GetAverageInt" effect from ADC component for the output of the Map Function to stabilize the reading, actually i am using the MCP3201 ADC component created by @Chipfryer27, it works very nice on real hardware along with Map Function, i think something like "GetAverageInt" will be very useful or can you prompt some other way.

Thank you.

Abhi

Re: Map Function for any target device.

Posted: Wed Jan 27, 2021 9:14 pm
by medelec35
Hi Abhi,
You're welcome.
Not sure if your are aware, but Ben has made the Map function in to an official component.
He has also added Float to the list of the type of variables used.
Its the

Code: Select all

GetAverageInt 
that does the stabilizing as the result is just being averaged out.
The Map function just changes one range of values into another range of values.
So Ints can be changed to bytes, centigrade to Fahrenheit, Value to a required PWM etc.
If the input to the map function is changing then depending on the scale factor, the output of the map function will be changing as well.
If after using GetAverageInt the value is drifting still then either the voltage measuring has ripple or some type of drift/interference.
Or there is an issue with MCP3201 ADC component?
An alternative to GetAverageInt there is a moving average method.
Here is an old thread so you can read about it.
Attached is the flowchart from that thread converted to v7 and above.

Re: Map Function for any target device.

Posted: Thu Jan 28, 2021 1:08 pm
by AbhijitR
Hello! Martin
good afternoon

FC Wiki, no exaggeration, you understand exactly what is the problem and its solution, many many thanks for the below post, thanks to @Jan Lichtenbelt too for that detailed study, so many things to learn.

Abhi

Re: Map Function for any target device.

Posted: Sat Jan 30, 2021 3:03 am
by medelec35
Hi Abhi,
You're welcome & thank you.

Re: Map Function for any target device.

Posted: Tue Mar 30, 2021 8:16 pm
by Eng,A
Hello!
is there Map function can work with Flowcode V6 ?

Re: Map Function for any target device.

Posted: Tue Mar 30, 2021 8:50 pm
by medelec35
You can try this, its not the newest version.
Close Flowcode.
Place the attached in:
C:\Program Files\Flowcode 6\components
If 32 bit windows
Or
C:\Program Files (x86)\Flowcode 6\components
If 64 bit windows?
Open Flowcode.
You can find the Map component in the Storage section.

Alternatively:
1. Create a new folder for component files.
2. Place the component in the new component folder.
3. Open Flowcode & select View Global Options.
4. Select Locations and the ... icon in the Look for components in.
5. Browse to the new components folder and choose the .fcpx file.
6. Close and reopen Flowcode & the new component should be present.