Page 1 of 1

RTC componrnt macro

Posted: Sun Apr 26, 2020 2:34 am
by billduck
I am writing to the RTC and then reading the Hours and Minutes.
I am not getting the expected results when displaying the Hours and Minutes.
What am I doing incorrectly?
Thanks in advance.

Re: RTC componrnt macro

Posted: Sun Apr 26, 2020 1:16 pm
by medelec35
Hi billduck,
Have you tested on hardware?
Simulation shows 0 for hours and minutes.
My actual hardware shows 45 for minutes and 12 for hours.
Not tested with arduino as not got one to hand.
Tested with 16F1937
If not working for you then its always best to run the one second flash test.
LCD's are much more forgiving than I2C, therefore you could believe clock speed is correct when it is not.

Re: RTC componrnt macro

Posted: Sun Apr 26, 2020 3:11 pm
by mnf
Try running the i2c channel as hardware - or at 100kHz for software mode...

Might be stretching the arduino a bit to run 400khz bit-banging the port. Should work AOK in hardware mode though?

Martin

Re: RTC componrnt macro

Posted: Sun Apr 26, 2020 5:50 pm
by billduck
My post was a dump post. Mine works on the hardware. I will post something later that does not work.
In it, I go thru the process of setting the minutes,Hours,Month and Day of month. Then disconnect power or reboot, and the DS3231 does not retain the numbers, as they come up as 0:00.

Re: RTC componrnt macro

Posted: Sun Apr 26, 2020 6:04 pm
by medelec35
billduck wrote: Then disconnect power or reboot, and the DS3231 does not retain the numbers, as they come up as 0:00.
Sounds like a battery issue.
If you apply power and hours and minutes are shown as 00:00, that is the RTC default state it no time has been programmed.
If you have programmed a time then due to battery issue it's not being retained.
You will need to check the battery voltage of at least 2.3V is present between Vbat an GND.
billduck wrote:Mine works on the hardware. I will post something later that does not work.
If battery voltage is OK, then if need help should post a flowchart that is not working rather one that works, as we have used our time to test flowchart that has been posted.

Re: RTC componrnt macro

Posted: Sun Apr 26, 2020 6:45 pm
by jgu1
Hi!

I don´t know if this is the issue, but I think you have to use the same name when you set and read the time again.

Set hour = Hour, Read hour = Hour and the same for minute. this is the way I use the rtc component and it always work for me.

Could be :wink: But also check Martin and Martin´s Idea :lol:

Br Jorgen

Re: RTC componrnt macro

Posted: Mon Apr 27, 2020 10:13 pm
by billduck
I have a problem displaying the data from the RTC.
I set the clock with a program. Works fine.
Then I read the data, convert the binary value to a string (ToString$(binary)) and display the time, and it works fine.
But I want to use the binary formatted values in a construct "MinuteFromMidnight", an integer.
The int variable "MinuteFromMidnight" is simply "60 * Hour + Minute"
I have tried it when Minute and Hour are bytes. A time of 12:56 gives "MinutefromMidnight" as 61. I suspect there is a broblem with bytes.
I have tried it when I cast the bytes to integers. Get the same result 61, enen though the RTC time has changed.
Does anyone have a suggestion?
Thanks in advance.

Re: RTC componrnt macro

Posted: Mon Apr 27, 2020 10:38 pm
by billduck
I have to add, that before I used the RTC component macro, that I used the following code to create MinuteFromMidnight.
Maybe this is part of the solution.

.HourFromRTC = (.HourFromRTC >> 4) * 10 + (.HourFromRTC & 15)
.MinutefromRTC = (.MinuteFromRTC >> 4) * 10 + (.MinuteFromRTC & 15)
MinuteFromMidnite = .HourFromRTC * 60 + .MinuteFromRTC

Re: RTC componrnt macro

Posted: Tue Apr 28, 2020 8:52 am
by mnf
Create a Macro - MinsFromMidnight(hrs, mins) returning an int (16 bit)

Should return hrs * 60 + mins.

Then plug in a few figures (not necessarily from the RTC) and check the results..

In pseudocode..
res = hrs (if hrs is a byte this will skip any extension (8->16 bit) problems - but probably isn't necessary)
res = res * 60 + mins.

Should be possible to check in simulation or on hardware. Try printing MinsFromMidnight(m, h) for various values.....

Martin

Re: RTC componrnt macro

Posted: Tue Apr 28, 2020 12:28 pm
by medelec35
One thing that is puzzling me.
When I load your flowcharts,
The GetTime call function is wrong, it won't be accessed:
GetTime Call Macro.png
(6.03 KiB) Downloaded 408 times
Version is okay as you can see it showing Version() on the right of the icon.

Is that the case or V8 is bugged when loading a Flowchart?

Re: RTC componrnt macro

Posted: Tue Apr 28, 2020 5:27 pm
by billduck
I do not know what I got correct / changed, but this program works. If the time is 8:32, the Min From Midnight is 512 = 60*Hours + Minutes
Now to integrate it into the main program for a 2 axis Solar Tracker