Map Function for any target device.

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Map Function for any target device.

Post 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 9236 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 9236 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.
Attachments
Map component Test UInt.fcfx
(10.94 KiB) Downloaded 298 times
MapFunction.fcpx
(2.49 KiB) Downloaded 264 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function - LM35

Post 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 9237 times
This will require:
LM35 Map Funcrtion Properties.png
LM35 Map Funcrtion Properties.png (81.06 KiB) Viewed 9237 times
No need for any formulas used in any other flowcharts e.g

Code: Select all

Temp = Temp * 49 / 10
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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.
Attachments
MapFunctionV2.fcpx
(3.36 KiB) Downloaded 268 times
Martin

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

this function is only work in simulation.
this function does't work in real.

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

i try but it does not work in pic16f1939

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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?
Martin

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Map Function for any target device.

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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.
Last edited by medelec35 on Wed Jul 15, 2020 5:53 pm, edited 1 time in total.
Martin

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Map Function for any target device.

Post by AbhijitR »

Good morning Martin

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

Abhi

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

the problem is the result is always same as the input.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post by medelec35 »

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

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

yes i checked
Attachments
map is not working.png
map is not working.png (14.95 KiB) Viewed 9195 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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 9189 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.
Attachments
MapFunctionV2.fcpx
(3.36 KiB) Downloaded 206 times
Last edited by medelec35 on Thu Jul 16, 2020 5:45 pm, edited 1 time in total.
Reason: Incorrect test
Martin

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

i attached the file which i am working on
Last edited by panuj417 on Thu Jul 16, 2020 6:28 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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.
Martin

panuj417
Posts: 10
Joined: Sat Oct 26, 2019 9:33 am
Contact:

Re: Map Function for any target device.

Post by panuj417 »

Hii medelec35,
it works now.
thank you for your help.

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Map Function for any target device.

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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.
Attachments
Moving Average.fcfx
(12.81 KiB) Downloaded 132 times
Martin

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Map Function for any target device.

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post by medelec35 »

Hi Abhi,
You're welcome & thank you.
Martin

Eng,A
Posts: 1
Joined: Tue Mar 30, 2021 8:07 pm
Contact:

Re: Map Function for any target device.

Post by Eng,A »

Hello!
is there Map function can work with Flowcode V6 ?
Last edited by Eng,A on Tue Mar 30, 2021 8:21 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Map Function for any target device.

Post 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.
Attachments
MapFunctionV2.fcpx
(2.06 KiB) Downloaded 129 times
Martin

Post Reply