Shop OBEX P1 Docs P2 Docs Learn Events
two questions — Parallax Forums

two questions

realolmanrealolman Posts: 65
edited 2008-02-23 23:55 in BASIC Stamp
I have two questions, both having to do with visual basic

1. I would like an elspsed time meter that can stand alone accruing·running time , and then will communicate with a Visual basic app.· It seems a bit of a waste to use a stamp, but I can't seem to locate anything any better.· Is there a way I could use the stamp as an elapsed time meter.

2. I have a usb board of Ed. . How can I communicate with a visual basic app with that?

thanks

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-02-23 15:28
    1. Depending on the accuracy you need yes you can and with extra parts you can get good accuracy.
    2. the USB BOE looks to the computer like a serial com port so you communicate with it just as you would a regular com port.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • realolmanrealolman Posts: 65
    edited 2008-02-23 15:42
    Thank you . I had no idea about the usb and serial port similarity (obviously )

    Could you point me toward programming the stamp to be an elapsed time meter? I don't see any commands having to do with time, other than short term like pause , pollwait, pulsin pulsout.

    Seconds would be fine as a unit of measurement. I don't need anything any more accurate than that. I would just like to hook the stamp to something and whenever the something runs, a non volatile count would accumulate so I could read it later through a VB app.

    again thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-23 16:18
    Really, the only way to measure elapsed time is with the PAUSE statement. In some cases, you can use the SLEEP or NAP statements, but they work in a similar fashion. Essentially, your program spends most of its time sitting in a known duration PAUSE statement, waiting. For short periods of time, your program continues from the PAUSE, checks whether the timed condition is over. If not, it increments a time counter variable and goes back to the PAUSE again. When the timed condition is false, your program can listen to the communications port from the PC and, if there's a request received for the data, can send it and optionally reset the elapsed time counter.

    If you need more accurate timing, you can attach an external real time clock like the DS1302 to the Stamp (see the StampWorks manual). With a real time clock, you'd read the time and date when the timed condition begins and then again when it ends. The difference is your elapsed time.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-23 16:49
    Hi realolman, if your application requires being permanently hooked up to a PC then you can use the computer clock to measure elapsed time by sending a start and a stop signal. You can do this in Visual Basic or you could use PLX-DAQ depending on what you want to do with the results.

    Jeff T.
  • realolmanrealolman Posts: 65
    edited 2008-02-23 18:30
    Thanx Mike and Unsound.

    Unsound, I'd like the Elapsed Time meter to do it on it's own, without the computer. I'd like to just connect with the computer occassionally to "read the meter"

    Mike, so with the PAUSE, I could check on the status of a pin in approx mSec intervals, up to approx. a minute or so (65535 ms + instruction time )and increment a variable. Can the variable be stored so that it is non volatile?

    thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-23 18:56
    Stamps store their program in EEPROM and the space left over can be written and read with READ and WRITE statements. READ is fast, but WRITE takes a few milliseconds. The main issue is that a specific location in the EEPROM (actually a group of locations like 16 or 32 bytes depending on the EEPROM size) can be written only about 100,000 to 1,000,000 times before it wears out ... can't be written anymore. If you would be happy with the elapsed time being non-volatile to the nearest minute, that's not a problem since it would be an awful lot of minutes before the counter can't be rewritten. On the other hand, updating the non-volatile counter every second would wear out the memory locations in a year of continuous use.

    Typically the way this is handled is that the time in minutes, kept in an ordinary variable, is compared to the EEPROM memory locations (byte by byte). If it's not the same, the EEPROM is updated with the new value. This way the locations in EEPROM are rewritten only when necessary.
  • realolmanrealolman Posts: 65
    edited 2008-02-23 22:22
    Thank you
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-23 22:32
    Something else to consider. A DS1302 includes a small amount of RAM and the whole thing will run off a small Lithium battery for years. You could copy the date and time into a RAM location when the timed condition begins and actually have a number of such conditions. When the timed condition(s) end, you'd calculate the time difference and store that in the same location (with a flag showing it's an elapsed time rather than a start time) or in some other location in the RAM. SparkFun has a complete real time clock module using a slightly different DS1307 and a battery for $20 (www.sparkfun.com/commerce/product_info.php?products_id=99). I believe there's sample BS2 code in one of the Nuts and Volts articles downloadable off the Resources tab of the main Parallax website. I don't remember which column it is, but it's one of the ones on the use of I2C since the DS1307 uses an I2C interface.

    I looked them up. They're #85 and #115. The latter has specific examples for the DS1307.

    Post Edited (Mike Green) : 2/23/2008 10:42:01 PM GMT
  • realolmanrealolman Posts: 65
    edited 2008-02-23 23:55
    The Spark Fun Clock lookss real promising may be just the ticket... thanks.

    I would think that an elapsed time meter that communicated with a computer would be common, but I haven't found one. Curtis makes a circuit board mounted something that has a reader, but I haven't found any specifics about either one, even from their site.

    So with your PAUSE example, I could keep the count in a variable, which would be volatile, but store it in EEProm once a minute, and the most I should ever lose is a minute (approx.) and the EEprom shouldn't wear out for many moons?

    Thank you very much.
Sign In or Register to comment.