Help, i need an Analog delay circuit

drjohsmith

Joined Dec 13, 2021
1,615
@crutschow
using a shunt wont eliminate my delay problem as i cant sample simultaneously with the onboard adc's , i still need a deay to compensate for the read time difference of about 100uS as mentioned
@michael8
thats what im leaning toward using s/h with a programmable delay for the holdoff
@Ian
params all previously discussed as well as the mcu etc, no delay gives >70% error @20khz, delay to within 400nS of perfect sync gives 5% error, and obviously a tighter match improves this. the highest freq gives worst error. looking for at least 5% accuracy hopefully better
@Dr
yes sampling continously @ 5ish ksps and storing then averaging and processing after the sample buffer is full, as i said nyquist doesnt matter as this is a long term ave , ive already tested it and its accurate for freq even higher than the 20k target. im not needing 1 cycle resolution so the averaging over tens of thousands of cycles is accurate for repetitive waveforms. the adc is rated at 1msps so is plenty faster enough, reason for it being so slow is the circuitpython interpreter for the code on the M4 samd51 microcontroller is neutering the hardware , but its what i have to work with and try to work around
The interpreter is not limiting the ADC speed,
you "just" need to find out how to access the ADC directly , and allow it to DMA into RAM,
then you can use 50 KHz,

If your sampling at 5 Ksps,
and your averaging,
then no mater what , are not measuring "power" of the higher frequencies,

When you say
" ive already tested it and its accurate for freq even higher than the 20k target"
what test have you done ?

Averaging is a low pass filter,

https://www.analog.com/media/en/technical-documentation/dsp-book/dsp_book_Ch15.pdf

so again the higher frequencies power is lost,
 

Thread Starter

Rod888

Joined Feb 14, 2022
20
using a signal generator into the adc input i ran a 25khz sinewave and sampled it 50,000 times at 5ksps and then parsed the data and the peak value was equal to my generator peak as well as the averaged values turned out to be .707 of the peak so the rms and peak current calcs were exact, ive also done it with triangle and square waves, it works. you're missing the whole point of long term averaging vs transient detection, im not interested in capturing short duration transients, i dont care to discuss this further im looking for analog delay circuits not debates on nyquist or dsp processes.
 

drjohsmith

Joined Dec 13, 2021
1,615
using a signal generator into the adc input i ran a 25khz sinewave and sampled it 50,000 times at 5ksps and then parsed the data and the peak value was equal to my generator peak as well as the averaged values turned out to be .707 of the peak so the rms and peak current calcs were exact, ive also done it with triangle and square waves, it works. you're missing the whole point of long term averaging vs transient detection, im not interested in capturing short duration transients, i dont care to discuss this further im looking for analog delay circuits not debates on nyquist or dsp processes.
Thank you for your thoughts

May be you should write and publish a paper on this sampling idea.

Re delay.

You seem to have the tools to experiment, which is great,

Your delaying I or V to align it with each other

Have you tried your circuit with different delays on I and V
see what effect it has on the averaged answers your using,

Also , try two tones,
say 1 KHz and 6 KHz,
keep one constant amplitude, vary the other
see how your power varies

Regarding how a conventional system would work,
the voltage across a small resistance is measured,
the two voltage levels and the resistance give you the current and voltage at any one time,
from which you can calculate instantaneous , peek, rms , median powers
 

drjohsmith

Joined Dec 13, 2021
1,615
I suggest you read this post by @Yaakov https://forum.allaboutcircuits.com/...h-you-will-almost-certainly-never-see.178685/
You clearly have the wrong microcontroller for the job, and are trying to bodge it to get it to work. There are plenty of microcontrollers than can sample 2 channels within a microsecond, and some with two separate A/d converters that can sample two channels simultaneously.
@Ian0

As far as I know , the OP is using a

https://www.adafruit.com/product/4064

Can some one confirm ?

this has two, 1 Msps ADC,
and thy can sample together at 1 Msps.

more than up to the job,

See page 1584

https://www.mouser.com/datasheet/2/268/60001507A-1130176.pdf
 
Last edited:

Ian0

Joined Aug 7, 2020
13,158
Looks to me like it could sample two channels 1us apart!
What’s all this nonsense about 100us between samples?
Not only that, it’s easily capable of sampling above the Nyquist frequency for 20kHz.
 

drjohsmith

Joined Dec 13, 2021
1,615
Looks to me like it could sample two channels 1us apart!
What’s all this nonsense about 100us between samples?
Not only that, it’s easily capable of sampling above the Nyquist frequency for 20kHz.
The Op has stated

" reason for it being so slow is the circuitpython "


One thought for @Rod888

The analog delay lines pointed to , seem to have too much delay for you to use on one channel

How about putting delay lines on both the current and voltage inputs ?

what is the resolution of the delay lines ?
can you set one to be smaller than the other by the required delay
OK, both inputs are now delayed, bu tyou have them lined up
 

Thread Starter

Rod888

Joined Feb 14, 2022
20
yes the problem is with circuitpython , the mcu is fully capable but there are no libraries for poking the mcu directly to use some of its features like setting clock dividers, adc references, averaging , dma etc so a guy would have to write his own module which is too much for my coding skills, way faster to correct with hardware. Also the reason for the samplerate not needing to follow nyquist is i am only interested in values in time, kind of like taking the average of temperature outside over a day by sampling every half hour, missing the transient deer fart which raises the temperature by .001 degree has minimal effect on the overall average nor do i care to capture it. i can sample a 100Mhz sinewave at a 1 sps rate and it will still give me the level of that sinewave at that particular time, which is the end game, i dont care about doing an accurate fft or restreaming the values, i only care that the simultaneous i and v samples are exactly in phase so they can be multiplied correctly. The only real requirement regarding my samplerate is that the frequency of the signal i am measuring must not be an exact harmonic of my samplerate for obvious reasons, but i have enough jitter in my rate that this is not an issue.
i have not tried any delays and tests as of yet as i was waiting to see if any other alternatives to using two s/h's with a delay line surface but it appears not. i was looking at the ad585 for s/h and havent really chased down a delay but any timer like a 555 setup as a triggerable one shot could be used for the delay, or maybe some cascaded ds1020's which would give me software tuning/calibration options.
interesting point about using 2 bucket brigades one in each branch, that too would take some experiments as im not sure how linear those devices are
What’s all this nonsense about 100us between samples?
circuitpython interpreter/complier is my guess, using an oscilloscope with triggering on one of the adc channels if i program 2 succussive reads on the different channels like
adc0 = analogio.AnalogIn(A0)
adc1 = analogio.AnalogIn(A1)
ch0 = adc0.value
ch1 = adc1.value
V0.append(ch0)
V1.append(ch1)
the reads come about 90uS apart, fastest she'll go, throw it in a loop and toss is some summimg etc and it goes down from there
Not only that, it’s easily capable of sampling above the Nyquist frequency for 20kHz.
i suppose if the code was in assembly but certainly not python. i noticed in forums even the c++ coders are only getting 250ksps with a ton of optimizing, in any case i dont need a high samplerate, just time coherancy
 

drjohsmith

Joined Dec 13, 2021
1,615
If your averaging, and single sampling,
does the current and voltage need to be aligned

Have a go,

As you say, the "fart" is ignored,
thus if the current or voltage is off,
does it matter as the average is going to be correct ?
 

drjohsmith

Joined Dec 13, 2021
1,615
Btw , I think we agree that your jitter will eliminate this , but for future ref of others.

If you sample say a 10 hz waveform at 1 sample per second ,
You could sample all the bottom or all the top of the amplitude. This your average will be wrong.

If your signal is constant , and your sampling is "random" compared to the signal, then you can average and get a value .

But if the signal is not repetitive ,then this does not work .
 

Thread Starter

Rod888

Joined Feb 14, 2022
20
yes exactly on the rate "dither" and i agree the low sr does cause decreasing accuracy as the sampled signal gets less periodic, but i am dealing with signals of significant repetitive periods that i dont have to worry about these errors
the timing does matter as i said a 10uS difference can cause >50% error at 20Khz i need 400nS or better to limit error to 5%.
i have just found another device, an ade7755 which looks like it will solve all my issues and its very cheap, has a 14khz -3db bw so is close enough for my purposes and very simple to read the power values into my uC and scale/correct as needed i could probably even run the data through a correction curve compensating for the device hf rolloff to stretch the bw a bit
 

drjohsmith

Joined Dec 13, 2021
1,615
yes exactly on the rate "dither" and i agree the low sr does cause decreasing accuracy as the sampled signal gets less periodic, but i am dealing with signals of significant repetitive periods that i dont have to worry about these errors
the timing does matter as i said a 10uS difference can cause >50% error at 20Khz i need 400nS or better to limit error to 5%.
i have just found another device, an ade7755 which looks like it will solve all my issues and its very cheap, has a 14khz -3db bw so is close enough for my purposes and very simple to read the power values into my uC and scale/correct as needed i could probably even run the data through a correction curve compensating for the device hf rolloff to stretch the bw a bit

The point on the 50 percent error I get
but

For your averaging to work, the sample needs to be at a random time on the waveform,
QED, The error is "random"
thus the -50 % will at some point be cancelled by a +50 % error.

QED, actual sampling tine in this case does not matter

Try it
 

Thread Starter

Rod888

Joined Feb 14, 2022
20
no because the chip has 2 built in adc's which are already time aligned , phase compensated and setup to do power calcs all on chip, its perfect! all i have to do is read back the result
 

crutschow

Joined Mar 14, 2008
38,538
no because the chip has 2 built in adc's which are already time aligned , phase compensated and setup to do power calcs all on chip, its perfect! all i have to do is read back the result
I may be wrong but I think the current and voltage signals still need to be aligned in time, since the multiplication of the two values together to get the power still must be from the same point in time.

Using a shunt resistor for the current measurement would achieve that.
 

Thread Starter

Rod888

Joined Feb 14, 2022
20
oh i see what your getting at, yes the chip has its own signal conditioning so my current sensor and opamp i originally would have used is all tossed, the chip uses a resistive divider on the v channel and r shunt on the i channel so there will be no lag
 
Top