I want to perform this routine
distanceProd = distance * 36
timeProd = seconds * 10000
KPH = distanceProd / timeProd
sKPH = KPH * 32
where distance = 10000 (this is the maximum distance)
and seconds = 3600 (the minimum KPH of 0.01 at maximum distance)
This wouild mean a 32/24bit opperation. How can i do that in FlowCode
Regarsd
Harry
MATH problem
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Harry
You may be able to do the calculations using int variables but if the numbers are getting too large then you can define short variables and use a C code Block.
However this calculation routine would be very inefficient and would probably not work correctly due to instructions running into the thousands if not higher. A simpler approach would be to scale down the equasions and use psudo numbers to represent the actual numbers.
You may be able to do the calculations using int variables but if the numbers are getting too large then you can define short variables and use a C code Block.
Code: Select all
short distanceProd, timeProd, KPH, sKPH;
distanceProd = FCV_DISTANCE * 36;
timeProd = FCV_SECONDS * 10000;
KPH = distanceProd / timeProd;
sKPH = KPH * 32;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
32-bit maths can be done within C using the "long" datatype, so this may work:
(where the 3 FCV_ variables are defined within Flowcode as 16-bit "integers").
Code: Select all
long distanceProd, timeProd, KPH;
distanceProd = FCV_DISTANCE * 36;
timeProd = FCV_SECONDS * 10000;
KPH = distanceProd / timeProd;
FCV_SKPH = KPH * 32;
-
- Posts: 209
- Joined: Thu Oct 19, 2006 11:46 am
- Location: Bakewell, UK
- Has thanked: 20 times
- Been thanked: 16 times
gharryh
I would personally consider this as a math problem rather than a Flowcode capability issue.
You generate a number *36 and divide it by a number *1000. It makes more sense to combine these constants into a single divide by 28. This should then sit nicely within the +/- 32000 that Flowcode provides.
As a general point, 32,000 effectively allows for 2^15 accuracy, which is 2^ 3 or 8 times better resolution than a good A/D input. Hence, I would personally put 32 bit math as a low priority for Flowcode.
Hope this helps,
Mark
Mark
ps the 28 is an approximation and could be *10 then /277
I would personally consider this as a math problem rather than a Flowcode capability issue.
You generate a number *36 and divide it by a number *1000. It makes more sense to combine these constants into a single divide by 28. This should then sit nicely within the +/- 32000 that Flowcode provides.
As a general point, 32,000 effectively allows for 2^15 accuracy, which is 2^ 3 or 8 times better resolution than a good A/D input. Hence, I would personally put 32 bit math as a low priority for Flowcode.
Hope this helps,
Mark
Mark
ps the 28 is an approximation and could be *10 then /277
Go with the Flow.
Hi Steve,
If i would use this inside flowcode how should i do that??steve wrote:32-bit maths can be done within C using the "long" datatype, so this may work:
(where the 3 FCV_ variables are defined within Flowcode as 16-bit "integers").Code: Select all
long distanceProd, timeProd, KPH; distanceProd = FCV_DISTANCE * 36; timeProd = FCV_SECONDS * 10000; KPH = distanceProd / timeProd; FCV_SKPH = KPH * 32;
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Create 3 integer variables, "Distance", "Seconds" and "sKPH", within Flowcode.
Put the code into a C icon within your flowchart.
Before this icon, populate "Distance" and "Seconds" with appropriate values.
After the C icon, the value in "sKPH" should be correct.
NOTE: this code will not simulate, so you would need to download it to a PICmicro to see it working.
Put the code into a C icon within your flowchart.
Before this icon, populate "Distance" and "Seconds" with appropriate values.
After the C icon, the value in "sKPH" should be correct.
NOTE: this code will not simulate, so you would need to download it to a PICmicro to see it working.
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
The code you need to place into a C icon in step (2) is the code previously mentioned, ie:steve wrote:1. Create 3 integer variables, "Distance", "Seconds" and "sKPH", within Flowcode.
2. Put the code into a C icon within your flowchart.
3. Before this icon, populate "Distance" and "Seconds" with appropriate values.
4. After the C icon, the value in "sKPH" should be correct.
NOTE: this code will not simulate, so you would need to download it to a PICmicro to see it working.
Code: Select all
long distanceProd, timeProd, KPH;
distanceProd = FCV_DISTANCE * 36;
timeProd = FCV_SECONDS * 10000;
KPH = distanceProd / timeProd;
FCV_SKPH = KPH * 32;
We will be allowing users to post their code for review on this site, hopefully within the next month or two (we are waiting for an update to the BB software).
If you were a registered user of Flowcode, I would suggest that you send the code to us and we would have a quick look. But unfortunately, you have not bought Flowcode and so we cannot provide that extra level of support.