Measure the speed of electricity...

I have been inspired by "Laser Developer" and have made a DMTD (Dual Mixer Time Difference) measurement system using two propeller boards.
One board is simply a generator. It generates two 1MHz square waves that are 90 degrees (250nSec) out of phase.
These two signals are fed into a second propeller board that will sample the two signals at 1MHz. But because the two boards have seperate crystals there will be (should be) a small frequency difference between the two boards. In my setup the difference between the two was 19ppM (19Hz @ 1MHz). There MUST be some difference between the two for the system to work.
First the two signals are interconnected using short wires of the same length. The system can then be zeroed by pressing a key in PST. Then one of the short wires is replaced with a long wire to be measured. The system will measure the actual phase delay caused by the time it takes the signal to travel the length of the wire being measured.
I have hacked this up in PropBasic, but I want to re-write it in spin to make it more generic for Propeller users.
I've tried this on two different setups (one at work and one at home) and it seems to work. I used a 19 foot piece of wire and the system said it was 22 ft (but I don't think electricty flows at exactly 1 ft per nSec).
If you want to try this out, I used P0 and P1 for the signals (don't forget to connect the grounds together too).
Let me know if you try this. If there is enough interested I'll do a little write-up for it.
P.S. If you prefer there is a spin version posted further down.
Bean
One board is simply a generator. It generates two 1MHz square waves that are 90 degrees (250nSec) out of phase.
These two signals are fed into a second propeller board that will sample the two signals at 1MHz. But because the two boards have seperate crystals there will be (should be) a small frequency difference between the two boards. In my setup the difference between the two was 19ppM (19Hz @ 1MHz). There MUST be some difference between the two for the system to work.
First the two signals are interconnected using short wires of the same length. The system can then be zeroed by pressing a key in PST. Then one of the short wires is replaced with a long wire to be measured. The system will measure the actual phase delay caused by the time it takes the signal to travel the length of the wire being measured.
I have hacked this up in PropBasic, but I want to re-write it in spin to make it more generic for Propeller users.
I've tried this on two different setups (one at work and one at home) and it seems to work. I used a 19 foot piece of wire and the system said it was 22 ft (but I don't think electricty flows at exactly 1 ft per nSec).
If you want to try this out, I used P0 and P1 for the signals (don't forget to connect the grounds together too).
Let me know if you try this. If there is enough interested I'll do a little write-up for it.
P.S. If you prefer there is a spin version posted further down.
Bean
Comments
I believe the difference in signal speed vs. speed of light is called Velocity Factor. It would be a good experiment to try coax vs. a single conductor as the VF of coax is usually pretty significant, on the order of .8 or more.
It is amazing to see some of the folks on here like you that are good at putting ideas into practice.
C.W.
Thanks, yeah I guess I should have made the units "nSec" instead of "ft".
It would be a great experiment to measure the velocity factors of different cables.
Bean
Perhaps you have the solution there. Just run the signal through a laser/photo diode set up.
Anyway the speed of signals through wires might be close enough for me:)
My friend works as a director/professor at our German standars lab PTB where they are doing very high precision speed & time measurement.
If you look in their publications there are lots of very interesting things to be found. But more to the normal user environment, I would suggest to use
GPS stabilized oszillators for such experiments, because standard quarz oszilators are not very good in terms of jitter & stability.
http://www.jrmiller.demon.co.uk/projects/ministd/frqstd.htm
Cheers, Fried
What does DMTD stand for? Google comes up with noise...
DMTD is Dual Mixer Time Difference
The reading are pretty jittery, but using long wires of CU and AL should show some difference in speed.
Bean
Wagon Wheels & Stobe lights - Have you ever seen in old movies when a wild west wagon is moving and the wheels seem to be turning very slowly (or even backwards) ? This is because the movie is a series of still picture frames taken at 24 frames per second. If the spokes in the wheel rotate just enough so that a spoke is in almost the same place as a different spoke in the previous frame, it will look like the spoke barely moved at all from one frame to the next. The same effect can be seen by using a strobe light and a fan. By adjusting the speed of the strobe and/or fan, you can make the fan appear to stop or move very slowly. Aliasing & Downconverting - Well the same thing can be done for digital signals. This is called "Aliasing". Anytime you sample a signal at a frequency less than twice the frequency of the signal itself, you will get aliasing. For example if you have a squarewave at 1MHz and you sample it at 1,000,100 it will appear to be toggling at only 100Hz (the difference between the two frequencies). The interesting thing is that the duty cycle will be correct. If the 1MHz signal has a duty cycle of 30% then the 100Hz signal seen by sampling it will also have a duty cycle of 30%. This process of converting a frequency to a lower frequency is called "Downconverting". Time Expansion - It could be said that by downconverting the fast signal to a much slower rate (but keeping the waveform shape) is expanding time. We took a signal that lasted only 1uSec and transformed it into an identical signal that lasts for 10mSec (10,000 times longer). Of course we haven't REALLY expanded time because the signals need to be repeating. Measuring the speed of electricity - We can use this time expansion to accurately measure a phase error too. If we take TWO 1MHz signals that have a phase error, and sample them at the same time we get two signals that are the same duty-cycle and have the same phase error (in degrees) as the originals. So if the use two signals with 90 degrees of phase error (250nSec @ 1MHz), when we measure the phase error in the downconverted signals the phase error will still be 90 degrees, but 90 degrees of 100Hz is 2.5mSec. We can measure this 2.5mSec time very accurately by counting the samples. By introducing an additional phase change (like using a longer piece of wire for one of the two signals) this phase change can be expanded and measured. Since the phase change is expanded by 10,000 times, a 1nSec (about 1 foot of wire) change at the inputs will result in a 10uSec change at the outputs. Propeller implementation - Since we cannot get EXACTLY 100Hz of difference just by using the propeller boards, we will take what we get by chance. No two crystals will be exactly 5MHz. And between any two propeller boards there will most likely be a significant enough variance that we will get reasonable result. However if you don't, try a different board. The crystals may be too close or too far apart to get good measurements.
If the signal was not so jittery, could something approaching the accuracy of Laser Developer's chip be made with a couple props?
Measuring very fast events using a relatively slow clock seems like kind of cool thing that might be useful. I love this stuff!
Jim
Yes, if you had two oscillators (TCXOs) that where about 10ppM apart (or VCTCXOs) that would be ideal.
Bean
Exactly my thoughts. Now I'm interested because I have been thinking of an el'cheapo homebrew TDR for a while. I have tried a couple ideas out, but I could never get it to work accurately enough to be field-usable. If I ever get the non-exsistant spare time, I would love to set this up and see it in action. *glares menacingly at the HUGE stack of paperwork on my desk*
Lawson
I used 16 averaged together and the results varied only by a couple tenths of a nSec.
Bean
These undefined SF-TLA's make me crazy!
And yeah, Prof_Braino. Thaat's exactly what I'm talking about.
The fluctuations are small in the short term, so these average out. I think that you would want to limit sample taken to a single measurement session, as the large drift occure over the long term, in that case you would be measure the long term drift of the crystal and other parts of the system.
I would think one could store reading in EEPROM and transfer to PC later, or just store directly to SD.
The point of interest in this application would be the reflected signal, and the chanllenge would be to fliter out the reflection from other noise, is that correct?
This is a cool application, and might turn out to be useful!
When I was talking about storage, I was not implying the cable under test, I was meaning some sort of database with the average signal propegation for your stock of cables. Like for our purposes here, say 14ga wire made of copper would have a very different signal propegation than 30ga. nickel plated wire, and that would have to factor in to your calculations. I am by no means a math whiz, and would have to call in some big guns to help out with this, but I can't help but think it would work... but.. to repeat myself, accuracy would be my biggest fear. High-dollar TDR setups can detect faults down to the centimeter over miles and miles of cable, and the already inherant errors Bean saw is the biggest turn-off. High precision xtals would help, but not an end-all solution to it.
C'mon Bean. I know you are interested in this, where's your $0.02?
I tried it without the PLL (5 MHz instead of 80 MHz) and it didn't seem to make much difference.
Here is the latest version of the receiver with averaging and better edge handling. Before I started measuring after any jitter, now I start measuring at the first edge regardless of how much jitter comes after it.
Bean
' DMTD receiver for use with DMTD transmitter ' Receives two 1MHz square waves on P0 and P1 ' The waveforms are normally offset by 90 degrees (250nSec) ' To create a phase shift, replace one of the wires on P0 or P1 with a longer wire. ' If you get a negative phase shift time, use the other wire. ' ' NOTES: ' This method relies on a small frequency difference between the clock of the transmitter ' and the receiver. If you are having trouble, try a different board for one or the other. ' ' see further information at bottom of this file... ' CON _ClkMode = XTAL1 + PLL16X _XInFreq = 5000000 OBJ pst : "Parallax Serial Terminal" ' Serial to PC f : "Float32" ' IEEE-754 32-bit Floating Point Math fp : "FloatString" ' Format 32-bit Floating Point Value for display VAR LONG newValue LONG value LONG sum LONG offset LONG divisor PUB __Program pst.Start(115200) ' For PC communication f.Start ' Start the floating point math library fp.SetPositiveChr(" ") ' Don't show '+' for positive numbers value := -1 ' No value measured yet offset := 0 ' No offset set yet waitcnt(80_000_000 + cnt) ' Wait 1 seconds for things to settle CogNew(@Init, @newValue) ' Start measurement cog repeat ' Repeat forever sum := 0 ' Start with sum of zero repeat 10 ' Average 10 readings repeat until newValue > -1 ' Wait for a new measurement if ina[31] == 0 ' While waiting, see if user press a key to set new offset offset := 0 ' If they DID press a key, set offset to zero (not set) value := newValue ' Get measurement value newValue := -1 ' Set value to no measurement (so we don't read it again) if offset == 0 ' If offset is NOT set offset := value ' Use this value for the offset divisor := f.fdiv(f.ffloat(value), 250.0) ' Calculate nSec divisor value-=offset ' Subtract offset from value sum+=value ' Accumulate sum of values sum:= sum / 10 ' Compute average of sum sum:=f.fdiv(f.ffloat(sum), divisor) ' Divide to get nSec pst.str(fp.FloatToString(sum))' Display value pst.str(string(" nSec")) ' Display units pst.char(13) ' Display one measurement per line DAT ' PASM routine to measure the time expanded phase difference ' Store measurement in "newValue" ' org 0 Init mov time,cnt ' Setup initial waitcnt value cnt+511 adds time,#511 WaitPhase waitcnt time,#80 ' Sync 1MHz (80 counts @ 80MHz) mov temp,ina ' Read inputs and temp,#3 ' Mask off bits we are interested in cmps temp,#2 WZ, WC ' Are we in phase 2 ? IF_NE jmp #WaitPhase ' No, jump back Loop waitcnt time,#80 ' Sync 1MHz (80 counts @ 80MHz) mov temp,ina ' Read inputs and temp,#3 ' Mask off bits we are interested in cmps temp,#1 WZ, WC ' Are we in phase 1 ? IF_NE jmp #Loop ' No, jump back mov _value,#0 ' Yes, zero loop counter Wait waitcnt time,#80 ' Sync 1MHz (80 counts @ 80MHz) mov temp,ina ' Read inputs and temp,#3 ' Mask off bits we are interested in adds _value,#1 ' Add 1 to counter cmps temp,#1 WZ, WC ' Are we in phase 1 ? IF_E jmp #Wait ' Yes, keep waiting (and counting) cmps _value,#100 WZ, WC ' No, is the value =< 100 ? IF_BE jmp #Wait ' Yes, Loop back (jitter in edges) mov temp,par ' No, write value to HUB so spin code can read it wrlong _value,temp jmp #WaitPhase ' Repeat forever In0 LONG 1 << 0 In1 LONG 1 << 1 time RES 1 temp RES 1 _value RES 1 {{ Wagon Wheels & Stobe lights - Have you ever seen in old movies when a wild west wagon is moving and the wheels seem to be turning very slowly (or even backwards) ? This is because the movie is a series of still picture frames taken at 24 frames per second. If the spokes in the wheel rotate just enough so that a spoke is in almost the same place as a different spoke in the previous frame, it will look like the spoke barely moved at all from one frame to the next. The same effect can be seen by using a strobe light and a fan. By adjusting the speed of the strobe and/or fan, you can make the fan appear to stop or move very slowly. Aliasing & Downconverting - Well the same thing can be done for digital signals. This is called "Aliasing". Anytime you sample a signal at a frequency less than twice the frequency of the signal itself, you will get aliasing. For example if you have a squarewave at 1MHz and you sample it at 1,000,100 it will appear to be toggling at only 100Hz (the difference between the two frequencies). The interesting thing is that the duty cycle will be correct. If the 1MHz signal has a duty cycle of 30% then the 100Hz signal seen by sampling it will also have a duty cycle of 30%. This process of converting a frequency to a lower frequency is called "Downconverting". Time Expansion - It could be said that by downconverting the fast signal to a much slower rate (but keeping the waveform shape) is expanding time. We took a signal that lasted only 1uSec and transformed it into an identical signal that lasts for 10mSec (10,000 times longer). Of course we haven't REALLY expanded time because the signals need to be repeating. Measuring the speed of electricity - We can use this time expansion to accurately measure a phase error too. If we take TWO 1MHz signals that have a phase error, and sample them at the same time we get two signals that are the same duty-cycle and have the same phase error (in degrees) as the originals. So if the use two signals with 90 degrees of phase error (250nSec @ 1MHz), when we measure the phase error in the downconverted signals the phase error will still be 90 degrees, but 90 degrees of 100Hz is 2.5mSec. We can measure this 2.5mSec time very accurately by counting the samples. By introducing an additional phase change (like using a longer piece of wire for one of the two signals) this phase change can be expanded and measured. Since the phase change is expanded by 10,000 times, a 1nSec (about 1 foot of wire) change at the inputs will result in a 10uSec change at the outputs. Propeller implementation - Since we cannot get EXACTLY 100Hz of difference just by using the propeller boards, we will take what we get by chance. No two crystals will be exactly 5MHz. And between any two propeller boards there will most likely be a significant enough variance that we will get reasonable result. However if you don't, try a different board. The crystals may be too close or too far apart to get good measurements. }}
Bean
http://Galileo.phys.Virginia.EDU/classes/109N/lectures/spedlite.html
It could be helpful as a baseline reference..
So far it looks good, and the readings are more stable.
I should have something to post tomorrow, but right now it appears able to have about 50 picoSecond resolution. But I just got it working a couple minutes ago, so that may change.
This will be quite a nice demo of the capabilities of the Propeller chip.
Stay tuned...
Bean
Interesting, how do you get around the need for 'all timeslot sampling', also known as two non-locked frequencies ?
'NOTES:
' This method relies on a small frequency difference between the clock of the transmitter
' and the receiver. If you are having trouble, try a different board for one or the other.
'
"
I'm trying to use the video generator, but it's not working too well.
Initially I was getting nice steady values, but they seem to jump large amounts. I guess because even though the video generator is creating a different frequency it is still phase locked to the crystal.
I'm going to try dithering the video frequency and see if that helps.
Bean
Why not add a simple device like a 74HC4060/LV4060, which has an oscillator and divider ?
Two crystals are always going to give a better result, if you want fractions of a ns averaging.
Oh well. I tried....
Bean
Technically the velocity of electrons in the wire move very slowly.
Something like 1/2" per hour.
It's the wave through them that moves fast.
Nit pick off:
Duane