Pages: [1]   Go Down
Author Topic: High Accuracy Timing Problems  (Read 140 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[please delete]
« Last Edit: July 10, 2014, 10:17:33 pm by Aakash » Logged

Melbourne. Australia
Online Online
God Member
*****
Karma: 23
Posts: 716
Freelance software and hardware development based in Melbourne Australia
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Polling to get an accurate time doesnt seem like it would ever be very successful.

I suspect you need external signal conditioning so that you can convert the impulse into a digital signal, that you can use to trigger an ISR.

If you don't have enough interrupts available, you'd need to OR the triggers through some external hardware (OR gates), and then get the Arduino to read the status of the individual inputs to see which one triggered the interrupt (this is a common method around the problem of not having enough interrupt pins)

Sending data will still be an issue because you'll need to make sure that your data capture interrupts are not effected by other interrupts.
AFIK, you can re-enable a interrups inside the an ISR (see http://stackoverflow.com/questions/5111393/do-interrupts-interrupt-other-interrupts-on-arduino)

However, I think you may be better off running your sending code in the main loop and modify the core Serial code to send using polling rather than interrupts.
You could take a look at the software serial library (both the old and new versions) as they may be easier to convert to not using interrupts however 250kpbs is probably out of the question for software serial

You could also consider using SPI, as generally it operates via polling from what I recall.


Quote
A final problem is time accuracy. The Due clock sucks for stuff like
Really ??

I've not checked this on a Due but it seems odd that you'd need to check every 5 secs

In fact, how are you doing this. Does your RTC return the time to that level of precision?
I just looked at the spec on the RTC  http://datasheets.maximintegrated.com/en/ds/DS1337-DS1337C.pdf
and it only returns the time to the nearest second.

So you'd have either use the Alarm Interrupt or continuously poll the device and wait for the second value to change.

If you need it to be as accurate as you say, I'd suggest that those RTC's arent accurate enough for you in the first place.
I suggest you connect a GPS module, as once they have lock, they are exceedingly accurate as they get their data from the atomic clocks on the GPS satellites.

However you'd still have an issue of determining how long it was taking to retrieve the time data from the GPS or RTC module and whether there was any variability in the time taken for the data comms

If you think that the clock freq is too far off, I'd suggest that rather than continously reading the external reference, that you initially run a calibration process for 5 mins or more , and then calculate a correction factor to apply to the time that the Arduino is keeping.

Note the time keeping of the Arduino is also done on an ISR, so this too will affect your results.

What is your desired level of time accuracy, you mention 40nS at one point, however I'm surprised that you are getting it that accurate  i.e accurate to about 1/3 of the Due's clock rate.

How are you measuring this time accuracy, do you have an external atomic clock etc which you are using to measure this ?


Quote
Q1) One main problem I'm having trouble with is data offloading. Currently, I have a computer send a byte to the Arduino telling it to initiate offload (Serial.print() @ 250kbps the timestamps in memory) every quarter second.

Why are you sending the data this often ?

Is it because the upstream systems need to be notified quickly of a change of input.
Or do you get loads of data all the time.

If you are not getting data all the time, it seems pointless swamping the upstream systems with the same data they got in the last 1/4 sec ????


Quote
(Serial.print() @ 250kbps the timestamps in memory)
Where is the data going? To a PC or another arduino or are you just recording the data over a long period

I think unless you describe the whole system, you are not likely to get completely use response from anyone to this question
« Last Edit: July 10, 2014, 09:53:59 pm by rogerClark » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[please delete]
« Last Edit: July 10, 2014, 10:17:06 pm by Aakash » Logged

Melbourne. Australia
Online Online
God Member
*****
Karma: 23
Posts: 716
Freelance software and hardware development based in Melbourne Australia
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Re: Polling using AnalogRead

It sounds like you have a loop where you constantly do AnalogueRead and check the values

Quote
loop()
{
val=analogeRead(1);
if (val>100)
{
DO SOMETHING. e.g. store time of event
}

}

This is called Polling.

but what you really need to do is

Code:
myISR()
{
DO SOMETHING. e.g. store time of event
}
setup()
{
attachInterrupt(1,myISR);
}

Then attach your pizo to the pin for Interrupt 1 (not sure what pin this is for the Due)

Note, Do you this, you'd need external hardware that performs the analog hardware equivalent of

Code:
if (val>100)
{
}

The device is called a Comparator  (you can also use an OpAmp as they are similar, but technically you need a comparator)





However I'm afraid I'm not a free online design service ;-)

Logged

Melbourne. Australia
Online Online
God Member
*****
Karma: 23
Posts: 716
Freelance software and hardware development based in Melbourne Australia
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As the original poster has deleted his questions after I spent a lot of my time trying to give useful responses, I'm just reposting his questions for the benefit of the community

_________________________________________________________________________________________
Hello,

I'm working on a project where there are 4 piezo sensors hooked up to an analog port on an Arduino Due. I'm going to read the values of the 4 analog ports as fast as possible using the ADC as described here: http://frenki.net/2013/10/fast-analogread-with-arduino-due/

When a piezo sensor is hit hard enough and a certain threshold value is exceeded on an analog port, I'll record a time stamp in the RAM of the Arduino. (I'll sequentially read the 4 ports. Using the read method described in the link, this process should only take 1.79uS/port * 4 = 7.17 uS.) Once a hit happens, reading a time stamp, recording it in RAM, and setting a flag to not read the port for a few milliseconds until voltage has returned to normal should only take what I'm assuming will be 2-3 more microseconds maximum. There could be a case where all sensors are hit at the same time, but I *think* reading all 4 ports and recording 4 different time stamps will still take less than 15 uS. Does this sound reasonable?

As you can probably already see, accurate timing is *very* important for this project. I currently have a setup that involves 9 Arduino Dues for managing the data offloading, hit detection, timestamp synchronizing, etc. and I'm getting data accurate within 40 uS. However, I'm currently using analogRead() and similar functions, so I feel like I can redo this project using just a single Arduino AND get better timing results by using the ADC fully.

Q1) One main problem I'm having trouble with is data offloading. Currently, I have a computer send a byte to the Arduino telling it to initiate offload (Serial.print() @ 250kbps the timestamps in memory) every quarter second. However, serial comm uses ISR, so all running code will be halted (and thus detection of piezo hits is delayed). What is an alternative offloading method that can still ensure all hits are detected immediately?

Q2) A final problem is time accuracy. The Due clock sucks for stuff like this. The interval between hits for all the sensors is the most important thing I'm measuring, so I was thinking of polling to an RTC like the DS1337 or something similar every 5-6 seconds to keep the Arduino's reported time stamps reasonable (So I can compare times between hits regardless of how long it has been since the Arduino booted, as calls to micros() is extremely variable. I don't actually care what the time is, just relative time between hits). Is there a way I can do this that's better? I realize the polling still still cause similar problems as experience in the offloading, with detection being delayed if the hit happens exactly during the sync. How can I resolve this?

I've given a lot of thought to this and can't seem to think of any good solutions.

Thanks!
Aakash
Logged

Melbourne. Australia
Online Online
God Member
*****
Karma: 23
Posts: 716
Freelance software and hardware development based in Melbourne Australia
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the OP's response to my answer to his question, - which he also deleted.

----------------------------------------------------------------------------------------------------------------------------------------

Quote
Polling to get an accurate time doesnt seem like it would ever be very successful.
Do you have any other suggestions? The only one I can think of right now is just to get a better crystal (though I'm not sure that exists). In my current setup, each piezo is connected to its own Arduino to detect hits, which in turn triggers a pin to go HIGH. This triggers an ISR on another Arduino, at which point  it records a timestamp. These latter Arduinos sync their time with a central Arduino every 5 seconds and also offload their data when prompted over serial. This allows all the timestamps reported to be similar in relative terms. Though they each drift off by like ~20-40 microseconds between syncs, and the central syncing Arduino has its own drift. This setup is why I have 9 Arduinos.

Quote
If you don't have enough interrupts available, you'd need to OR the triggers through some external hardware (OR gates), and then get the Arduino to read the status of the individual inputs to see which one triggered the interrupt (this is a common method around the problem of not having enough interrupt pins)

I believe I currently do this (described immediately above), right?

Quote
However, I think you may be better off running your sending code in the main loop and modify the core Serial code to send using polling rather than interrupts.
You could take a look at the software serial library (both the old and new versions) as they may be easier to convert to not using interrupts however 250kpbs is probably out of the question for software serial

You could also consider using SPI, as generally it operates via polling from what I recall.
I'm a bit confused on what you mean by polling. Can you please elaborate? Do you mean that interrupts in my code will be able to interrupt SPI communication? Also, I picked 250kbps because it was the fastest I reliably tested, though it's not necessary. 9600bps will be fine too.

Thanks!
Aakash
Logged

UK
Offline Offline
Tesla Member
***
Karma: 101
Posts: 6255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for doing that Roger.

And shame on @Aakash for deleting all that useful information - it doesn't show much sense of community spirit.

...R
Logged

Melbourne. Australia
Online Online
God Member
*****
Karma: 23
Posts: 716
Freelance software and hardware development based in Melbourne Australia
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Robin2

I was rather riled when the OP did this.

Fortunately their original posting was caught into Googles page cache, so I was able to recover it ;-)

I did also report this to the moderator, in case they have the option to undelete - which would be better as it keeps the formatting.

In hindsight, I suspect that the OP is working on a commercial project and deleted his question so that the end client would not find out that they had posted a quiet technical question to a enthusiast forum.

It also started to ring alarm bells with me, when the OP didnt seem to know what polling was.

Anyway, at least I was able to recover what they'd deleted.
Logged

Pages: [1]   Go Up
Jump to: