Shop OBEX P1 Docs P2 Docs Learn Events
Accurate track of time while doing something else? — Parallax Forums

Accurate track of time while doing something else?

GenesisGenesis Posts: 42
edited 2005-12-27 23:12 in BASIC Stamp
Hi folks...

I don't think this can be done, but I thought I'd ask.... [noparse]:)[/noparse]

My application needs to be able to set an output high, and then come back at it after some period of time and turn it back low.

The duration exceeds that of the "PULSOUT" command.

What I've been doing is:

HIGH DEFINED-PIN
PAUSE MILLISECONDS
LOW DEFINED-PIN

Which works fine.

However, what I'd like to be able to do is go off and run other parts of the program, and then determine if "X" milliseconds (or more) have elapsed.

The DS1307 would at first blush appear to have what I need on-chip for a polling implementation but on second look it appears that the resolution is too fine, plus there is no latch (its a square wave output) which gets me in trouble on both counts.

Also, there is a potential further "gotcha" that I can see here in that writing characters to a serial LCD (for example) potentially exposes you to a long period of time during which poll status is not checked (e.g. write 10 characters @9600 bps, you are "unpolled for as much as 10ms) which leaves you with the distinct possibility of "missing" one or more poll events.

Finally, the poll-run is not an interrupt, so state is not saved - you transfer ocntrol but can't get back to where you were, since you don't know where you were when the poll "hits".

Am I pretty much square on this?· My first blush was that I could get more-or-less what I wanted with polled inputs, but the more I look at it the more it appears that this is unrealistic, and that I probably need to feed the SQW output from the DS1307·into a counter with an enable controlled by the BS2, and then read that back to determine "where I am" in terms of elapsed time.
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-27 02:27
    With such strict timing requirements, this sounds like something the SX might be better suited for.· Have you checked out what can be done with the SX, especially using SX/B?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • GenesisGenesis Posts: 42
    edited 2005-12-27 03:23
    Its not really a matter of a strict timing requirement - its a matter of knowing where I am in terms of elapsed time with some manner of determinism, and with a finer resolution than seconds. Accuracy in the tens of ms range is plenty good enough.

    The 2pe is extremely useful to me as it has onboard EEPROM for data logging, which is also part of this, and it also has very "nice" power consumption numbers. It also has returned impressive development speed thus far!

    I can "get there" by using HIGH/PAUSE/LOW, but it means suspending execution of other things during that interval. Ideally I'd like to be able to recognize a button press and respond to it while the output in question is "on"; that means being able to set it and continue execution, then check back for a timer to see if it has expired.

    It may be that what I need to do is add an off-board programmable timer that I can load with the desired "countdown", use the DS1307s SQW output as a clock into that chip, and then have the output from the timer wired to an input. This would give me an independant one-shot programmable timebase with resolution closer than seconds.

    That'll definitely do the job but I'm trying to avoid it if I can. If I can't, well, then I can't!

    The SX chipset at a "raw" level will definitely do the job; perhaps down the road that's a second - or third - cut at this beast.... looks like the SX48 is the chip that's ON the 2pe, if I read the part numbers right (squinty eyes these days - I'm not 20 any more!); I may end up there somewhere down the road, but for the present I'm trying to avoid it.· Certainly at a production level the pricing is attractive - if this thing "goes" then I may look towards reimplementing on that chipset simply due to cost considerations.· However, from what I can see on the SX, even the SX/48, I'll end up implementing a P-code interpreter anyway just due to code requirements (what I have now running consumes most of six partitions - while a goodly bit of it is messages and can be stuck on an EEPROM for display, I bet what's left as instructions doesn't fit in the on-chip code space, especially when the 16-bit math and such is handled.....)

    I can live with the controller simply going "offline" to this I/O when it is having parameters adjusted in this application (at least at the prototype level) but if I can avoid it that's even better.....

    Maybe I'll pick up an SX chip and "Key"..... although I still think I can get this to work on the 2Pe as it stands, although I may need to add one offboard piece of silicon to keep track of elapsed time with the granularity I need [noparse]:)[/noparse]

    Post Edited (Genesis) : 12/27/2005 4:01:17 AM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-12-27 20:58
    It's not hard for the Stamp to keep up with the 1 Hz frequency from the DS1307 SQW output. That gives 1/2 second resolution in a POLLing loop. The next selectable SQW frequency is 4096 hz, not useful for polling. It's too bad the '1307 doesn't have a 10 Hz output!

    There are other chips that give you a good periodic reference:
    www.rhombus-tek.com/co-processors.html
    8 pin chip puts out a 50 millisecond reference
    Peter Anderson was selling timing reference clock with 11 different frequency ouputs at
    www.phanderson.com/
    but the "clock" link seems to be broken at the moment.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • GenesisGenesis Posts: 42
    edited 2005-12-27 22:31
    1/2 second resolution is too coarse. Tens of milliseconds is ideal, 100ms I can live with. Coarser than that is too much.

    I can live with a pass through the code being aborted if the timer fires; that can be coded around and just re-enter at the top, since in terms of passes it doesn't happen that often.

    The Rhombus chip will do the job but I bet I can come up with a cheaper solution than $12, given that I have a timebase already in the 1307....
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-12-27 22:50
    Well, the SQW output at 4096 Hz from the DS1307, followed by a CD4040 or CD4060 ripple counter, from the /256 output, would give a 16 Hz timebase.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • GenesisGenesis Posts: 42
    edited 2005-12-27 23:12
    Yep, for about 50 cents [noparse]:)[/noparse]
Sign In or Register to comment.