Toggling GPIO pins for pulse width of <100ns

mbferguson
Posts: 31
Joined: Thu Nov 15, 2018 2:33 pm

Re: Toggling GPIO pins for pulse width of <100ns

Heater wrote:
Tue Nov 27, 2018 7:12 pm
What about that 860 SPS rate?

What kind of time of flight are you expecting to see? Sorry have no idea about that sensor but I imagine it can be very short.
The medium being measured is Aluminum, speed of sound is 6320m/s. The dimensions of my object are 20cm x 20cm x 1.5cm and will be measured from the 1.5cm side. (The PT-12 says maximum range of 15cm but another seller listed it as 20cm for steel which is more dense than aluminum)

If there is no flaw --> flight time = 0.40m / 6320m/s = 63.2us (don't tell arduino)
If flaw present (roughly near middle) --> 63.2us / 2 = 31.6us (arduino we struck gold!)

I don't think I actually need any SENDING rate for the pulses higher than 100Hz to be able to quickly detect the probe moving around, the sending rate is pretty much just arbitrary.
Last edited by mbferguson on Tue Nov 27, 2018 7:36 pm, edited 4 times in total.

Brandon92
Posts: 949
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Toggling GPIO pins for pulse width of <100ns

mbferguson wrote:
Tue Nov 27, 2018 7:05 pm
Heater wrote:
Tue Nov 27, 2018 6:55 pm
Why do you want mV resolution, you only need to know when a pulse comes back? You could do that with a comparator circuit.
Correct, my apologies. I can confuse myself since I've been working on this for a while, going through different iterations of how it will work. The voltage shouldn't matter, only the time at which the voltage is raised from 0V.

I mentioned I wasn't sure what the magnitude of the reflected wave would be, only in mV. This was told to me by someone who had worked in the industry testing with these devices. I thought an ADC that could detect small differences would be best in case the signal was very low.

This seems to be a good ADC as replacement. MCP3008, sample rate of 200kHz max.
Where do you want to use the ADC for. And what for frequency do you want to measure. Because the adc need to be at least 2 times faster then the signal you want to measure (Nyquist).

Also, you say you don't want to use a ADC. But give a replacement part for the ADC?
Here you can find more suitable ADC by the way.

mbferguson
Posts: 31
Joined: Thu Nov 15, 2018 2:33 pm

Re: Toggling GPIO pins for pulse width of <100ns

Brandon92 wrote:
Tue Nov 27, 2018 7:24 pm
Where do you want to use the ADC for. And what for frequency do you want to measure. Because the adc need to be at least 2 times faster then the signal you want to measure (Nyquist).

Also, you say you don't want to use a ADC. But give a replacement part for the ADC?
Here you can find more suitable ADC by the way.
I thought the Raspberry PI was unable to process analog inputs on its GPIO pins. Therefore ADC would be needed to determine voltages between HIGH and LOW.

Since my pulses are at 100ns, that is a 5MHz frequency. ADC at 10MHz frequency is needed then I guess. MCP3008 no longer viable

Will a comparator avoid the need for such a high sampling ADC?

Although this AD7400A is only \$6 with a 10MS/s rate and 16-bit.
Datasheet: https://www.mouser.com/datasheet/2/609/ ... 501851.pdf

Brandon92
Posts: 949
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Toggling GPIO pins for pulse width of <100ns

There is a different between a analog signal and a digital signal. A analog signal can have every value between for example 0V and Vcc. And a digital signal is for example only 0V and 3.3V (in the case of the Rpi), so a '0' or a '1'.

And if you want to measure a digtal signal it is possible with the Rpi. You can connect it directly* to the Rpi.

For example:
If you want to measure a analog signal, like a sine wave, audio, you need a ADC.
If you want to read if a switch is on or off, you will use it as a "digital" signal.

*if the voltage, ect. is within the specification of the Rpi. As mention here under Voltage specifications

DavidS
Posts: 4340
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Toggling GPIO pins for pulse width of <100ns

mbferguson wrote:
Tue Nov 27, 2018 7:29 pm
Brandon92 wrote:
Tue Nov 27, 2018 7:24 pm
Where do you want to use the ADC for. And what for frequency do you want to measure. Because the adc need to be at least 2 times faster then the signal you want to measure (Nyquist).

Also, you say you don't want to use a ADC. But give a replacement part for the ADC?
Here you can find more suitable ADC by the way.
I thought the Raspberry PI was unable to process analog inputs on its GPIO pins. Therefore ADC would be needed to determine voltages between HIGH and LOW.
All you need to detect the change between high and low (assuming a high voltage) is to through capacitive isolation bias the input to by division.

As long as you bias it so that it will be high value when needed. Now you will have to skew it to have a large enough change in range for a digital signal input, though that can be done with a high speed transistor.

I do not know why you thought that an ADC would be needed, though it definitely is not.
Last edited by DavidS on Tue Nov 27, 2018 7:54 pm, edited 1 time in total.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: Toggling GPIO pins for pulse width of <100ns

mbferguson,
I don't think I actually need any sample rate higher than 100Hz to be able to quickly detect the probe moving around, the sample rate is pretty much just arbitrary.
On the contrary. If you do use an ADC the the sample rate is critically important.

If the duration you are measuring is 30us and you want a 10% accuracy in measurement you will need a sample every 3us. A sample rate of over 30,000SPS !

You 100Hz sample rate probably won't ever see a return pulse.

The MCP3008 sounds more like it at 200ksmps. If you can get them into the Pi at that rate.

Personally I would consider skipping the ADC. Just add some signal conditioning to get a nice pulse into the GPIO pin that you can then time.

Next question...

Why are you wanting to use a Pi for this?

The output pulse and return timing are better done in some simple hardware. I might consider doing it in a 10 dollar Lattice FPGA.

Your display apparently is on an Arduino. What is the Pi for? Apart from making the problem more difficult?
Memory in C++ is a leaky abstraction .

mbferguson
Posts: 31
Joined: Thu Nov 15, 2018 2:33 pm

Re: Toggling GPIO pins for pulse width of <100ns

Heater wrote:
Tue Nov 27, 2018 7:53 pm

The MCP3008 sounds more like it at 200ksmps. If you can get them into the Pi at that rate.

Personally I would consider skipping the ADC. Just add some signal conditioning to get a nice pulse into the GPIO pin that you can then time.

Why are you wanting to use a Pi for this?

The output pulse and return timing are better done in some simple hardware. I might consider doing it in a 10 dollar Lattice FPGA.

Your display apparently is on an Arduino. What is the Pi for? Apart from making the problem more difficult?
Apologies, I mispoke. I meant to say SENDING rate of pulses, others I spoke with referred to how many pulses I sent into the circuit as the sampling rate, not the rate at which the ADC samples the receiving node. I know, I apologize again for the needless confusion.

I'm using a PI because of one main reason --> The Arduino has a 16MHz clock rate, and it can only toggle its GPIO pins at a measly frequency not anywhere close to ns accuracy. The Arduino also has analog input pins... that sample at ~10kHz. I had started writing the GUI code at the very beginning of the semester before I was aware of these problems. It would take too much time to rewrite the GUI on another MCU or the PI.

Why the PI? I had one already available, and its 1.4GHz processor seemed to be a good choice compared to the 16MHz Arduino in terms of toggling the GPIO pins.

The way these transducer probes work is by sending a short pulse, of <= 1/2 a cycle. The RF of the PT-12 is 5MHz, or 200ns, which is 100ns pulse to "ping" or "poling" the transducer. Because the pulse needs to be near +/-100ns, if I did use an ADC it's SAMPLING rate, (not sending), would need to be at least twice the 5MHz pulse, otherwise the high portion of the pulse could slip through while the ADC samples the low portion of the pulse every cycle. Thus an ADC would need to have 10MHz sampling rate to ensure that wouldn't occur. (This is assuming the reflected wave is still at 100ns pulse width ofcourse)

I am far from an expert, and the first option I thought to explore was using an ADC. If you suggest other methods like the comparator or the FPGA, I'm definitely interested in seeing the advantages those have over an ADC.

mbferguson
Posts: 31
Joined: Thu Nov 15, 2018 2:33 pm

Re: Toggling GPIO pins for pulse width of <100ns

DavidS wrote:
Tue Nov 27, 2018 7:53 pm
All you need to detect the change between high and low (assuming a high voltage) is to through capacitive isolation bias the input to by division.

As long as you bias it so that it will be high value when needed. Now you will have to skew it to have a large enough change in range for a digital signal input, though that can be done with a high speed transistor.

I do not know why you thought that an ADC would be needed, though it definitely is not.
I'd be glad if I could avoid purchasing another component and paying the \$8 shipping from Mouser.

Perhaps this wouldn't work, as the reflected wave is supposed to be very low, only millivolts in amplitude.

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: Toggling GPIO pins for pulse width of <100ns

mbferguson,

You remind me that at some point in my career I did a course in production engineering and as part of that we did a lab exercise in detecting flaws in steel bars using an ultrasonic sensor. Sounds very similar to your set up.

It was crude setup with only a scope connected to the sensor output. When an echo was returned there was a distinct pulse appearing on the screen. It's left/right position on the screen indicating the echo return time, hence depth to a flaw in the steel. We could easily see the tiny holes drilled in the sample bars we were given.

Sorry I forget the time scales or amplitudes involved but I bet they were similar to yours.

So I suggest you get down to your lab and hook a scope to your sensor and see exactly what kind of signal we are dealing with here. What is the echo return time, what pulse width, rise and fall time, amplitude.

Then we can think about a fool proof way to detect it.
Perhaps this wouldn't work, as the reflected wave is supposed to be very low, only millivolts in amplitude.
Never mind "supposed" go and measure it. It may well only be millivolts. You seem to be wanting to use an ADC as an amplifier. Well, that is what op-amps are for. You might need to use a instrumentation amplifier if a differential signal is called for to eliminate noise.

I imagine you will need some filtering to block low frequency noise, "mains hum" and possibly block high frequency noise.

Once you have a good amplitude, low noise pulse a schmitt trigger will get you a nice pulse edge to feed into a Pi GPIO or whatever you decide to measure it with.

It just seems to me that having long dangly wires feeding raw tiny signals into an ADC and expecting to see the pulses amongst the noise flipping the low bits is a recipe for failure. Never mind the sample rate problems.

We can only tell by looking at it with the scope.
Memory in C++ is a leaky abstraction .

mbferguson
Posts: 31
Joined: Thu Nov 15, 2018 2:33 pm

Re: Toggling GPIO pins for pulse width of <100ns

Heater wrote:
Wed Nov 28, 2018 5:47 am
mbferguson,
Never mind "supposed" go and measure it.

We can only tell by looking at it with the scope.
I have all the components and am soldering them all now I originally wanted to wait on the simulation to ensure things were working, which I wasn't able to get right until before Thanksgiving. I'll be writing the code that you suggested in your post earlier about running my program on a single core after. Should be able to come back tomorrow with more information after I head to the lab.

I do have one question. I have purchased a ~12x12 inch copper foil piece, I was told this will need to act as my ground for the high voltage power supply. Obviously, I will be cutting out a smaller portion that will be reasonable for the size of my container for the finished device. Should I just solder a wire directly to the copper? If I do that am I going to electrocute anyone that touches the container of the box???

I'm planning on going to Lowe's and buying a decent wood of short width to use as container walls... hopefully copper won't conduct through the wood

https://www.mouser.com/ProductDetail/3M ... V4kp65YvwU
Datasheet: https://www.mouser.com/datasheet/2/1/1181-45855.pdf

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: Toggling GPIO pins for pulse width of <100ns

I'm not sure what's the deal with your copper sheet.

Ideally any dangerous powers supplies will be in a metal box and that box will be connected to ground, as in the ground connection of you mains plug. It's good safety practice that such earth connections are made with a screw connection with anti-slip washers to be sure they are solid and won't come undone.

As a kid I built such boxes by bending up aluminium sheet to house the tube circuits I was making, powered from 300 to 500 volts.

Some times I have built such enclosures from sheets of PCB material and soldering the seems together.
Memory in C++ is a leaky abstraction .

matias.vidalguti
Posts: 1
Joined: Tue Jan 26, 2021 7:14 am

Re: Toggling GPIO pins for pulse width of <100ns

mbferguson wrote:
Wed Nov 28, 2018 6:01 am
Heater wrote:
Wed Nov 28, 2018 5:47 am
mbferguson,
Never mind "supposed" go and measure it.

We can only tell by looking at it with the scope.
I have all the components and am soldering them all now I originally wanted to wait on the simulation to ensure things were working, which I wasn't able to get right until before Thanksgiving. I'll be writing the code that you suggested in your post earlier about running my program on a single core after. Should be able to come back tomorrow with more information after I head to the lab.

I do have one question. I have purchased a ~12x12 inch copper foil piece, I was told this will need to act as my ground for the high voltage power supply. Obviously, I will be cutting out a smaller portion that will be reasonable for the size of my container for the finished device. Should I just solder a wire directly to the copper? If I do that am I going to electrocute anyone that touches the container of the box???

I'm planning on going to Lowe's and buying a decent wood of short width to use as container walls... hopefully copper won't conduct through the wood

https://www.mouser.com/ProductDetail/3M ... V4kp65YvwU
Datasheet: https://www.mouser.com/datasheet/2/1/1181-45855.pdf
Hi friend. I have followed this post and I have been very interested in your project, I have an excellent quality 5Mhz transducer. terminates in a double lemo connector 00 (FFA 00).
I would like to know if you managed to characterize the transducer signal and if you finally managed to meet your objective and how you did it to solve the problems.

Best regards.

davidcoton
Posts: 6582
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Toggling GPIO pins for pulse width of <100ns

@matias.vidalguti
mbferguson

User statistics

Joined:
15 Nov 2018 14:33
Last active:
09 Dec 2018 07:20
I think it's unlikely that the OP will reply.
Location: 345th cell on the right of the 210th row of L2 cache