Digital Signal Pins

Howdy,

I’m attempting to create a high speed pulse counter by using the two digital signal pins on the SCM20260D (PA0 & PB3). I’m using the digital signal pins because they can run non-blocking, but if there’s another way to read <1ms pulses I’m open to alternate methods. Just reading standard GPIO pins does not read consistently enough for my use case.

If I only use one of the two digital signal pins, I’m able to get consistent readings using the _digSigObject.OnCaptureFinished event and .Capture() function. However, when I add the second digital signal pin, only one of the two events executes, and which of the two pins to get captured seems to be random.

Is this an expected issue and I can only use one digital signal pin at a time, or is there a way to setup both pins so they can capture simultaneously?

Useful info: When I call Capture() for both, count is 64, detection edge is falling, waitForEdge is true, and the timeout is 200ms. The signal pulse values are about 2-4ms apart. Right now I’m just printing the buffer values to the debug console. I’m also testing using a Wiegand card reader.

EDIT:
I also tried setting waitForEdge = false, and just polling every 200 ms but still had the same issue.

Hi, could you provide a simple code to reproduce please?

That will help us to see the issue (and fix if needed) faster.

This is the only code running on the SCM20260 Dev board connected to a Wiegand card reader through pins PA0 (Data0) and PB3 (Data1). If you have any questions please ask.

using System;
using System.Threading;
using System.Diagnostics;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Signals;

namespace Wiegand_Testbench
{
    public static class Program
    {
        //Signal pins
        private static DigitalSignal _digitalSignalData0;
        private static DigitalSignal _digitalSignalData1;
        private static GpioPin _gpioD0Pin;
        private static GpioPin _gpioD1Pin;
        private const int Data0PinNumber = SC20260.Timer.DigitalSignal.Controller5.PA0;
        private const int Data1PinNumber = SC20260.Timer.DigitalSignal.Controller2.PB3;

        //Constants
        private const uint MaxDataValues = 64;
        private const GpioPinEdge DetectionEdge = GpioPinEdge.FallingEdge;
        private const double CaptureTimeoutMs = 200;

        //Main application entry point
        private static void Main()
        {
            //Bootup message
            Debug.WriteLine("Booting up...");

            //Initialize the D0 signal pin
            _gpioD0Pin = GpioController.GetDefault().OpenPin(Data0PinNumber);
            _digitalSignalData0 = new DigitalSignal(_gpioD0Pin);
            _digitalSignalData0.OnCaptureFinished += SignalD0CaptureComplete;

            //Initialize the D1 signal pin
            _gpioD1Pin = GpioController.GetDefault().OpenPin(Data1PinNumber);
            _digitalSignalData1 = new DigitalSignal(_gpioD1Pin);
            _digitalSignalData1.OnCaptureFinished += SignalD1CaptureComplete;

            Debug.WriteLine("Bootup complete.");

            while (true)
            {
                //Read any D0 signals
                if (_digitalSignalData0.CanCapture)
                {
                    Debug.WriteLine("Capturing D0...");
                    _digitalSignalData0.Capture(MaxDataValues, DetectionEdge, true, TimeSpan.FromMilliseconds(CaptureTimeoutMs));
                }

                //Read any D1 signals
                if (_digitalSignalData1.CanCapture)
                {
                    Debug.WriteLine("Capturing D1...");
                    _digitalSignalData1.Capture(MaxDataValues, DetectionEdge, true, TimeSpan.FromMilliseconds(CaptureTimeoutMs));
                }

                //Execute once per second
                Thread.Sleep(1000);
            }
        }

        private static void SignalD0CaptureComplete(DigitalSignal signal, double[] buffer, uint count, GpioPinValue endState)
        {
            //Ignore empty data
            if (buffer == null || count == 0)
            {
                return;
            }

            Debug.WriteLine($"Signal D0 capture complete - {count} values received (End State: {(endState == GpioPinValue.Low ? "low" : "high")}).");
            double totalTime = 0;

            //Iterate through the buffer and extract the time values
            for (uint i = 0; i < count; i++)
            {
                totalTime += buffer[i];
                Debug.WriteLine($"Sample [{i}]: {totalTime / 1000000} ms (dt = {buffer[i] / 1000000} ms)");
            }
        }

        private static void SignalD1CaptureComplete(DigitalSignal signal, double[] buffer, uint count, GpioPinValue endState)
        {
            //Ignore empty data
            if (buffer == null || count == 0)
            {
                return;
            }

            Debug.WriteLine($"Signal D1 capture complete - {count} values received (End State: {(endState == GpioPinValue.Low ? "low" : "high")}).");
            double totalTime = 0;

            //Iterate through the buffer and extract the time values
            for (uint i = 0; i < count; i++)
            {
                totalTime += buffer[i];
                Debug.WriteLine($"Sample [{i}]: {totalTime / 1000000} ms (dt = {buffer[i] / 1000000} ms)");
            }
        }
    }
}

EDIT:
The firmware is v2.2.0.6200. Again, only one of the signal pins seems to read during a card swipe and the output console looks something like this:

'GHIElectronics.TinyCLR.VisualStudio.ProjectSystem.dll' (Managed): Loaded 'C:\Users\Will\Documents\Projects\19 - Wiegand Testbench\Firmware\Wiegand_Testbench\bin\Debug\pe\..\mscorlib.dll'
'GHIElectronics.TinyCLR.VisualStudio.ProjectSystem.dll' (Managed): Loaded 'C:\Users\Will\Documents\Projects\19 - Wiegand Testbench\Firmware\Wiegand_Testbench\bin\Debug\pe\..\GHIElectronics.TinyCLR.Native.dll'
'GHIElectronics.TinyCLR.VisualStudio.ProjectSystem.dll' (Managed): Loaded 'C:\Users\Will\Documents\Projects\19 - Wiegand Testbench\Firmware\Wiegand_Testbench\bin\Debug\pe\..\GHIElectronics.TinyCLR.Devices.Gpio.dll'
'GHIElectronics.TinyCLR.VisualStudio.ProjectSystem.dll' (Managed): Loaded 'C:\Users\Will\Documents\Projects\19 - Wiegand Testbench\Firmware\Wiegand_Testbench\bin\Debug\pe\..\GHIElectronics.TinyCLR.Devices.Signals.dll'
'GHIElectronics.TinyCLR.VisualStudio.ProjectSystem.dll' (Managed): Loaded 'C:\Users\Will\Documents\Projects\19 - Wiegand Testbench\Firmware\Wiegand_Testbench\bin\Debug\pe\..\Wiegand_Testbench.exe', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Booting up...
Bootup complete.
Capturing D0...
Capturing D1...
Signal D0 capture complete - 13 values received (End State: low).
Sample [0]: 2.050918227 ms (dt = 2.050918227 ms)
Sample [1]: 14.408835948 ms (dt = 12.357917721 ms)
Sample [2]: 18.528102963 ms (dt = 4.119267015 ms)
Sample [3]: 20.593364004 ms (dt = 2.065261041 ms)
Sample [4]: 22.653024597 ms (dt = 2.059660593 ms)
Sample [5]: 24.712572681 ms (dt = 2.059548084 ms)
Sample [6]: 30.901071888 ms (dt = 6.188499207 ms)
Sample [7]: 39.139447572 ms (dt = 8.238375684 ms)
Sample [8]: 41.199028992 ms (dt = 2.05958142 ms)
Sample [9]: 45.318075156 ms (dt = 4.119046164 ms)
Sample [10]: 51.496623567 ms (dt = 6.178548411 ms)
Sample [11]: 57.674926125 ms (dt = 6.178302558 ms)
Sample [12]: 63.853603713 ms (dt = 6.178677588 ms)
Capturing D0...
Capturing D1...

Thank, we will look into it soon

I hooked up an oscilloscope to make sure I wasn’t crazy and this is the reading for the same card (32 bits) in the console output above. The D0 pin is blue, and the D1 pin is yellow.

I noticed two more things:

  1. The first pulse isn’t included in the capture buffer while using the wait for edge functionality, would be nice to have that value with a time delta of zero? May be silly…

  2. When reading the card, since the D0 pin is triggered first, the D0 capture event is always the one triggered. It is not random like I thought before.

Hi,
Update latest 2.2.0.7000 and let us know if any other issue.

You need both firmware and library to correct the issue.

Downloads (ghielectronics.com)

Looks like the update worked! Reading out both events now, thanks!

3 Likes