Shop OBEX P1 Docs P2 Docs Learn Events
Huge program plus a DS1302 — Parallax Forums

Huge program plus a DS1302

RandyRandy Posts: 79
edited 2006-04-11 02:26 in BASIC Stamp
I have a project I've been working on for a long time. It measures, displays and stores time and temperature information from eleven sensors. It has an A/D converter, eleven temperature sensors, two Stamps, a clock and a display. It has been pieced together and modified to merge as I built and tested the circuit and the programs in sections. Like many of us "stampers", this is a hobby. I am learning as I go and often don't have time to work on it for months allowing me to forget half what I had learned.·The hardware is pretty straight forward and compact but the program has gotten huge and I still want to add to it. Storing and comparing data takes a lot of precious memory and at some point I would like to add an EEPROM and also use StampDaq, but before that I need to make the program I have more compact. For all the articles I have seen on DS1302 clocks, I've found none that use alll of the chips time and date functions and can be set buttons rather than a PC. This project lives out in the world un-tethered to a computer. I like what my clock setting program does and I think it is user friendly but there has got to be a better way.
Of far less importance, but this bugs me, I never did get the backup charging function to charge the capacitor. I tried every combination of 1s and 0s that would fit but it never did·charge. If you look at the schematic I found a way around it, the clock maintains time for days without power, but I'd still like to know why it won't work from the chip's circuit. I am also suspicious that the SELECT CASE and·STORE routines can be more efficient. Some day I would like to add an EEPROM and give myself a new headache but I would like to learn a better way of what I have before I dive into that pond. So if any of you experienced program writing gurus are fool enough to take the time to look at the attached programs and make suggestions I would be grateful. I have aworking model that has been in use for months. I·periodically·comment out some functions, program a Stamp for the specifics I want to see, and swap Stamps. The clock has a backup power source so I can put in a Stamp, set the clock, remove power from the rest of the circuit, change to a Stamp without the clock setting program, turn it back on with the·new functions and still have time and date. The program is so bloated it stil limits what I can do. Sorry about the long intro but I think this is the minimum explanation to understand what I want this to do. I am not able to check responses to my question very regularly but will be happy to provide more info if needed. Like my programing I can't be succinct.
Randy

Comments

  • NewzedNewzed Posts: 2,503
    edited 2006-04-08 23:01
    For a starter, I would suggest you switch to battery backup for the clock and eliminate the charging routines.· I have several DS1302s, all with a backup battery.· Batteries are good for about seven years.· Here are the Digikey part numbers for the battery and the holder:

    attachment.php?attachmentid=74063





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
    363 x 46 - 554B
  • FORDFORD Posts: 221
    edited 2006-04-10 08:40
    I havent got time to read your stuff sorry, but this has worked on hundreds of our systems for around 7 years.
    We use a supercap, and it holds the time for about 3 - 4 weeks without power.

    Sorry if the code is a bit meaningless, its mixed in with heaps of other stuff (keypad input and lcd output) which would just make it more confusing, so I have just cut the bit out that actually writes the time / date / setup to the ds1302.

    It is a very reliable timekeeper.

    Code below,
    Cheers, Chris

    >>>>>

    UPDATE:
    TIMER.LOWBYTE = $10 'clear write protect bit in control register
    TIMER.HIGHBYTE = %00111
    GOSUB writeRTC
    TIMER.LOWBYTE = %10100111
    TIMER.HIGHBYTE = %01000 'enable trickle charger, 1 diode, 8K resistor
    GOSUB writeRTC
    TIMER.LOWBYTE = %00010011
    TIMER.HIGHBYTE = %00000 'set SECONDS
    GOSUB writeRTC
    TIMER.LOWBYTE = LITCT.LOWBYTE
    TIMER.HIGHBYTE = %00001 'set minutes
    GOSUB writeRTC
    TIMER.LOWBYTE = LITCT.HIGHBYTE
    TIMER.HIGHBYTE = %00010 'set hours
    GOSUB writeRTC
    TIMER.LOWBYTE = LCDTIME.HIGHBYTE
    TIMER.HIGHBYTE = %00011 'set date
    GOSUB writeRTC
    TIMER.LOWBYTE = LCDTIME.LOWBYTE
    TIMER.HIGHBYTE = %00100 'set month
    GOSUB writeRTC
    TIMER.LOWBYTE = CAP
    TIMER.HIGHBYTE = %00110 'set year
    GOSUB writeRTC

    TIMER.LOWBYTE = $80 'reset write protect bit to "1" in control register
    TIMER.HIGHBYTE = %00111
    GOSUB writeRTC
    GOTO EXITCYCLE

    WRITERTC:
    HIGH Res1302
    SHIFTOUT datapin, clock, LSBFIRST, [noparse][[/noparse]%0\1,TIMER.HIGHBYTE\5,%10\2,TIMER.LOWBYTE] 'write instruction to ds1302
    LOW Res1302
    RETURN
  • RandyRandy Posts: 79
    edited 2006-04-11 02:26
    Thanks Newzed and Ford for the reply. As far as a battery is concerned that might be simple but a good part of this project was to see what I could do - the learning thing. To charge it without the chip's circuit only cost me a resitor and a diode. I am using a super cap which is a bit over kill for this particular project. It is in a facility with a backup generator so it would not see more than about ten seconds without power if there was an outage. I have only tested it for a couple of days without power and it was fine. Ford the binary sequence I wanted to use was %10100101 which should have been the same as yours except for a 2K resistor. I also tried 4K, 8K, 2 diodes, msb first, msb last and other combos that were essentialy random trying to figure out what I was doing wrong. I am guessing it is something else in the routine but it accepts everything else perfectly. Without seeing the rest of your code which might explain the question of -·whats with the low and high bytes adding up to 13 bits? I get the one 8 bit byte but what·are the other 5 bits for? Thanks to both of you for the ideas. Randy
Sign In or Register to comment.