最初我怀疑我需要使用闪电驱动程序才能达到我需要的中断频率。事实证明,标准收件箱驱动程序足以满足我的需要。
以下是重现我的情况的步骤:
我创建了一个简单的 Arduino 草图,它会以 10,000 Hz 的速率发出脉冲。
int dataPin = 12;
void setup() {
pinMode(dataPin, OUTPUT);
}
void loop() {
int count = 0;
while (count < 400)
{
//pulse
digitalWrite(dataPin, HIGH);
digitalWrite(dataPin, LOW);
//This delay presumably makes the pulse be 10000 Hz
delayMicroseconds(100);
count++;
}
delay(5000);
}
创建了一个带有简单 UI 的 UWP 应用,该应用在页面中心有一个 TextBlock。
public sealed partial class MainPage : Page
{
private GpioController gpio;
private const int inputPinNumber = 17;
private GpioPin inputPin;
private int count;
private I2cController i2cController;
private SpiController spiController;
public MainPage()
{
this.InitializeComponent();
this.Setup();
}
private void Setup()
{
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}
this.gpio = GpioController.GetDefault();
this.inputPin = this.gpio.OpenPin(inputPinNumber);
if (this.inputPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
this.inputPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
this.inputPin.SetDriveMode(GpioPinDriveMode.Input);
}
this.inputPin.ValueChanged += InputPinOnValueChanged;
}
private void InputPinOnValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
if (args.Edge == GpioPinEdge.FallingEdge)
{
this.count++;
this.CountBlock.Text = this.count.ToString();
}
else
{
}
});
}
}
}
将 Windows IoT 设置为使用直接内存映射驱动程序。
下一步是通过晶体管将 Arduino 上的引脚与 Pi 上的引脚连接起来。我这样做是为了利用 Pi 上 GPIO 引脚上的内置上拉电阻。
当两个应用程序同时运行时,我每个周期只收集大约 30 个脉冲。
返回 Windows IoT 设置并将驱动程序重置回收件箱驱动程序并重新运行这两个应用程序。这一次我没有错过任何一个脉搏。
总之,收件箱驱动程序应该足以让我达到 10khz 没有任何问题。