4
\$\begingroup\$

I've been teaching myself FPGA programming in Verilog over the past year during the COVID-19 lockdown.

I found a discussion of whether it was possible to measure the speed of light using an Arduino or other microcontroller and the consensus was that the processor speed was too slow and there were too many outside factors like system interrupts.

I figured an FPGA would be well suited to this task and it would be cool to see if I could directly measure the speed of a signal through a wire, which moves at something like 0.85 the speed of light. I've gotten code working on a DE10-lite development board that does this, but I'm having some issues understanding the results. I'm really looking for feedback on whether my approach works at all and what to look out for.

My code is very straightforward. A state machine starts in IDLE until a button press moves it to state "COUNTING." In COUNTING an output wire "measure_outW" is raised from 0 to 3.3 V and then a 100 MHz always block increments a register ("measure_counterR)." This always cycle continues until an input wire (measure_inW), which is pulled down to ground by a 12 kΩ resistor, goes high. Measure_outW and measure_inW are connected through the test object, a long spool of wire. So the number of 100 MHz cycles it takes for the signal to travel from measure_outW to measure_inW (through the long spool of wire) is recorded by measure_counterR.

The state then moves to "REPORT" and the binary value in measure_counterR is converted to binary-coded decimal and fed to a UART which displays it on a PC. (I chose this setup just to get practice using a UART in Verilog.)

I used a fresh roll of 24-gauge wire-wrapping wire as a test object. It's advertised as being approximately 305 meters in length. I get values around 264 clock cycles for the travel time. Now this is with a PLL clock of 100MHz. Another roll of the same wire gives me values around 274 so I feel I'm really measuring something.

Question 1. Does an always block, that runs at posedge of a 100MHz clock, occur at 100 MHz or at 50 MHz (because it's just the posedge)? Sorry, I don't have a scope that can handle these speeds. If it's 100 MHz then in each clock cycle the signal moves 0.85 x (3x108 m/s) * 1x10-8 s) = 2.55 m. It takes 264 cycles to get through the spool so 2.55 m x 264 = 673 m. This is more than twice what I'd expect.

Question 2. Is it legit to measure very short time intervals this way? Does the PLL clock synchronize itself across the FPGA so everything is simultaneous? Or does it keep the phase across the device, at the expense of the actual absolute number of cycles?

Question 3. The values I get move around a bit, and are affected by the position of the spool of wire and its feed-in wires. I'm surprised it isn't a fixed number of clock cycles. Why does it vary by about + or - 10 cycles? I know oscillators can vary ("jitter"), but does this manifest over such short intervals (i.e., only 264 cycles)?

Question 4. I've measured two different spools of wire with different values. But when I combine them into one long test object the resulting time is a somewhat less than the sum of their individual times. Is there a capacitive or inductive effect happening? I'm just turning the line from low to high-- not sending pulses so it's not an AC signal.

\$\endgroup\$
11
  • 3
    \$\begingroup\$ Is this wall of text to simply describe a "stopwatch" logic? \$\endgroup\$
    – Eugene Sh.
    Commented Apr 9, 2021 at 21:11
  • 3
    \$\begingroup\$ Do you have anything to say regarding the four questions I ask about this experimental electronic setup? You are under no obligation to read anybody's wall-of-text. \$\endgroup\$
    – Tim
    Commented Apr 9, 2021 at 21:16
  • 2
    \$\begingroup\$ Coils, huh? Since the speed of propagation of EM wave in a medium depends on both the distributed inductance and capacitance, when you're using coils of wire, you're measuring propagation in said coils, so it's rather hard to generalize such results to get the speed of light in vacuum (c). \$\endgroup\$ Commented Apr 9, 2021 at 21:21
  • 1
    \$\begingroup\$ Furthermore, I'd consider "relativistic speeds" to be somewhat sensationalizing the matter. You're measuring signal propagation, not "relativistic speeds" - EM propagation modeling for the class of devices you use works just fine without taking into account relativistic effects. IMHO, the biggest problem you have is that you can't see your signals (no fast scope), so it's "garbage in garbage out". At the very least, you must have a consistent transmission line with a matched driver and receiver. Coax is cheap - use it. Coiling it up won't change things too much. \$\endgroup\$ Commented Apr 9, 2021 at 21:26
  • 1
    \$\begingroup\$ Since you're talking about actual circuits, you need to post pictures of how you set it up. Otherwise we'll be going in circles. Measuring propagation speed in coax is fairly easy and can be done to a rather high precision with crude methods - no need for an FPGA - as long as you understand the underlying fundamental principles. You could make a circuit that produces a voltage related to propagation time, and use a voltmeter for readout - no need for timers. Simplest of such circuits is a phase detector. And it could be all single-frequency sine wave AC. \$\endgroup\$ Commented Apr 9, 2021 at 21:35

4 Answers 4

6
\$\begingroup\$

You're measuring how long

  1. The source current of your output pin

takes to charge up

  1. The capacitance of your input pin

through

  1. The inductance of your coil of wire

until it reaches

  1. The threshold voltage of your input pin.

Number 3 is related to the length of your wire, but not as directly as you would think. It's also influenced by the geometry of the wire (the value you get with it laid in a coil like that is very different from the value you would get if it made a single 100m-diameter circle) and by the presence of any conductive objects nearby. Numbers 1, 2, and 4 have nothing to do with the wire you're testing; mostly they're fixed properties of the FPGA chip, but they are liable to vary several percent depending on things like your supply voltage and the ambient temperature.

Your experiment isn't impossible, but there are several things you would have to change before you stand any chance of measuring the thing you're trying to measure. Replacing the wire with coax (to reduce interaction with the outside world) and impedance-matching the whole system would be a first step.

You may also be interested in looking up time-domain reflectometry (in which only one end of the cable is connected to the measurement device, and the length can be found by looking for the reflection of the signal from the far end) and frequency-domain reflectometry (in which, instead of sending a single pulse down the cable, we send various frequencies of sine waves, and measure the magnitude and phase of the reflected signals relative to the original). The cost of that last one has come down quite a bit in recent years.

\$\endgroup\$
2
  • \$\begingroup\$ TDR #howto : youtube.com/watch?v=z6UJPqQYzNc \$\endgroup\$
    – Tejas Kale
    Commented Apr 10, 2021 at 13:51
  • \$\begingroup\$ Can’t you calibrate for 1, 2 and 4? 3 is tough though. Optical would be easier since light’s travel time in air or fiber is really only affected by the distance (and a material constant). \$\endgroup\$
    – Michael
    Commented Apr 10, 2021 at 16:52
5
\$\begingroup\$

Just using a single wire isn't going to work for this -- basically, layer of winding on the spool talks to the next. Typically, you conduct this experiment with a good long length of coax cable; the measuring instrument can be a plain old oscilloscope. Then it's just a matter of trading off how much the measuring instrument costs vs. how much the roll of cable costs.

A 100MHz clock means one full cycle takes 10ns. So your "always" block should pop off 100,000,000 times a second. Note that 1ns is about a foot (convenient if you grew up measuring things in feet). If you do a lot of high-speed work, just memorize that (or 300mm, if that's easier).

So 10ns is about ten feet in free space.

100MHz clock means one full cycle in 10ns, or your "always" block popping off 100,000,000 times a second.

Until you do this using coax, or twisted-pair wire, differential signalling, and care to keep the wire at least somewhat spatially isolated, you're not going to get good results.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the comment. Yes I wondered about the individual turns on the spool talking to each other. Though I'm not sending AC so I didn't think there would be much affect. And if anything that should shorten the travel path, not lengthen it as seems to be the case.. I'm going to try this with coax and long straight wires too. \$\endgroup\$
    – Tim
    Commented Apr 9, 2021 at 21:24
  • 4
    \$\begingroup\$ The leading edge of the pulse has a lot of high-frequency content. In that sense, it is "AC". \$\endgroup\$
    – TimWescott
    Commented Apr 9, 2021 at 21:26
  • \$\begingroup\$ @Tim AC is anything not DC. Think of DC as something you get when you average the multimeter readings in DC mode for a "very long time" - or at least much longer time than the propagation time through your test specimen. Whatever is not DC in that mental framework will be AC. And, specifically, you're dealing with propagation of RF signals. \$\endgroup\$ Commented Apr 9, 2021 at 21:29
3
\$\begingroup\$

Does an always block, that runs at posedge of a 100MHz clock, occur at 100MHz

Yes, a 100MHz clock has 100M rising edges and 100M falling edges per second.

Is it legit to measure very short time intervals

The resolution is one clock cycle, or 10ns here, so how legit it is is up to you to decide, depending on the accuracy and resolution you need.

Does the PLL clock synchronize itself across the fpga so everything is simultaneous?

No, the clock propagates inside the FPGA along the clock lines.

Or does it keep the phase across the device

No, if there is signal propagation, then some points get the signal later than other, so there is phase shift.

at the expense of the actual absolute number of cycles?

This does not make sense. All the logic units in your FPGA get the same clock (if enabled) with a delay that depends on how much routing fabric it had to travel through.

"at the expense of the actual absolute number of cycles" is a decision you would make, since you choose the clock frequency so design can run properly accounting for all propagation delay. The PLL doesn't make design choices, nor does it skip cycles.

Question 3. The values I get move around a bit, and are affected by the position of the spool of wire and it's feed-in wires.

A single wire in a spool isn't a transmission line. There has to be a waveguide to constrain the wave into following the path you want it to follow along the transmission line. For acoustic waves, a pipe works well. For electromagnetic waves, consider coax, twisted pair, or even copper pipe but that only works at high frequency.

In your wire spool, the electromagnetic waves will jump from one turn of wire to the next without trouble, through the capacitance between wires, so why would they bother running in circle through all the turns when they can go straight?

Question 4. I've measured two different spools of wire with different values.

You're not measuring propagation speed, you're measuring capacitance.

If you want to play with this, you can buy a cheap roll of 75 ohm coax for TV antenna, or a spool of Cat6 twisted pair which has 100 ohm differential impedance. Pick the one you're most likely to reuse in the future for home improvement projects.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks so much for the comment. I totally get that I'm measuring capacitance. The first thing I did was add a capacitor going to ground to one end of the coil to see how it increased the time-delay of the signal I'm left wondering how the densely-packed logic signals in an integrated circuit are able to move around without jumpig into a neighboring line \$\endgroup\$
    – Tim
    Commented Apr 10, 2021 at 13:18
  • \$\begingroup\$ There is an internal ground plane, and traces over a ground plane form transmission lines. Note I say "ground plane" but it is not necessarily ground, it can be another voltage, or the substrate, but it acts as a reference plane. \$\endgroup\$
    – bobflux
    Commented Apr 10, 2021 at 13:25
1
\$\begingroup\$

As others have noted, classical circuit theory effects (RLC) will overwhelm relativistic effects, making direct measurement from the FPGA impossible.

If you want to experiment, you can try building a Nutt interpolator. Background: here. Basically, create ratioed current sources and use the FPGA (asynchronously!) to control them, based on input events. The sources charge/discharge a capacitor, and the ratio of the currents effectively "stretches" the time interval to something the FPGA can measure.

Success will be constrained by how well you can match the current sources, as well as noise in the system. Likely you won't get anywhere near accurate results (these things are finicky) but it's a learning experience.

\$\endgroup\$
1
  • \$\begingroup\$ This sounds really interesting. I will definitely do some reading and investigate the possiblity. Thank you. \$\endgroup\$
    – Tim
    Commented Apr 10, 2021 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.