Shop OBEX P1 Docs P2 Docs Learn Events
Trying to get back in the game — Parallax Forums

Trying to get back in the game

koolvistakoolvista Posts: 16
edited 2014-12-24 08:29 in General Discussion
After a 9 – 10 year hiatus of working on Basic Stamp/Picaxe/Scribbler 1/Boe-Bot I am trying to get back ‘in the game’.
As I approach 3/4 of a century age I decided I need to get some brain stimulation and try to keep my brain active.
As I was doing some packing up of my stuff for a move, I found some SX modules and boards. I have the following hardware.
3 – SX 18 modules
4 – SX20 modules
2 – SX 48/50 Proto boards
1 – SX Tech board
1 – SX Key (serial connection)

I would like to use this hardware in projects, realizing that it is ‘out-of-fashion’.

Now for my questions;
1. Can the SX software be used on Windows 7 or 8.1?
2. Can this hardware be used to drive the NeoPizels LEDs?
3. Can this hardware be used with I2C hardware like a Real Time Clock?
4. I ordered and received a Parallax USB to Serial unit. Can this be used with SX-Key mentioned above?
5. Probably a hundred other questions.

My project I would like to do is a Resistor Color Code clock using the NeoPixels and RTC.
The time and date would be displayed as the different colors.
I have 13 Parallax NeoPixels, 2 – Adafruit 8 NeoPixel strips, and 30 ‘raw NeoPixels.

I was originally going to try and use a Propeller for this project but looking at SPIN code
made my head spin. I think I can eventually learn SPIN but using the SX/B software seems easier
since I had experience using Basic previously even thought it was looonnng time ago.
I have limited time to work on my project since I am planning and getting ready for a move
and my 75 year brain works against me.

Any input is welcomed, thanks.
«1

Comments

  • Ken GraceyKen Gracey Posts: 7,392
    edited 2014-12-12 08:14
    Hey koolvista,

    My dad is 78 and he programs most everything made by Parallax, but excelled with the BASIC Stamp and SX line.

    I could use that lot of SX hardware you have for customers who need tools and hardware. We've pretty much sold out of the SX programming tools (we still have chips) and customers are always asking if we have any more SX-Keys.

    Should you be interested, I'd be happy to trade your SX hardware for a Propeller setup consisting of a Propeller Activity Board or two. But don't do this on my account, please - just be sure you really want to go that way. Heck, you might want to just buy a Propeller Activity Board on sale now and get started, keeping your SX hardware too!

    Ken Gracey
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-12 08:32
    @Ken
    I am hanging on to Both my SXKeys. But why not recommend the Fluffy 2 Scenix Programmer to those that are SXKey-less?

    http://www.semis.demon.co.uk/Sx/SXmain.htm

    And yes, the SX software will install in Windows 7. I have no idea what 8.1 will do. But swapping out for Propellers might be much more fun -- lots of power, able to do video on a VGA or in NTSC, programs in several languages (SPIN, PASM, Basic, C, Forth), and much more.

    Not much activity in the SXes here at this point. You will make more friends using a Propeller.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-12 08:43
    koolvista wrote: »
    1. Can the SX software be used on Windows 7 or 8.1?
    2. Can this hardware be used to drive the NeoPizels LEDs?
    3. Can this hardware be used with I2C hardware like a Real Time Clock?
    4. I ordered and received a Parallax USB to Serial unit. Can this be used with SX-Key mentioned above?
    5. Probably a hundred other questions.

    Short replies
    1. Yes to Windows 7, and probably yes to Windows 8.1
    2. Don't know what NeoPixel LEDs are, but I am pretty sure they will work.
    3. I2C works fine with the SXes
    4. USB to Serial will work with the SXes
    5. Ask some more.
  • PublisonPublison Posts: 12,366
    edited 2014-12-12 08:53
    Welcome to the forums!

    The latest version of the SX software:

    http://www.parallax.com/downloads/sx-key-editor-software

    works fine on my Windows 7 machine.

    I just, (minutes ago), loaded onto a HP Stream tablet, and seemed to install correctly. I can't try out the USB connection yet as I am waiting for a OTG cable.

    I see you have a serial SX-Key. You might want to grab a newer USB SX-KEY:

    http://www.parallax.com/product/45214

    They are on sale until 12/15. The would fit with the newer computers out there.

    As Ken mentioned, have a look at the Propeller. It is an awsome MCU!

    Jim
  • wasswass Posts: 151
    edited 2014-12-12 08:56
    Years ago I started with the STAMP and much later on moved to the SX then dabbled in the Propeller world. I love programming in SX/B. It's a lot like STAMP programming but becasue the compiler is simple and EPROM is small it requires more creativity in coding. If you get stuck and can't fit your code into the 2K space, you can mix in SX assembly code really easily. The form factor of the 28 pin DIP SX is great for most projects (you can occasionally find the olf 18 pin DIP version too).

    The IDE (aka the software development environment) runs fine in Windows 7 (I haven't checked 8.1, but I'll bet it's fine there too). It's also really simple to use and has a debugger if needed. You'll spend 10 minutes learning it and the rest of the time concentrating on programming. Yes, you can program the NeoPixels with SX/B as well as I2C RTC's, etc.. Of course it does RS-232 communications too, it works with every USB to RS232 converter I've tried.


    I would love to have seen the SX line live on and grow. It's so much better than the STAMP for small, real-world projects and much, much cheaper. It's not that the SX is "out of fashion" so much as it's out of production. This happened several years ago so most people that were using it switched to the Propeller or some other other platform. The support forum for the SX still exists but is not active these days. Still, I think if you choose to use the SX people here will read your posts and respond I'm sure. Once you get going with it I think that you'll find you'll be able to master it after a few projects.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-12 09:21
    Did you ever use SX-B (a form of Basic)? Or are you strictly an Assember user?

    I believe SX-list is still active. www.sxlist.com

    If you can handle the Interrupt Service Routines for I2C, SPI, and Asynchronous Serial (for RS-232 and RS-422), there are a lot of things you can do.

    Abebooks has copies of Guenther Daubach's "Programing the SX Microcontroller" that are used for $4 USD plus shipping.

    http://www.abebooks.co.uk/servlet/BookDetailsPL?bi=13987212730&searchurl=sts%3Dt%26kn%3DParallax+programming+SX

    I think the SX18 and SX20 are all gone. (I have a tube of 25 SX18 chips here).
  • PublisonPublison Posts: 12,366
    edited 2014-12-12 10:28
  • koolvistakoolvista Posts: 16
    edited 2014-12-12 11:53
    Replies To:
    Ken Gracey – It is great to hear that at 78 your Dad can still play with this ‘stuff’
    Your trade offer sounds good, but I think I will try the SX route for now as it
    has Basic and at one time with the Stamp I learned a lot so I thought that
    would be easier to learn. I still like to learn how to program the Propeller
    but I think it will have to wait until after I move as I can only try to learn one.
    I do have 2 Propeller Quickstart boards and 1 Propeller Demo board. My
    My total experience with Propeller is downloading the Demo program
    for the Quickstart board and running it one time. This is more than I have
    with the SX boards.

    Loopy - Thanks very much for your answers to my questions. No, I never used SX/B but
    did use Basic on the Stamp and Picaxe (a long time ago). I also wrote Assembler
    programs (trial & error for my own use) for the IBM PCJR after I retired in 1992.
    Great fun doing all that back then don’t know if I can learn anything new but
    will give it a try. Also, thanks for the heads up on SX programming book.

    Jim Publison - Thanks Jim for your Input. I do have the USB to Serial gizmo (just received
    the other day) so that should plug into serial SX- Key and also used for
    serial input on my Basic Stamp stuff that I will get into again after I move.
    (South Florida to Central Florida).
    Thanks for the links.

    wass – Thanks for telling about your experiences with the SX and the SX software. I hope
    as I start to use the software that things come back to me from my Stamp days

    I wish I knew how to use the ‘Quote’ thing, something else to learn, my gray hair will be
    getting grayer after all this.


    Thanks to everyone for their input.
    Bob aka southernbob
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-12 12:02
    Just one more thing to tempt you to use the Propeller, PropBasic. Bean wrote sx/b and then did PropBasic for the Propeller, if you liked sx/b then I think you would like PropBasic. I am surprised that the previous seasoned thread responders did not mention this.

    Ray
  • PublisonPublison Posts: 12,366
    edited 2014-12-12 12:11
    The forums are going through an upgrade , so the "Quote" may not be available. Not to worry, you post came throug A-OK. :)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-13 02:27
    Hi all,

    Here is a nudge to get discussion moved over to the SX forum, where it belongs

    http://forums.parallax.com/showthread.php/158635-RAM-comparison-SX28-BS2-and-the-Propeller-1?p=1305947#post1305947

    Simply put, the Propeller 1 has 32K bytes of RAM for combined program and variable allocation. In many cases, larger table of variables are useful and I have generate useful table up to 4K that worked well controlling complex stepper motor motions.

    On the other hand, the SX-28 has merely 136 bytes of variable space and the BS2 has only 32 bytes of the same.

    Choices eventually come down for the need of more variable space resources.

    And of course, the Propeller just runs faster in special instances; such as video and multi-tasking.

    But I do admit, the Propeller runs at 3.3VDC and the SX can run at 3.3VDC or 5VDC. Some of us just want to stay with 5VDC.
  • koolvistakoolvista Posts: 16
    edited 2014-12-13 05:31
    On this day 12-13-14 (month,day.year) I want to thanks all replier's (is that a word?) to my Post. I have to try
    and decide whether to pursue the SX option or the Propeller option. I have downloaded and sent to my Kindle and
    Android tablets the G. Daubach manual on the SX/B now I have to find time to read it. The Propeller option
    is more confusing to me since to program it there is SPIN, PASM, Propeller IDE, Simple IDE, (are they one
    and the same?), BasicProp, and probably a few others. I have never programmed any higher language.
    only Stamp Basic and PC Assembler and that was years ago.

    Questions:
    1. Can the Propeller Mini do I2C since the pins devoted to I2C aren’t brought out (before finding the SX hardware
    I was considering getting a Mini but saw the I2C pins weren’t available)?

    2. If I decide to go with the Propeller, what programming would be best for a beginner (also long term)
    to go with?
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-13 06:24
    All answers are my opinion only.
    1. Can the Propeller Mini do I2C ...
    If you are planning on doing breadboard work, I would suggest going with the PropStick-USB.
    2. If I decide to go with the Propeller, what programming would be best for a beginner (also long term)
    to go with?
    This is a much tougher question to answer, it can lead a language war, even here. In the beginning of Propeller time, you could choose between Spin, PASM or both. Today we have a few more choices, depends on how much time you want to devote to this hobby.

    I personally started with Spin, just like everybody else, but now I prefer C, because now there are a lot of drivers available, especially for the Activity Board. You also have access to learn.parallax.com, which has lessons for the C beginner.

    There are other choices, you might want to do a search of the propeller forum for PropBasic, like I mentioned in the other thread, this is basic to be used for the Propeller. Or you can go with Forth, if that suits your tastes. Lots of choices, you will have to do some research, also keep in mind there is a Propeller II that is going to show up one of these years.

    Ray
  • RS_JimRS_Jim Posts: 1,766
    edited 2014-12-13 06:32
    koolvista wrote: »
    On this day 12-13-14 (month,day.year) I want to thanks all replier's (is that a word?) to my Post. I have to try
    and decide whether to pursue the SX option or the Propeller option. I have downloaded and sent to my Kindle and
    Android tablets the G. Daubach manual on the SX/B now I have to find time to read it. The Propeller option
    is more confusing to me since to program it there is SPIN, PASM, Propeller IDE, Simple IDE, (are they one
    and the same?), BasicProp, and probably a few others. I have never programmed any higher language.
    only Stamp Basic and PC Assembler and that was years ago.

    Questions:
    1. Can the Propeller Mini do I2C since the pins devoted to I2C aren’t brought out (before finding the SX hardware
    I was considering getting a Mini but saw the I2C pins weren’t available)?

    2. If I decide to go with the Propeller, what programming would be best for a beginner (also long term)
    to go with?
    In answer to question 1, any two pins can be used as i2c pins, and yes you can run more than 1 i2c at the same time.
    2, I am nearly 73, and my language of choice is Spin. Like you, I have no formal training in any software and with obex and the propellar forum support, I have been able to do most of what I want to do. just wish I had more time to do it!
    Jim
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-13 06:45
    I suspect that your reluctance to use the Propeller is due to having a lot of comfort with BasicStamps and Basic in general.

    Historically, the BS2 was a huge success and so there was and still is a lot of material provided for it. And historically, just about everyone has used Basic in one form or another.

    Assembler on a PC is quite a different animal that assembler on an SX. It becomes obvious when you look at the fact that all Assemblers are very close to their CPU architecture and a PC is comparatively complex device with BIOS calls and storage. The SXes are amongst the small end of the CPU architectures.

    Dealing with the language barrier...
    If you want to stay with Basic, by all means do so. SX/B and PropBasic both had signicant contribution by Bean. So he may help you. The SX/B ended up with documentation the compiler and is no where near as in depth as what PBasic provides. I am not sure of the status of PropBasic.

    If you want an interactive language rather than a write-compile-load language for the Propeller, there are some. I find that the interactive languages are more fun than write-compile-load languages; and adequate for many learning sessions.

    You might consider Forth on the Propeller for an interactive language. There are actually 3 choices --- Pfth, PropForth, and Tachyon. All are pretty good, but styles of support drastically varies. I have some experience with all three, and strong personal preferences about which I like (which I won't share). But the simple fact is Forth on the Propeller might be a real confidence booster as results are immediate and it certainly allows one to explore the Propeller's potential in a very user-friendly way.

    I hate to believe that there is a SPIN barrier as a language...
    If you don't know where to begin, there is a SPIN tutorial in pdf form that came out of the Ver 1.0 of Propeller Manual. They took this out of the up-dated manuals as of Ver 1.1, and when to providing the tutorial in the compiler (like was done with SX/B). Personally, I'd rather have a PDF than documentation within the compiler, but these choices were made by others.

    If you use SPIN, you really need to learn to use the OBEX for objects that help you build.
    And if you want to learn PASM, it really requires you learn to manage SPIN first as even the Propeller's PASM is compiled within a SPIN code object.
  • RS_JimRS_Jim Posts: 1,766
    edited 2014-12-14 05:54
    Ken Gracey wrote: »
    Hey koolvista,

    My dad is 78 and he programs most everything made by Parallax, but excelled with the BASIC Stamp and SX line.

    I could use that lot of SX hardware you have for customers who need tools and hardware. We've pretty much sold out of the SX programming tools (we still have chips) and customers are always asking if we have any more SX-Keys.

    Should you be interested, I'd be happy to trade your SX hardware for a Propeller setup consisting of a Propeller Activity Board or two. But don't do this on my account, please - just be sure you really want to go that way. Heck, you might want to just buy a Propeller Activity Board on sale now and get started, keeping your SX hardware too!

    Ken Gracey
    Hey Ken,
    I have 2 SX keys that I am willing to part with! See PM.
    Jim
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-12-14 10:51
    decide whether to pursue the SX option or the Propeller option.

    Go with the Propeller. The SX, for all intents and purposes, is dead (Editorial: Ubicom sucks), hence you won't find any new conversations about it here in the forums.

    1. Yes, the Propeller can do I2C on any set of pins. Many of us have written I2C drivers for the Propeller. Mine (and I suspect the others) are used in commercial products.

    2. Stick with Spin. It's elegant, easy to learn, and the only language that does not have to be crowbarred into the Propeller. It was designed for the Propeller, and allows one to easily learn and exploit the Propeller's architecture. After getting proficient in Spin (which does not take long), it will be easier to use the other languages.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-12-14 15:03
    If it were me I would take Ken up on his offer. That way, you get something that you can use for many years to come and Ken can satisfy his other customer(s),
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-15 00:04
    I previously mentioned that the SX-28 has 136 bytes of RAM for variable space. (also the SX-48 has about double that); whereas, the Propeller has 32kbytes of hubRAM to deploy for combined program and variable space.

    About the ONLY real reason to stay with the SX-28 is a desire to learn how to create and manage Interrupt Service Routines. The Propeller has true parallel processing and avoids using interrupts.

    I think most of us are happy to put interrupts behind us in exchange for full-duplex serial, bigger i/o buffers, generally more speed, and far more project diversity.

    Nonetheless, I do hang on to my own SXes. What's paid for has a way of nagging one into a desire to fully master it. Of course, I have on my BasicStamps for similar reasons.

    With the BasicStamps, they can often make quick work of a tiny task without much thought. Or they are easily shared with a friend that desires and easy starting point. I can't say that is the same with the SXes. I feel that SX/B was a bit confusing compared to PBasic (as it required some knowledge of clock timing). And Scenix/Ubicom made example code horrible to read by trying to make all demos conditional to work with all chips and any crystal speed. Guenther's book is a much saner entry point.

    Still, I try to be open-mined about people wanting to learn with what they have.
  • koolvistakoolvista Posts: 16
    edited 2014-12-15 12:40
    I decided to try both the SX and the Propeller with a little more emphasis on the Propeller. I set
    up a temporary work table with both type of boards. I also put a couple of my Basic Stamps/Scribbler1
    projects on the work table to take a picture of the old and the new. Hopefully I can attach a picture of it.
    Thanks for all the comments.
    Parallax Hardware_1.jpg


    1. Propeller Quickstart board.
    2. Propeller Demo board
    3. SX Tech Board
    4. A 3.5 volt & 5 volt power supply plugged into small breadboard
    5. Parallax USB to Serial adapter
    6. Dial-a-voltage power supply (3/4.5/6/7.5/9/12 volts)
    7. Scribbler1 with target sensing tower
    8. top of tower for #7 with IR sensing (control with remote)
    9. Basic Stamp 2P board with everything I could think of connected to it.
    PcJr IR Keyboard, LCD display, RTC w/battery, Agilent displays,Dallas Static
    memory w/battery, LEDs, switch inputs, serial connection to DOS PC, etc
    10. PcJr IR keyboard
    11. BOE-Bot
    12. IR Sensor for keyboard from IBM PcJr
    13. LCD display
    1024 x 768 - 155K
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-15 18:43
    The OBEX for the Propeller has some Real Time Clock objects in Spin that might be exactly what you need to get started with the project you first mentioned.

    Much depends on your choice of a RTC chip.

    You just have to be careful to add a series resistor (3.9K to 4.7K will work fine) on any 5VDC logic attached to Propeller inputs. Going the opposite direction does not require resistors.
  • koolvistakoolvista Posts: 16
    edited 2014-12-16 12:28
    Thanks Loopy, I did find a RTC “driver” for the DS1307 in the OBEX which is what I used in my
    Stamp 2P board shown in a previous post. So, I ordered one of these board on EBAY.

    Arduino I2C RTC DS1307 AT24C32 Real Time Clock Module For AVR ARM PIC SMD

    Hopefully it will work with the Propeller or SX, if not it wasn’t that expensive.

    I was also wondering whether the Propeller itself could be used as a clock instead of using a RTC.
    I was also wondering whether a Atomic Clock Module (US – WWVB signal) could be used.
    The only module I could find was from Merry Ole England (EBAY). Of course right now my
    knowledge of SPIN/Asm is about as confusing as Einstein theory on ‘Worm Holes’ (saw
    a program on History Channel at lunch time about that, and how Alien spacecraft could
    use that method to travel thru space). Over time I may be able to somewhat master SPIN
    but I don’t think I will ever understand ‘Worm Holes’
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-12-16 12:34
    Hopefully it will work with the Propeller or SX, if not it wasn’t that expensive.

    The clock/eeprom module doesn't care which microcontroller it's attached to; I use the DS1307 in many Propeller designs -- like this one:

    -- http://www.cameraturret.com/genesis.htm#Camera

    Let me editorialize here: The Arduino is like a plague; okay, not deadly, but something being branded "Arduino" is meaningless -- intended for a vast majority of the Arduino audience that doesn't want to be bothered learning about components.

    I was also wondering whether the Propeller itself could be used as a clock instead of using a RTC.

    Absolutely -- done it dozens of time (and, depending on code construction, one can do a simple RTC without consuming another cog). The advantage of an external RTC is date functions and battery back-up of time and date when the rest of the system is powered down.

    Of course right now my knowledge of SPIN/Asm is about as confusing as Einstein theory on ‘Worm Holes’

    This is temporary (won't last forever) and temporal (in your head).

    Do you know why that plague called the Arduino spread so fast? Because they teamed with O'Reilly publications to tell everybody it's "easy." Smile! I was trying to port some candle code I do in the Propeller to the Arduino and wanted to jump out of my window. The only reason I didn't is that I live on the second floor and it just would have hurt (not put me out of my Arduino misery).

    Take it from me -- an actor (how many rocket scientists do you see on the red carpet?) -- the Propeller is easy to program. And five minutes after you've started when you want to do something substantial, the Propeller is a hell of a lot easier than the Arduino . Period.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-16 13:12
    If it says Arduino device, you may have to do a wee bit of reverse engineering.

    So far everyone of the Arduino add-ons I have purchased came without documentation and often with a manufacturer that seems to not participate in the World Wide Whatever.

    It will work fine. Dallas Systems documents the chip. You might have to poke around on the internet for someone that already figured it out.

    I must admit that I got spoiled by Parallax rigorously documenting everything they sell.

    I do admit I have one of those Arduino RTC boards around here --- too inexpensive to pass up.

    ++++++++++++
    You really have to options with using it.

    A. Write a program to read once at start-up and have the Propeller run a clock internally that never calls it again unless power is lost.
    B. Write a program that checks with the RTC each and every second for an update.

    Option A might be a bit more interesting. It is the solution I would prefer.

    Setting the time in the RTC is yet another issue, and that can almost be a separate program unto itself.
  • Heater.Heater. Posts: 21,230
    edited 2014-12-16 18:10
    Loopy,

    Another option:

    C) Write some code that reads time from the RTC. Call that whenever your program actually needs to know the time.

    I'm not happy with your option A) as it means I have to have Propeller code that counts seconds, minutes, hour, date etc to maintain a time/date value. Why do that when the RTC chip does it already? Especially becomes a pain if I want to have all COGs paused for power saving or want to slow the Prop clock for the same reason.

    I'm not happy with your option B). Polling anything is inefficient and in elegant. I can see that it might be required if the process that needs to know the time also needs to loop really fast and has no time for reading the RTC directly.
  • koolvistakoolvista Posts: 16
    edited 2014-12-17 11:51
    Here is my initial thinking of what is needed for my Resistor Color Code Clock;

    1. A main section(cog) which will control everything.
    2. A section (cog) to control the RTC and report back to the Main section when a new minute has occurred.
    3. A section(cog) to update the RGB LEDs every minute plus day/month
    4. A section (cog) to change the time/date on RTC. I was thinking of using a Propeller Quickstart and using
    the touchpads as slow/fast change of time and date.
    I am not sure at this point, in my Propeller education, about cog-to-cog communication.
    I need to study more code and the manual,

    Using 8 RBG LEDs Such as Adafruit strip of 8 NeoPixels or 8 Parallax WS2812B modules.
    High          Low          High         Low       High        Low      High         Low
    Month       Month       Day           Day       Hour       Hour    Minute     Minute
    Digit          Digit          Digit         Digit        Digit       Digit     Digit        Digit
    
    I wanted to use 8 boxes with the colors in them as the example but I don’t seem to have a ‘Paint’ program,
    so I hope the following made sense.

    Example:
    HMD = Brown
    LMD = Red
    HDD = Brown
    LDD = Violet
    HHD = Black
    LHD = Green
    HMD = Yellow
    LMD = Orange

    Month = 12
    Day = 17
    Hour = 05
    Minute = 43
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-17 20:41
    Hi,
    I guess you are thinking that reading the RTC every minute is going to gain you accuracy. Or it is going to conserve resources on the Propeller. I doubt that either is really going to be achieved.

    I would read the RTC once at power up and convert the day and date to one 32bit number representing seconds (in Unix Time) - http://en.wikipedia.org/wiki/Unix_time, set up a Propeller 'tick' for each second to advance the Unix Time number.

    That would be the core of your clock inside the Propeller, just a second tick and one 32bit register representing time.

    From there, you could do very simple conversions to get the time. Calendar conversions would take a bit more code due to the 365 day year and leap year.

    The advantage with Unix Time is that you can use it for timers, clocks, and/or calendars. And you learn that a 32bit clock is much easier than the 8bit format that the RTC provides. In other words, it will be a lot easier to extend your code. AND, you will waste a lot less time and code resource that reading the RTC every second would require.

    I suppose you could check RTC if you feel the Propeller is less accurate, but the reality is they are just about the same. So why bother?
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-12-18 19:42
    If you use unix time, updating the clock every second is as simple as this:
    VAR
    
      long time ' unix time
      long cnt2 ' the next time we should increment time
    
    PUB InitClock ' you probably want to merge this into your main init function
    
      time := getUnixTimeFromWherever
      cnt2 := cnt + clkfreq
    
    PUB UpdateClock ' updates clock
      repeat while cnt-cnt2>0                           ' loop in case lag > 1 second
        cnt2+=clkfreq
        time++
    

    Call UpdateClock as often as you want - it can be more or less often than every second, as long as you call it at least every 2^31ish ticks (~25-30 seconds).

    In your case of your clock, you can replace the repeat while with an if because you will always be calling this function at least every second, but as a general solution for unix timekeeping without using a separate cog, you should normally use a repeat while here.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-12-19 02:55
    I just took a peek at the DS1307 data sheet, and as I suspected, seconds, minutes, hour, date, month, year, and DOW are all stored and accessed separately as a mix of bytes (8 bits), nibbles (4 bits) and other lengths (5, 6, and 7 bits).

    So, just to get TIME, you have to read three 8bit registers and convert over to Unix Time. DAY and DATE even require more reads. Synthesis into UnixTime is going to be a little tedious. (I really wish that someone would make a UnixTime RTC that just provides one 32bit Long)

    Making the clock code is the easiest part. It just has to increase at one second ticks.

    Setting the DS1307 and/or setting the Propeller in UnixTime are the bulk of the work. In theory, one could set the DS1307 from something else, like a BS2 and it would keep time while being transferred physically from one device to another.

    For the DS1307 (and maybe the older DS1302), the format is this

    Seconds (7 bits total) out of a byte read.
    Minutes (7 bits total) out of another byte read.
    Hours (6 bits for the actual hours plus one bit to flag 24/12 hour format)

    I suppose that some feel strongly that once they finally got the DS1307 providing info, it is just easiest to set up a cycle to re-read it every so often. But you are going to have to select a polling cycle (1 second, 10 seconds, 30 seconds) and be late by that amount. And you are going to have to store Seconds, Minutes, and hours separately. Since the Propeller is a 32bit machine, this becomes a bit of a nuisance.

    So I go with a 'one read' at power up and conversion to UnixTime. If the set time is not quite right, you can tweak the Unix time by adding or deducting from what was read.

    And, it any event --- setting the clock still remains more code work than reading the time. The 8 bit registers of the RTC devices never envisioned how a 32bit device might come along and make everything simpler.
  • Heater.Heater. Posts: 21,230
    edited 2014-12-19 04:59
    What's the problem here? Does one need Unix time ticks? Or does one just want to know what the time is? How accurate does it need to be?

    A chip like the DS1307 only has a one second resolution. So if that is good enough just read it when you need it.

    The DS1307 has 8 bytes of interesting data. 64 bits clocked at 100KHz can be done in less than a millisecond. That's a lag three orders of magnitude smaller than the available clocks resolution which should do nicely.

    Now. If one really wants time in terms of the unix epoch that is not exactly hard. Assuming one is content with a solution that only works till 2099, uses only UTC and knows nothing of daylight saving, one can use solutions like this: http://codereview.stackexchange.com/questions/38275/convert-between-date-time-and-time-stamp-without-using-std-library-routines

    I'm sure other solutions can be found. date/time to epoch and the inverse conversion would make a nice object for OBEX.
Sign In or Register to comment.