PSN-L Email List Message

Subject: RE: homebrew data logging program
From: "Westfall, Ron" RWestfall@...........
Date: Mon, 7 May 2001 16:26:58 -0700


Casey

There are three (possibly more) strategies for servicing hardware
periodically and performing housekeeping at the same time.  The method you
choose will depend on the capabilities of Quick Basic and/or what operating
system capabilities can be accessed using Quick Basic.

1) Design all housekeeping operations so they are very short duration.  If
need be, break longer operations up and use a variable to record progress
(e.g. 1 = step A completed, 2 = step B completed, etc.).  The goal is to
ensure that each housekeeping operation is rather shorter in duration than
the 50 milliseconds between A/D readings.

To read from the A/D you need to read the system's clock.  Calculate the
absolute value of the clock when you next want to take an A/D reading.  When
this value is reached, perform an A/D reading.  Do not use a delta value
since the last reading, as this will introduce drift and error.

Whenever the program is not performing housekeeping, it sits in a loop
checking the clock.  The loop will also contain a check to see if any
housekeeping operations need to be performed.  Whenever a housekeeping
operation, or step, is completed, check the clock.  If housekeeping
operations result from a check in the loop, the clock check at the end of
the operation will be automatically done when the program returns to the
loop.

2) If by some remote chance, Quick Basic supports "threads", you can avoid
chopping up your housekeeping operations.  In case you are not familiar with
threads, a thread is like having a separate computer to execute code.  If
you use two threads, its like having two computers.  The operating system
transparently shares the real computer between the two threads.  You can
also use "processes", but threads are preferable for your application,
because variables are shared between the two threads whereas they are not
shared between two processes.

One thread would sit in a tight loop watching the clock and performing A/D
operations every 50 ms.  The other thread would perform housekeeping
operations.  Because the operating system automatically switches execution
between threads periodically, the second housekeeping thread can execute
software that takes as long as it wants to perform operations.

3) PCs have a real time clock that I believe can be programmed to generate
an interrupt periodically.  When the interrupt occurs, an interrupt service
routine is called.  There is probably an operating system call to register a
routine of yours as the interrupt service routine.  Beware though, interrupt
service routines are finicky.

If the real time clock can only be programmed to generate one interrupt 50
ms. in the future, it can always be programmed for the next interrupt in the
interrupt service routine.  Again, avoid drift by taking the difference
between the current time and the desired time to program the next interrupt.

Once the interrupt routine is set up to run every 50 ms., the main program
can perform housekeeping.

If you are new to programming, I recommend method 1 to you.  Its simple.
Life gets progressively more complicated as you advance through methods 2
and 3.  On the other hand, as the interval between A/D readings decreases
(e.g. more than 20 samples/sec or more than one channel), methods 2 and 3
become increasingly necessary.

There are nuances to all three of these methods that I have left out for the
sake of brevity (hah!).  If you get further along and you are running into
trouble, drop me a line.

Ron Westfall



-----Original Message-----
From: David russel [mailto:ogzax@.........
Sent: Saturday, May 05, 2001 2:42 PM
To: PSN-L@..............
Subject: homebrew data logging program


I've just completed an AtoD convertor using the ADC0809 eight bit
convertor chip. I can address it and do data in/out from the Lpt1 port.
It all works out Ok as electronics is my forte' but I'm a little weak in
the programming department. I've come up with a program written in Quick
Basic which is but a glorified three Channel 
oscilloscope. It uses PSET and LINE statements to graph it all out.
I also have routines to scale the data from the ADC input and also
control the horizonal sweep speed. The speed however is not calibrated to
any thing.

        How do I go about taking a reading twenty times a second ?
and do all the other program house keeping without these other chores
impacting the sampling rate ?

        Is there an answer out there ?
        singed, anxiety's child
        
Casey
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/tagj.
__________________________________________________________

Public Seismic Network Mailing List (PSN-L)

__________________________________________________________

Public Seismic Network Mailing List (PSN-L)


[ Top ] [ Back ] [ Home Page ]

Larry Cochrane <cochrane@..............>