Passing Time

luminastrum

New Member
Using a simple 08M chip, I'm measuring light intensity with a phototransistor and reading the analog voltage with "readadc". I'm feeding those voltages to Matlab with the "sertxd" command. Question... is it possible to capture time or sample rate and output that with "sertxd"? Using the baudrate value is not accurate because time overhead related to picbasic code complexity results in reduced baudrate. I appreciate your comments.
 

eclectic

Moderator
lumin....

This section of the forum is for finished projects.
You'll probably get a better response if you re-post in the Main Active forum.
 

luminastrum

New Member
Transmitting Time with SERTXD

As an example, I'm measuring light intensity with a phototransistor and reading the analog voltage with "readadc". I'm feeding those voltages to Matlab with the "sertxd" command and computing the Power Spectral Density (PSD) to discern frequencies. However, I need the corresponding time or sample rate with the voltages in order to compute the PSD. Question... is it possible to capture time or sample rate and output that with "sertxd"? Using the baudrate value is not accurate because time overhead related to the picbasic code reduces the baudrate to an unknown quantity. I appreciate your comments.

Hippy, Eclectic... thanks for moving my question to a more appropriate forum.
 

tikeda

Member
I guess the trick is either read a timer 's count when you run the voltage measurement and send both values in the serial stream *or* start the voltage measurement at known intervals so that you'll know the actual intervals between reads, even if there is a variable delay in sending the data. For the latter, you can connect one input to something like a 555 timer circuit (or similar) that sends a regular pulse to initiate the conversion.
 

luminastrum

New Member
Tikeda, thanks for your comments. You suggested 2 options: 1) read a 555 timer's count or, 2) capture "known intervals" between readings. I like the latter suggestion because it does not involve a 555 timer. One way is to use a stop watch at the start and end of a measurement. The number of samples streamed divided by the total time would be the "known interval". Is it possible to capture the "known interval" with picbasic commands?
 

eclectic

Moderator
Luminastrum. A few points/questions.

Can you upload your commented program? Members may be able to make further suggestions.

You mentioned stopwatch. What sort of time periods do you require?
Number(s) of samples?

What level or % of accuracy do you require?

Using two 08M chips, one for ADC measurement and one for timing / Sertxd
seems a feasible proposition.

The last post in this thread

http://www.picaxeforum.co.uk/showthread.php?t=6569&highlight=08M*+time
contains this link
http://homepage.ntlworld.com/the.happy.hippy/picaxe/timers.zip

which may be of use.

However, I'll confess that I hardly understand a word of his timer programs.
Hopefully, Hippy will be along later to advise you further.

e.
 
Last edited:

tikeda

Member
The '555' timer I mentioned refers to an IC that is often used as a buffered oscillator to generate continuous pulses at a constant frequency. By choosing the values of a couple resistors and a capacitor, you can make the chip output a train of square waves at the frequency of your choice. Try this Google search. The chip doesn't keep count - It just generates pulses at a constant rate. There are other chips that output a count of 'ticks' between events (or the total number of ticks since the counter started).

As for the 'known interval' of picbasic commands, I think it's largely empirical. There are other threads describing how people have timed sections of code. With some of the larger chips it's possible to access the pic chip's internal timers and create interrupts with constant frequency. I don't know if people have gotten access to internal timers with the 08M chip. There have been several threads about timers & interrupts in this forum. Somewhere...
 
Last edited:

lbenson

Senior Member
In this thread, bflavery, following hippy, shows how to use the timer in 08M and other chips to get a relatively accurate time base--considered to be able to produce as accurate a time base as a 555 (tho both are subject to fluctuations due to temperature and manufacturing conditions) (and note the fiction, which you can fix with additional code, of 64-second minutes):

http://www.picaxeforum.co.uk/showthread.php?t=5849

For X1 chips, womai has a very good interrupt-driven timer in code snippets:

http://www.picaxeforum.co.uk/showthread.php?t=8541
 
Top