Hi all,
I recently upgraded Flowcode 4 to Flowcode 6 so i enjoy the new environment and i am trying to get used of it!
I would like to calculate the remaining time for one task. The issue that i am facing is the form of the calculated remaining time (only minutes) which looks like this : 5.87 (5 hours and 87% of an hour)
For example 5.87 is 5 hours and 51 minutes.
The problem here is that i do not want to have the minutes as a percentage of an hour but i want to display the value as minutes. As i looked for a solution, i think MOD function will help me to overcome this issue.
Is there any example about how to use MOD function? Is this the right direction to look at for this kind of an issue ?
If my description is not clear please let me know and i will do my best to give you more details.
Thank you
George
Minutes of an hour are shown as percentage Solved!
Moderator: Benj
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: Using MOD function
Hi,
Yes you can use MOD for that,
here is an example, where time is your minute counter and is a UINT, mins can be a BYTE, and hours a BYTE or UINT
Yes you can use MOD for that,
here is an example, where time is your minute counter and is a UINT, mins can be a BYTE, and hours a BYTE or UINT
Code: Select all
hours = time / 60
mins = time MOD 60
// or
mins = time % 60
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Using MOD function
Hi, thanks for your reply!
At the moment i have one variable(float) named Time2Finish in the form : 5.87 (here number 87 means 87% of an hour)
How can i end up (using MOD) with the same variable(float) Time2Finish in the form : 5.52 (here number 52 means minutes) ??
Thanks in advance
George
At the moment i have one variable(float) named Time2Finish in the form : 5.87 (here number 87 means 87% of an hour)
How can i end up (using MOD) with the same variable(float) Time2Finish in the form : 5.52 (here number 52 means minutes) ??
Thanks in advance
George
Last edited by George_B on Mon Jan 25, 2016 2:58 pm, edited 1 time in total.
- 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:
Re: Using MOD function
Hello George,
You could probably do something like this.
This stores the whole number of the hour in INTHour.
This gets the minutes as a floating point number from 0.00 to 0.999999
This converts from a percentage to a number from 0-59 representing the minute count.
You could probably do something like this.
Code: Select all
INTHour = FloatToInt (Time)
Code: Select all
FloatMinsAsPercentage = Time - INTHour
Code: Select all
Minutes = FloatMinsAsPercentage * 60.0
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
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Using MOD function
Hello LeighM and Benj, thank you very much for your help.
It is now working as expected! I used a slightly different approach from the MOD function but similar to Benj description i managed to have the solution very soon.
Thank you once again!
George
It is now working as expected! I used a slightly different approach from the MOD function but similar to Benj description i managed to have the solution very soon.
Thank you once again!
George
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Using MOD function
Hi, as i said above everything works as expected.
I am wondering if there is or will be any problem with those warnings after compile the program.
Serious Warning: Possible sw stack corruption, function 'float32_addsub' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_mul' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_div' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_eq' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_lt' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCM_Percentage2MinutesConversion' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
I am wondering if there is or will be any problem with those warnings after compile the program.
Serious Warning: Possible sw stack corruption, function 'float32_addsub' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_mul' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_div' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_eq' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'float32_lt' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCM_Percentage2MinutesConversion' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
- 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:
Re: Using MOD function
Hello,
On 8-bit PIC the floating point calculations are done using functions. It looks like these functions are being referenced from the main program loop and again from the interrupt. If there is the possibility for you to be inside the function when the interrupt kicks in and calls the function again then you will likely get stack and RAM corruption which then may lead to unpredictable events.
If you can move all the floating point maths to your main program loop then this should solve the problem.
On 8-bit PIC the floating point calculations are done using functions. It looks like these functions are being referenced from the main program loop and again from the interrupt. If there is the possibility for you to be inside the function when the interrupt kicks in and calls the function again then you will likely get stack and RAM corruption which then may lead to unpredictable events.
If you can move all the floating point maths to your main program loop then this should solve the problem.
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
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Using MOD function
Benj wrote:Hello,
On 8-bit PIC the floating point calculations are done using functions. It looks like these functions are being referenced from the main program loop and again from the interrupt. If there is the possibility for you to be inside the function when the interrupt kicks in and calls the function again then you will likely get stack and RAM corruption which then may lead to unpredictable events.
If you can move all the floating point maths to your main program loop then this should solve the problem.
I have made some changes trying to move float calculations from interrupt macros. The program looks to run well now and the compiler warning messages are absent.
I would like to thank you all for your help. I found the posts in the forum really helpful.
Regards
George