DigitalSignal Capture Accuracy

Hello,

What accuracy can we expect for DigitalSignal.Capture on SC13048? I’m seeing values ranging by up to 800ns between falling edges from a known signal. The known signal is being sent by a frequency generator and confirmed by scope. It seems like the captured values are always at least 150ns too long.

On 20260D I’m seeing values being ~30ns larger than expected, but very stable.

Any config that could be wrong to cause that or tips to improve?

Thanks,
Glen

Hi, we just checked,

SC13x could be ~150ns ~6.5MHz
SC20x could be ~40ns = 25MHz.

For SC13 we use PA2 to generate pwm
and capture from PA1.

Send us your code if you have different result.

PWM code:

 // sc13xxx PA2
            var pwmController = PwmController.FromName("GHIElectronics.TinyCLR.NativeApis.STM32L4.PwmController\\14");
            var pwmchannel = pwmController.OpenChannel(0);


            pwmController.SetDesiredFrequency(6000000);

            pwmchannel.SetActiveDutyCyclePercentage(0.25);

            pwmchannel.Start();

Capture code.

 var pin = GpioController.GetDefault().OpenPin(SC13048.GpioPin.PA1);

var dsig = new DigitalSignal(pin);

 dsig.OnCaptureFinished += Dsig_OnCaptureFinished;

while (true)
{
                if (dsig.CanCapture)
                {
                    dsig.Capture(1000, GpioPinEdge.FallingEdge, false);
                }

                Thread.Sleep(10);
}

private static void Dsig_OnCaptureFinished(DigitalSignal sender, double[] buffer, uint count, GpioPinValue initialState)
        {
            if (count == 0)
                return;

            var t = 0D;
            for (var i = 1; i < count; i++)
            {
                t += buffer[i];
            }

            t /= (count - 1);

            var freq = 1000000000.0 / t;

            Debug.WriteLine("freq = " + freq + " Hz, ns= " + t + ", count " + count);
        }
1 Like

Hi Dat,

Thanks for looking into this. Results from your code are consistent with mine. When doing a capture on a 2500Hz (400us) signal with 1000 samples using SC13 I get the following results (ignoring the first value):

Average = 400237
Median = 400238
Max = 400550
Min = 400088

Any chance of increasing that clock rate for the capture (maybe even as a special mode on the CPU)? This is an awesome feature but the current rate leads to errors of up to 3-4Hz at the frequencies we need to measure.

Thanks,
Glen

This mode use DMA, everything is done by hardware.

Let me read more on document to see anything we can improve, but so far I don’t think we can. We give DMA a buffer and bring this buffer to user when DMA done.

On SC20 it is more accurate you mean? Is the source generate clock correctly? :)).

Hum, I used code above to generate PWM, change to 2500Hz.

max min is very accurate on SC13.

Can you check source generator?

Hi Dat,

I do see much better results on SC20.

In your example is the source / capture on the same SC13? I setup a 2.5kHz PWM on PA2 on SC13. I’m seeing a similar issue with accuracy on the scope and protocol analyzer. The output frequency is 3-5Hz off. If you were going from SC13 to SC13 maybe the PWM / Capture accuracy cancels out and that’s why you got such perfect results?

Saleae single wave:
image

Salese average freq:

Scope stats:

To me it seems like the PWM and Capture use a similar accuracy timer behind the scenes. Can the frequency of that timer be cranked up in the hardware config?

Regards,
Glen

Interesting.

Good thing to me that there is no thing we can do so far, look to me hardware issue.
Bad thing to you is, something you need to do :)).

We will spend a bit more to see what we can help.

Thanks Dat.

No real surprise here: but FYI this is from SC20260 PWM at 2.5kHz 2.49997kHz measured.

1 Like

Just closing this one off… The issue was that we were testing on FEZ Flea so I’m assuming this was just a lack of xtal. It works great in production with a good xtal and on the SC13048Q dev board. Sorry for the false lead!

1 Like