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

Post Reply
George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Contact:

Minutes of an hour are shown as percentage Solved!

Post by George_B »

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.

User avatar
LeighM
Matrix Staff
Posts: 2043
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: Using MOD function

Post by LeighM »

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 / 60
mins = time MOD 60
// or 
mins = time % 60

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Contact:

Re: Using MOD function

Post by George_B »

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
Last edited by George_B on Mon Jan 25, 2016 2:58 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 14850
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Using MOD function

Post by Benj »

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.

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Contact:

Re: Using MOD function

Post by George_B »

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
Contact:

Re: Using MOD function

Post by George_B »

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)

User avatar
Benj
Matrix Staff
Posts: 14850
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Using MOD function

Post by Benj »

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
Contact:

Re: Using MOD function

Post by George_B »

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

Post Reply