RTC componrnt macro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

RTC componrnt macro

Post 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.
Attachments
RTC Test.fcfx
(13.57 KiB) Downloaded 161 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RTC componrnt macro

Post 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.
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1200
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times
Contact:

Re: RTC componrnt macro

Post 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

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: RTC componrnt macro

Post 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RTC componrnt macro

Post 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.
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: RTC componrnt macro

Post 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
Attachments
RTC Test (2).fcfx
(13.16 KiB) Downloaded 162 times

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: RTC componrnt macro

Post 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.
Attachments
RTC Not Work_Cast Integer.fcfx
(20.33 KiB) Downloaded 169 times
RTC Not Work_Bytes.fcfx
(19.7 KiB) Downloaded 166 times

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: RTC componrnt macro

Post 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

mnf
Valued Contributor
Valued Contributor
Posts: 1200
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times
Contact:

Re: RTC componrnt macro

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RTC componrnt macro

Post 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?
Martin

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: RTC componrnt macro

Post 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
Attachments
Read Time_RTC.fcfx
(14.43 KiB) Downloaded 142 times

Post Reply