Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:49 29 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM - replacing 1307 with 3231 RTC

     Page 1 of 3    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 07:25pm 06 Aug 2014
Copy link to clipboard 
Print this post

Hi folks.

As I am designing a custom PCB for my CMM based project, I was thinking perhaps I could use the likes of the 3231 extremely accurate RTC with internal crystal etc.

These are available as I2C modules on the likes of eBay for only about $10 or so - cheaper then the chip by itself, and they usually have on-board button cell too.

So, my question is, can I just substitute the 3231 for the 1307 and it's battery and crystal, and have a more accurate(over time) RTC?

From what I have been reading, both the 1307 and the 3231 or 3232 use all the same addresses for time keeping, but there are battery-backed RAM address differences, but I have no plan to use those features of the 3231 - I just want it for the RTC.

So, can I connect it where the 1307 would be, or are there special commands used with the 1307 that would mean I have to use that RTC?

Smoke makes things work. When the smoke gets out, it stops!
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 08:20pm 06 Aug 2014
Copy link to clipboard 
Print this post

  Grogster said   Hi folks.

As I am designing a custom PCB for my CMM based project, I was thinking perhaps I could use the likes of the 3231 extremely accurate RTC with internal crystal etc.

These are available as I2C modules on the likes of eBay for only about $10 or so - cheaper then the chip by itself, and they usually have on-board button cell too.

So, my question is, can I just substitute the 3231 for the 1307 and it's battery and crystal, and have a more accurate(over time) RTC?

From what I have been reading, both the 1307 and the 3231 or 3232 use all the same addresses for time keeping, but there are battery-backed RAM address differences, but I have no plan to use those features of the 3231 - I just want it for the RTC.

So, can I connect it where the 1307 would be, or are there special commands used with the 1307 that would mean I have to use that RTC?


$10 is expensive. Look around I'm sure I paid around AU$5.00. Not at home so I can't check. Try DX.com as well as ebay.

The last 3231 I checked went for several months I had trouble detecting the time gain or loss.

As long as you stay at basic functionality of time and date the two chips are the same.

I'm not in a fit state to read data sheets so I can't give you any more today.

 
donmck

Guru

Joined: 09/06/2011
Location: Australia
Posts: 1310
Posted: 08:40pm 06 Aug 2014
Copy link to clipboard 
Print this post


Heaps on ebay, and very cheap modules, with free postage:
http://x2t.com/3231-rtc

Cheers Don...
https://www.32v8.com/1
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 09:00pm 06 Aug 2014
Copy link to clipboard 
Print this post

  BobD said  $10 is expensive. Look around I'm sure I paid around AU$5.00. Not at home so I can't check. Try DX.com as well as ebay.

The last 3231 I checked went for several months I had trouble detecting the time gain or loss.

As long as you stay at basic functionality of time and date the two chips are the same.

I'm not in a fit state to read data sheets so I can't give you any more today.



Yes, you are right. To buy just the 3232 chip is about $25(from my local supplier), so that's why I wanted to use the pre-built modules. I will try one when my UBW32 boards arrive, and I have flashed the MM firmware into it.
Smoke makes things work. When the smoke gets out, it stops!
 
donmck

Guru

Joined: 09/06/2011
Location: Australia
Posts: 1310
Posted: 09:10pm 06 Aug 2014
Copy link to clipboard 
Print this post


And if you get one with the eeprom (because it could be cheaper) here is the schematic:
http://edwardmallon.wordpress.com/2014/05/21/using-a-cheap-3 -ds3231-rtc-at24c32-eeprom-from-ebay/

Cheers Don...
https://www.32v8.com/1
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 06:26am 07 Aug 2014
Copy link to clipboard 
Print this post

All,

Please, please beware of 'cheap' modules/chips. As many of you know by now I have had many bad experiences with 'cheap' parts.

My main issue is with the current drawn - typically I find these 'cheap' modules pulling much more power than the data sheets show. For some of you this may not be a problem but ask yourself why are they pulling more power - and if so, what else do they do/not do properly?

For an RTC, you would expect uS's in 'standby' so measure it as a precaution to ensure it is what it should be.

Other 'cheap' chips have warmed up (almost too hot to touch in some cases!). All I am saying is be careful as often these 'cheap' chips are too good to be true.

Another example, there is a global shortage of MX150's (TQFP) at the moment but I have had a Chinese supplier offer me 30 at £1.55 each. Should I buy these and use them in my 44-pin MicroMitres? NO WAY!

Moan (& warning) over . . . .

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 07:10am 07 Aug 2014
Copy link to clipboard 
Print this post

Hi White,
Out of curiosity, which rtc are you using for your new scrolling dealeo with the apple remote?
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 07:23am 07 Aug 2014
Copy link to clipboard 
Print this post

@viscomjim.

I am currently using GPS to set the TIME$ & DATE$ variables and hence using the inbuilt 'timer'. The only downside to this is when power is lost meaning a GPS satellite fix is required before the time can be displayed after power is re-instated. I am however about to include a PCF8563 (as per user manual) to give an immediate display in situations of power loss.

I am debating using two MicroMites in the design - one purely extracting GPS info and passing it to the second MicroMite which, by interrupt, sets the time variable and SETTIME (if I also use the RTC chip). The second MicroMite's main function is to deal with all the display scrolling simply reading either the Time$ variable (without any delay) or the Temp data (with a minimal delay) so that the scrolling is 'smooth'.

I have spent a fair bit of time trying to do it all with one MicroMite but the scrolling is not quite a 'smooth' as I desire.

Got the red acrylic sheets to improve the readability - display looks a lot better now. Another task ahead is to heat-bend the perspex into a nice one-piece case!

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 08:28am 07 Aug 2014
Copy link to clipboard 
Print this post

White, I apologize, you did mention that gps thing on the apple remote thread (which by the way I can't wait to play with, just waiting for tsop4838s to arrive). Using two uMites is a fine idea and very cost effective also. I used two on a project and just used i2c to send the data back and forth, this off loaded a lot of stuff between the two and it worked like a charm. I based the code off of the manual as a start and went from there.

I have tried the PCF8563 hoping it would work better that the 1307, which it did, but still not quite what I was looking for stability wise. Went with the 3231 and that is very acceptable. Will be sticking to that one for sure. I hope Geoff can implement an RTC function using that chip as an option to the 8563 when the bigger badder uMites with more memory become available. For now the code on this forum works quite well with the 3231.

One more thing, I have a couple of epilog laser cutters here and if you want to design the components, I would be happy to cut a case or two for you in trade for some dot matrix code as long as you pay just the shipping. I have tons of scrap acrylic here so won't cost me but a little time. Edited by viscomjim 2014-08-08
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 08:53am 07 Aug 2014
Copy link to clipboard 
Print this post

@viscomjim.

Without continuous GPS updating an RTC, I would also use the 3231. However, for my application, the only 'drift' from the RTC would be during a power outage.

In my circuit, the RTC is updated every second (assuming satellites observed) so in theory, before a power loss the RTC will be accurate. Assuming the power outage is only a matter of minutes, then when power is reapplied, the RTC time won't have drifted too much (not even a 1307!). Therefore an immediate display of the RTC time is good enough until a satellite fix is achieved once again (about 40seconds from power up).

Nice to hear you were successful too with MicroMites talking to each other - I have now used this method on a few things to get the desired result.

One thing I use my surplus PCF8563's for is triggering a timed interval WakeUp of the MicroMite. So I'm not actually using the RTC for the built in clock function and therefore drift/accuracy is not an issue. End result is an WakeUp every x seconds/minutes to minimise current drain on battery powered MicroMite loggers.

WW


For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 09:56am 07 Aug 2014
Copy link to clipboard 
Print this post

  Grogster said   Hi folks.
So, can I connect it where the 1307 would be, or are there special commands used with the 1307 that would mean I have to use that RTC?


You can do a drop in replacement and it should go fine.
Here is my code for the 3231 that does the temperature and day of the week


Jman's code for the DS3231
No alarms or offset
Calculation to set Day of the week
Goto settime from the console will set the DS3231 with the current
time and date


' I2C RTC based On DS1307 Secs,Mins,Hours,Day,Date,Month,Year,Control
Dim RTCbuff(7)
Dim Temp(2)
Dim Days$(7)
GoSub Days
i2caddr = &h68 ' DS3231 I2C address
I2C open 100,100 ' Enable I2C
I2C write I2caddr, 0, 1, 0
I2C Read i2caddr, 0, 7, RTCbuff(0) ' Read Time
I2C write I2caddr, 0, 1, 17
I2C Read i2caddr, 0, 2, Temp(0) ' Read Temperature
I2C Close

BCDTEMP = RTCBuff(0)
BCDtoDec BCDTEMP
sec$ = Str$(decimal)

BCDTEMP = RTCBuff(1)
BCDtoDec BCDTEMP
min$ = Str$(decimal)

BCDTEMP = RTCBuff(2)
BCDtoDec BCDTEMP
hours$ = Str$(decimal)

BCDTEMP = RTCBuff(3)
BCDtoDec BCDTEMP
DayOfWeek = decimal

BCDTEMP = RTCBuff(4)
BCDtoDec BCDTEMP
day$ = Str$(decimal)

bcdtemp = rtcbuff(5)
BCDtoDec BCDTEMP
month$ = Str$(decimal)

bcdtemp = rtcbuff(6)
BCDtoDec BCDTEMP
year$ = Str$(decimal + 2000 )

t$ = hours$+":"+min$+":"+sec$
D$ = day$+"/"+month$+"/"+year$
Time$ = T$
Date$ = D$
Temp
Print "Time has been set to ";Time$
Print"Date has been set to ";Date$
Print "Today is ";Days$(DayOfWeek)
Print "Temperature is";Temperature
End


'Temperature
Sub Temp
If Temp(0) < &h80 Then
Temperature= Temp(0) + (Temp(1) / 256)
Else
Temperature=-((Temp(0) Xor &HFF) + 1) + (Temp(1) / 256))
EndIf
End Sub

'Convert to Decimal
Sub BCDtoDec (BCDTEMP)
Decimal = Fix(BCDTemp / 16) * 10
Decimal = Decimal + (BCDTEMP And &hF)
End Sub

Days:
For I = 1 To 7
Read Days$(I)
Next I
Return

Data "Sunday"
Data "Monday"
Data "Tuesday"
Data "Wednesday"
Data "Thursday"
Data "Friday"
Data "Saturday"

SetTime:
' Get time from time$ and date$
tempdec = Val(Left$(Time$, 2))
BCDtoHex TempDec
hours = hex

tempdec = Val(Mid$(Time$, 4, 2))
BCDtoHex TempDec
minutes = hex

tempdec = Val(Right$(Time$, 2))
BCDtoHex TempDec
seconds = hex

tempdec = Val(Left$(Date$, 2))
BCDtoHex TempDec
day = hex

tempdec = Val(Mid$(Date$, 4, 2))
BCDtoHex TempDec
month = hex

tempdec = (Val(Right$(Date$, 4)) - 2000)
BCDtoHex TempDec
year = hex

DayOfWeek

' Write Time to RTC
i2caddr = &h68 ' DS3231 I2C address
I2C Open 100,100 ' Enable I2C
I2C Write i2caddr,0,8,0,seconds,minutes,hours,dow,day,month,year
I2C Close

Print "0=ok 1=nack 2=timeout"; MM.I2C
Print "RTC has been set to ";Time$;" ";Date$
End

'Calculate Day Of Week TZAdvantage's DOW Calculation
Sub DayOfWeek
A = Int(14-Val(Mid$(Date$,4,2)))/12
M = Val(Mid$(Date$,4,2)) + 12*a - 2
Y = Val(Mid$(Date$,7,4)) -a
D = Val(Mid$(Date$,1,2))
Dow=(day+y+Int(y/4)-Int(y/400)+Int(31*m/12)) Mod 7
End Sub

' Convert to Hex
Sub BCDtoHex TempDec
hex = Fix(tempdec / 10) * 16
hex = hex Or ((tempdec / 10) - (Fix(tempdec / 10))) * 10
Return



Regards
Jman
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 12:39pm 07 Aug 2014
Copy link to clipboard 
Print this post

Thanks again Jman, this is great for 3231!!!!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 01:14pm 07 Aug 2014
Copy link to clipboard 
Print this post

Thanks for those replies, guys.

@ WW: I note your comments with respect to cheap modules. Perhaps it would be a better idea to design the 3232(or 3231) into the main-board with it's own battery holder etc, over using a cheap module. These are base-station PCB's, so I only need a few of them, so even if the 3232 is much more expensive by itself, it WOULD be a genuine part. Many of those cheap modules will be using IC clones. Food for thought...
Smoke makes things work. When the smoke gets out, it stops!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 01:21pm 07 Aug 2014
Copy link to clipboard 
Print this post

@grogster.
If you only need a few, is it worth applying for some samples? This assumes they send to NZ? I use to get lots of Dallas & Maxim samples either free, or just the cost of import duty.
At least these will be genuine parts!!
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 01:31pm 07 Aug 2014
Copy link to clipboard 
Print this post

Good point, well made.

I have a feeling that I have a few of these chips somewhere, that I ordered in previously, but then never used, so they vanished into the abyss that is my stock....

EDIT: Yay! Yes, I do have some. They are 3232's, genuine DS parts from Element14. A bag of ten chips. Looks like this one has just fixed itself, and I will design-in these chips, as I only need four or five main-boards. Edited by Grogster 2014-08-08
Smoke makes things work. When the smoke gets out, it stops!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 01:36pm 07 Aug 2014
Copy link to clipboard 
Print this post

  Grogster said  . . . they vanished into the abyss that is my stock....

Have a look in the abyss for some 150's. If you find any I will jump on a plane and personally pick them up (anything to save ridiculous shipping costs from NZ!)
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 11:51pm 07 Aug 2014
Copy link to clipboard 
Print this post

  WhiteWizzard said  (anything to save ridiculous shipping costs from NZ!)


Don't they have PIGEONs over there?

Mick

EDIT*** Although mine havent done too well on their flight across the Tasman, 10 days now and still not in NZ.. They get to the UK and US in less than a week generally.

MikEdited by bigmik 2014-08-09
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 12:27am 08 Aug 2014
Copy link to clipboard 
Print this post

  bigmik said  Don't they have PIGEONs over there?

Mik

Knowing my luck, there is probably a world wide shortage of pigeons too!

Perhaps Grogs could quickly train a Kiwi (bird) to fly his 150's over to the UK.
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 01:18am 08 Aug 2014
Copy link to clipboard 
Print this post

Err... Phil, bird type Kiwi's don't have wings!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 01:25am 08 Aug 2014
Copy link to clipboard 
Print this post

  paceman said   Err... Phil, bird type Kiwi's don't have wings!

Exactly . . . It will be quicker to get one to fly (by any means) than to get hold of 150D's from anyone

Simply stressing the 'hiccup' in MicroChip's supply of these devices.

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
     Page 1 of 3    
Print this page
© JAQ Software 2024