ReadPulse can't work for measure frequency

In addition, I would like to have extended control of the internal ADC (if possible)

Please elaborate

In ADC main features I see
‚ÄúChannel-wise programmable sampling time‚ÄĚ
‚ÄúOversampling ratio adjustable from 2 to 1024x‚ÄĚ
‚ÄúContinuous mode converts selected inputs continuously‚ÄĚ
I would like to be able to use these functions through the API and not just through registers

TinyCLR is not built to satisfy what the processor can do. It is made to satisfy real life application’s needs. Plus the feature has to be generic so it can help everyone.

at least adjust ‚Äúsampling time‚ÄĚ because this should affect measurement stability for our real life applications

I agree with @jooos here, this will greatly benefit the stability of measurements.

I could defenitely use stable ADC readings in my next project :slight_smile:

Not sure I understand. Please explain

When sampling from a ADC, you are turning a continuous signal into a momentary signal. You are basically taking snapshots of the signal at a usually defined and constant rate.

If you have some noise on your signal, it is possible that you take a snapshot at the exact moment your signal gets changed by noise. This might seem like something that does not happen often, but if you are sampling at high frequencies (say more than 1kHz) this is defenitely a annoyance that can change your outcome.

By increasing the sample time, the ADC takes a longer time to make a measurement. This means that if there is a small peak of noise, it will be averaged out compared to other voltages measured by the ADC.

This is what I remember from my DSP classes, someone please correct me if I am wrong. :slight_smile:

1 Like

Here it is

1 Like

And now in the Digital_OnCaptureReady event we get a picosec?

Please try it and let us know if you see any issues

–°apture above 20MHz does not work correctly

var pwm1 = PwmController.FromName(SC20260.Timer.Pwm.Controller1.Id);
var pwm1_2 = pwm1.OpenChannel(SC20260.Timer.Pwm.Controller1.PJ11);
pwm1.SetDesiredFrequency(25_000_000); //max = 60_000_000

var digitalSignalPin = GpioController.GetDefault().OpenPin(SC20260.Timer.Capture.Controller2.PB3);
var digitalSignal = new DigitalSignal(digitalSignalPin);

bool waitForEdge = false;// Start capturing as soon as Capture is called
digitalSignal.OnCaptureReady += Digital_OnCaptureReady;
while (true)
    digitalSignal.Capture(2, GpioPinEdge.RisingEdge, waitForEdge, TimeSpan.FromSeconds(0.3));

private static void Digital_OnCaptureReady(DigitalSignal sender, uint[] buffer, uint count, GpioPinValue pinValue)
    if (count == 0)
        Debug.WriteLine("no data was captured!");
    for (int i = 0; i < count; i++)
        Debug.WriteLine("Sample [" + i + "]: " + buffer[i]);
    if (buffer != null)
        if (buffer.Length > 0 && buffer[1] != 0)
            var freq = 1.0 / (buffer[1] / 1000000000.0);
            Debug.WriteLine("freq = " + freq + " Hz");

I haven’t run code yet, but only 2 pulses and bool waitForEdge = false so I don’t think it is accurate.

starting 2 values are repeated

What Dat means is that WaitForEdge will have to start the mechanism in in software and so the first pulse will not be accurate. Run a loop in your event and calculate frequency on the first 100 pulses and let us know what you see please.

Regardless, reading a single pulse and assuming the frequency on 20Mhz may not be the best idea. There maybe noise on the wires for example. Take multiple reads and use the mid point…

digitalSignal.Capture(100, GpioPinEdge.RisingEdge, waitForEdge, TimeSpan.FromSeconds(0.5));
Sample [0]: 95
Sample [1]: 41
Sample [99]: 41
freq = 24390243.902439 Hz

all 99 values = 41

Hi we have checked on scope,

20MHz is fine.
Your code is 25MHz which is not really 25MHz. it is 23.98MHz ~24.33MHz on my scope.

Oh yes, I forgot about this! PWM may not be exact. It all depends on the source clock and the available dividers.

@jooos please use a scope and confirm you are seeing correct values if possible.

Now I understand. Need a stable signal source.
I just wanted to know the maximum measured frequency.
I tested 1Hz from PWM and got freq = 0.999921007240349Hz

1 Like