Page 1 of 1

Minutes of an hour are shown as percentage Solved!

Posted: Sun Jan 24, 2016 5:32 pm
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

Re: Using MOD function

Posted: Mon Jan 25, 2016 9:52 am
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

Re: Using MOD function

Posted: Mon Jan 25, 2016 12:45 pm
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

Re: Using MOD function

Posted: Mon Jan 25, 2016 1:17 pm
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.

Re: Using MOD function

Posted: Mon Jan 25, 2016 7:38 pm
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

Re: Using MOD function

Posted: Tue Jan 26, 2016 11:15 am
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)

Re: Using MOD function

Posted: Tue Jan 26, 2016 1:11 pm
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.

Re: Using MOD function

Posted: Sat Jan 30, 2016 2:01 pm
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