Sign in to follow this  
Followers 0
Rodrigo Balsalobre

HELP WITH A RTC LOGIC

5 posts in this topic

Hi,

  I was trying to do an logic with rtc, but I know i'm in the wrong way to do this, can someone give me a light about how can I do this on a better way?

 you insert an hour and minute to start a engine, and a hour and minute to stop this engine by the hmi. The way i'm doing this is:
 

(ActualHour>=SetOnHour)&(ActualMinute>=SetOnMinute) == EngineON
(ActualHour=SetOffHour)&(ActualMinute=SetOffMinute) == EngineOFF

I know that are completely wrong because

1st: If i select 5AM to start and 5PM to stop, after 5PM, the system will start again.
2nd:Thinking you selected to start 5AM and stop 5PM, and know its 8AM, the system will start by hours normally, but if you have selected 20 minute and know its 15, the system will not work

  

Share this post


Link to post
Share on other sites

For each bound, and for the current time, convert hour and minute to minute-of-day.  (zero to 1439.)  Then you can do normal bounds checking on those integers.

1 person likes this

Share this post


Link to post
Share on other sites

Wow, how i didn't try this hahaha, felling like a dumbass 

I will do this and i come later to show the results and possible problems... thank you for the enlightenment


 

Share this post


Link to post
Share on other sites

Problem solved with the function

(SetOffHour>=ActualHour)&(ActualHour>=SetOnHour) == engine (on/off)

Btw, with this, another problem has appeared, this doesnt solve this question: When the SetOFFHour is lower than the ActualHour, so, if I select 5Am to Start and 4Am to stop, after 23:59, the system just stop and will only start at 5am again

Share this post


Link to post
Share on other sites
On 04/03/2023 at 11:38 PM, Rodrigo Balsalobre said:

Problem solved with the function

(SetOffHour>=ActualHour)&(ActualHour>=SetOnHour) == engine (on/off)

Btw, with this, another problem has appeared, this doesnt solve this question: When the SetOFFHour is lower than the ActualHour, so, if I select 5Am to Start and 4Am to stop, after 23:59, the system just stop and will only start at 5am again

i'm here again and the fuction to solve is

(SetOffHour>=ActualHour>=SetOnHour) == engine (on/off)
OR
(SetOffHour>=0 && SetOffHour<=SetOnHour<=ActualHour) == engine on/off

these two conditions solve the problem

Edited by Rodrigo Balsalobre

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0