RTC componrnt macro
Moderator: Benj
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
RTC componrnt macro
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.
I am not getting the expected results when displaying the Hours and Minutes.
What am I doing incorrectly?
Thanks in advance.
- Attachments
-
- RTC Test.fcfx
- (13.57 KiB) Downloaded 183 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: RTC componrnt macro
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.
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.
Martin
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: RTC componrnt macro
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
Might be stretching the arduino a bit to run 400khz bit-banging the port. Should work AOK in hardware mode though?
Martin
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: RTC componrnt macro
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.
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.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: RTC componrnt macro
Sounds like a battery issue.billduck wrote: Then disconnect power or reboot, and the DS3231 does not retain the numbers, as they come up as 0:00.
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.
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.billduck wrote:Mine works on the hardware. I will post something later that does not work.
Martin
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: RTC componrnt macro
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
But also check Martin and Martin´s Idea
Br Jorgen
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


Br Jorgen
- Attachments
-
- RTC Test (2).fcfx
- (13.16 KiB) Downloaded 206 times
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: RTC componrnt macro
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.
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.
- Attachments
-
- RTC Not Work_Cast Integer.fcfx
- (20.33 KiB) Downloaded 202 times
-
- RTC Not Work_Bytes.fcfx
- (19.7 KiB) Downloaded 209 times
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: RTC componrnt macro
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
Maybe this is part of the solution.
.HourFromRTC = (.HourFromRTC >> 4) * 10 + (.HourFromRTC & 15)
.MinutefromRTC = (.MinuteFromRTC >> 4) * 10 + (.MinuteFromRTC & 15)
MinuteFromMidnite = .HourFromRTC * 60 + .MinuteFromRTC
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: RTC componrnt macro
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: RTC componrnt macro
One thing that is puzzling me.
When I load your flowcharts,
The GetTime call function is wrong, it won't be accessed: 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?
When I load your flowcharts,
The GetTime call function is wrong, it won't be accessed: 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?
Martin
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: RTC componrnt macro
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
Now to integrate it into the main program for a 2 axis Solar Tracker
- Attachments
-
- Read Time_RTC.fcfx
- (14.43 KiB) Downloaded 186 times