Map Function for any target device.
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Map Function for any target device.
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: 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: 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.
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: 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: 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 448 times
-
- MapFunction.fcpx
- (2.49 KiB) Downloaded 462 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function - LM35
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
Third column (C) is the ADC value for the given for the ADC voltage present on the ADC pin.
For that the formula is or 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: This will require: No need for any formulas used in any other flowcharts e.g
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
For that the formula is
Code: Select all
=ROUNDDOWN(1024/5*B1;0)
Code: Select all
=ROUNDDOWN(1024/5*B3,0)
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: This will require: No need for any formulas used in any other flowcharts e.g
Code: Select all
Temp = Temp * 49 / 10
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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.
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 435 times
Martin
Re: Map Function for any target device.
this function is only work in simulation.
this function does't work in real.
this function does't work in real.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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?
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
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 284 times
- Been thanked: 80 times
Re: Map Function for any target device.
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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.
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
Can you check you have the variable showing outlined present:
You're welcome.
Martin
Re: Map Function for any target device.
yes i checked
- Attachments
-
- map is not working.png (14.95 KiB) Viewed 15230 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
Can you post your flowchart please,
I will look in to it.
I have just tested it and working for me: 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.
I will look in to it.
I have just tested it and working for me: 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 383 times
Last edited by medelec35 on Thu Jul 16, 2020 5:45 pm, edited 1 time in total.
Reason: Incorrect test
Reason: Incorrect test
Martin
Re: Map Function for any target device.
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.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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.
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
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 284 times
- Been thanked: 80 times
Re: Map Function for any target device.
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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 thethat 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.
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
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 229 times
Martin
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 284 times
- Been thanked: 80 times
Re: Map Function for any target device.
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
Hello!
is there Map function can work with Flowcode V6 ?
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.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Map Function for any target device.
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.
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 270 times
Martin