Shop OBEX P1 Docs P2 Docs Learn Events
DS1307 square wave generator? — Parallax Forums

DS1307 square wave generator?

rwgast_logicdesignrwgast_logicdesign Posts: 1,464
edited 2013-03-22 09:15 in Propeller 1
So ive been building this board the last few days and it has come time to add the RTC to it. My initial plan was to use a ds1307 on the i2c bus to save some pins, but I didn't realize it needed a 5v VCC till I went through the data sheet this morning. They way my board is set up as far as power rails is a little different than most, and I would like the clock to run even when the the 5v rail is unplugged, i know if the backup battery is used the chip will keep the time even when the 5v rail is unplugged but will the propeller be able to read write to it on backup power only, I am assuming not?

I have some DS1302 chips also so I though about just using one of those instead. Basically this really comes down to a trade off in features I want/need and the DS1307 square wave generator has my interest peeked, I am trying to figure out an application for it. It appears as though it is only able to output a set frequency, so you cant just make it pulse every hour or something like that? The only use I can figure out is to output the square wave to the propeller and use it to count the pulses in order to get timing under 1 second, In which case the prop can already do this.... I'm just trying to figure out what this could be used for and if it is worth having. Even off the wall creative uses.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-03-14 15:24
    Pages 3 and 5 of the DS1307 datasheet explains the pulse output option and the possible choices. What do you think? There certainly are tradeoffs involved between using a DS1302 and a DS1307.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-03-14 16:09
    Hmmm I have Maxims data sheet, page 3 has AC and Capacitance Characteristics, page 5 has a timing diagram and a block diagram. The only information I could find on this pin was:
    Square Wave/Output Driver. When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square-wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT
    pin is open drain and requires an external pullup resistor. SQW/OUT operates with either
    VCC or VBAT applied. The pullup voltage can be up to 5.5V regardless of the voltage on
    VCC. If not used, this pin can be left floating.

    In the pin description on page 6, then a little bit about how to set up the registers in the i2c section. This is why Im curious about uses for this pin. I tried Googling it mostly came up with irrelevant Arduino threads where they keep track of the pulses via an interrupt to get timing in fractions of a second. The propeller has more than adequate short term timing so I am not really sure what this pin would be useful for. I will be using the 1307 anyways, as it turns out my oscillators require a 5v VCC too so may as well stick with the 1307. I just feel like there has to be a use for this pin i am missing.
  • manitoumanitou Posts: 29
    edited 2013-03-14 16:31
    Well, for what it's worth, I have used the SQuare wave output pin on various RTC's to feed a high-resolution frequency measurment. Results for various RTCs, TCXOs, and MCU crystals can be found at

    https://github.com/manitou48/crystals
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-03-14 16:51
    I used the square-wave output for a prop-based datalogger, to start a sampling period every second, and a write to an SD card every minute. I also have the DS1307 providing time and date stamps, and while the prop probably could keep accurate enough time, using the square-wave output ensures that the readings stay synchronized with the time. Plus it relieves a little bit of workload from the prop.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-03-14 17:24
    It's page 5 of the datasheet that has the additional information about the pulse output. There's nothing magic about it. If it fits the needs of your application, use it. If not, don't. It was probably added to the part because an early customer had a specific use for it. That's the way these features get added ... "If you put this feature in, I'll buy 100K next year."
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-14 19:27
    The pulse output at 1Hz can provide a heartbeat for a Prop data logger or device of that sort. Prop can sleep at 20kHz and microamps of current while waiting for the 1/2 second interval to pass. Using waitpne, when the heartbeat changes state, a countdown can continue, waiting for alternating edges, or the Prop can fire up, read the RTC registers, get the work done, and go back to sleep. Waitpne allows other events to be OR'd into the mix, for fast response to events. This allows micropower operation but with good timing.

    High frequency output from the RTC pulse output is helpful if you need to calibrate the RTC against an accurate timebase, or measure its temperature sensitivity. It's easier to make that comparison at 32768Hz than at 1Hz.
  • RDL2004RDL2004 Posts: 2,554
    edited 2013-03-15 11:51
    Just as an fyi, instead of the Ds1302/1307 anyone needing a RTC should check into the DS3234/3232. These are nearly identical except they have an internal TXCO which is about an order of magnitude improvement, plus you don't have the external crystal to deal with. They cost about twice as much though and only come in SOIC, but I think it's well worth it for the improved accuracy and hassle reduction.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-03-15 16:30
    Those are nice chips :) I dont understand why they aren't on common break out board, Im doing through hole only maybe 805 passives in some places. My set up is a ds1307 with a temperature compensated DS32Khz oscillator basically the same thing as the chips you mentioned above except separate through hole components for those of us that don't want to deal with surface mount chips.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-16 09:15
    My personal favorite RTC is the Intersil ISL12020M. Also smt of course, but with built-in xtal and temperature compensation to +/-5ppm over a temperature range of -40 to +85 °C. I use the 1/2 Hz square wave output to provide a heartbeat edge to the propeller at 1 second intervals. The pulse output has more output frequencies, from 32kHz down to one per day, or match to any combination of alarm registers.
  • RDL2004RDL2004 Posts: 2,554
    edited 2013-03-16 10:02
    Intersil ISL12020M

    That one looks pretty nice, too. I'll have to keep it in mind. It looks like Mouser just started stocking the ISL12020M and it's almost $3 cheaper than the Maxim DS32xx series, but it's a DFN package and they don't have the SOIC version (ISL12022M). Maybe they'll add it soon. Digi-Key has it, but I almost never buy from there since Mouser is close and regular shipping only takes a day or two.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-16 13:44
    Digikey has stock of both the ISL12022I or the ISL12122M, or you may try for samples Intersil direct. The '22I version is an soic8 with the same layout as the DS1307, and like the DS1307 you supply the external 32kHz rock. It has all the necessary frequency compensation registers for achieving a potential +/-5ppm over temperature, but you'd have to read the data sheet carefully and have the necessary calibration setup to achieve that. Operates over a wide voltage range. The '22M version in soic20 has the rock built in and the calibration already done at the factory. Nice, worth a lot.

    The ISL12020M in the dfn20 package is soooo tiny in comparison to the soic20. Also has the built-in crystal. I do have some breakout boards for it. It is a DIP14 board that holds both the rtc and also a 4-channel 16-bit ADC (ADS1115) on the same i2c buss. precision-pal. Would something like that be of interest to you guys?
  • hover1hover1 Posts: 1,929
    edited 2013-03-16 14:34
    RDL2004 wrote: »
    Just as an fyi, instead of the Ds1302/1307 anyone needing a RTC should check into the DS3234/3232. These are nearly identical except they have an internal TXCO which is about an order of magnitude improvement, plus you don't have the external crystal to deal with. They cost about twice as much though and only come in SOIC, but I think it's well worth it for the improved accuracy and hassle reduction.

    I like the DS3234 also. I have one to try out. I like the +/- 2pmm, programmable square wave output, 2-time of day alarms, battery backup, and 2.7-5.0 volt support.

    Sparkfun has a nice breakout board WITH battery holder for a good price:

    https://www.sparkfun.com/products/10160
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-16 15:08
    The Dallas/Maxim devices are great, but their gotcha' for micropower systems is that the current drain from the Vdd supply is quite high, >100µA even in standby mode with the chip deselected. On the other hand, the timekeeping current drain from the backup battery is on the order of 1µA. I used the DS1307 on my Stamp data loggers, but had to take its Vdd power from a Stamp pin, so that I could bring that low and get rid of the 100µA drain and keep the time going from the backup battery. Luckily the SQR output for the system heartbeat continues to run. That always seemed like a design shortcoming to me. Why not allow the chip to run at lowest timekeeping current from Vdd supply? I see from the data sheet that the DS3234 has the same scheme, but of course in many systems, millipower and up, an extra 100µA here and there is not going to matter.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-03-20 00:17
    Ok I am hoping someone may know what my problem is!! I've been messing with this clock for over 2 hours and ruined my first prop chip!!! I am using Kye's 1307 object and I have tested every feature and they all work, except the square wave pin! I can set it Hi, I can set it Low and there is no problems, but when I try to generate a frequency the pin just stays low!! Ive tried pulling it up to 5v, 3.3v and using different value pull ups. At 10k the pin just stays low like I said, but when I use a 4.7k pull up or less I see a 32.7khz triangle wave no matter what values I set SQW to in to the nice serial command interface Kye wrote. I'm banging my head against the wall!
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-03-20 06:32
    There's a problem in Kye's DS1307_RTCEngine object; the clockSquareWaveOut method only ever writes $01 to register 7. In that method:
    return setRAM(7, (((state & $2) << 6 | (state & $1) | ((frequency <# 3) #> 0)))
    
    ' change to: 
    
    return setRAM(7, (((state & $2) << 6 | (state & $1) [b]<< 4[/b] | ((frequency <# 3) #> 0)))
    

    Also, if you're using #DS1307_RTCDemo, the programSQW method limits the square wave output to 1 Hz and 4096Hz. In order to get 8092 and 32768 Hz outputs, change the "& 1" to "& 3" in the line
    result := rtc.clockSquareWaveOut(str.decimalToInteger(str.tokenizeSting(0)) & [b]1[/b], 1)
    

    Shameless plug: the I2C driver in my sig contains a DS1307 demo.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-03-20 11:15
    Hey man thank you that was exactly what the problem was, I never suspected it was Kye's code. I also downloaded your object to check out, I just need something like kye's code to make testing my hardware a lot easier and faster, I will definitely be switching to a minimal i2c driver later. Can your object clock the bus at 400Khz, 1Mhz?
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-03-22 09:15
    My I2C driver has a top speed of 952KHz, and while the DS1307 acknowledges at that speed, the data is corrupt; it sends $FF for all registers. It looks like the top speed of the DS1307 is between 740KHz and 769KHz. The datasheet lists 100KHz as the max. clock rate.
Sign In or Register to comment.