## Minutes of an hour are shown as percentage Solved!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

### Minutes of an hour are shown as percentage Solved!

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
Last edited by George_B on Sun Jan 31, 2016 5:07 pm, edited 1 time in total.

LeighM
Matrix Staff
Posts: 1911
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 460 times
Been thanked: 646 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

Code: Select all

`hours = time / 60mins = time MOD 60// or mins = time % 60`
These users thanked the author LeighM for the post:
George_B (Mon Jan 25, 2016 8:35 pm)
Rating: 5.26%

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

### Re: Using MOD function

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) ??

George
Last edited by George_B on Mon Jan 25, 2016 2:58 pm, edited 1 time in total.

Benj
Matrix Staff
Posts: 14367
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4446 times
Been thanked: 4144 times
Contact:

### Re: Using MOD function

Hello George,

You could probably do something like this.

Code: Select all

`INTHour = FloatToInt (Time)`

This stores the whole number of the hour in INTHour.

Code: Select all

`FloatMinsAsPercentage = Time - INTHour`

This gets the minutes as a floating point number from 0.00 to 0.999999

Code: Select all

`Minutes = FloatMinsAsPercentage * 60.0`

This converts from a percentage to a number from 0-59 representing the minute count.
These users thanked the author Benj for the post:
George_B (Mon Jan 25, 2016 8:35 pm)
Rating: 5.26%

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 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

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 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)

Benj
Matrix Staff
Posts: 14367
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4446 times
Been thanked: 4144 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.

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 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
These users thanked the author George_B for the post:
Benj (Mon Feb 01, 2016 12:13 pm)
Rating: 5.26%