[英]How to get better performance out of GPIO pins on Raspberry pi in Windows IOT core
I have the following code running on a raspberry pi 3 running windows 10 using C#我在使用 C# 运行 Windows 10 的 raspberry pi 3 上运行以下代码
GPIO init .... GPIO 初始化 ....
_gpioController = GpioController.GetDefault();
_motorPin = _gpioController.OpenPin(Convert.ToInt32(RaspberryGPIOpin);
_motorPin.SetDriveMode(GpioPinDriveMode.Output);
GPIO pin on off GPIO 引脚打开关闭
_motorPin.Write(GpioPinValue.High);
_motorPin.Write(GpioPinValue.Low);
The problem is that in my application to turn on and off the GPI pin takes 100 milliseconds, but I need this it happen in less that 25 milliseconds to change the direction of a servo.问题是,在我的应用程序中,打开和关闭 GPI 引脚需要 100 毫秒,但我需要在不到 25 毫秒的时间内改变伺服的方向。
Is there a way to speed up the on off of the GPIO pins?有没有办法加快 GPIO 引脚的开启?
or should I be looking at a hardware controller of some sort, to control the servo.或者我应该看看某种硬件控制器来控制伺服。 I would prefer not to do this.我宁愿不这样做。 My code is also running in a thread as well.我的代码也在一个线程中运行。 should I remove the threading?我应该删除线程吗?
I have a much simpler application where the code does work...https://github.com/StuartSmith/RaspberryPi-Control-Sg90-Example我有一个更简单的应用程序,代码确实可以工作...https://github.com/StuartSmith/RaspberryPi-Control-Sg90-Example
Microsoft provides a complete test result on toggling GPIO bit using raspberry pi 2, find it in https://developer.microsoft.com/en-us/windows/iot/docs/lightningperformance . Microsoft 提供了关于使用 raspberry pi 2 切换 GPIO 位的完整测试结果,可在https://developer.microsoft.com/en-us/windows/iot/docs/lightningperformance 中找到。
So you can see the result varies with IoT version, driver model, .NET native toolchain, and even programming languages.因此您可以看到结果因物联网版本、驱动程序模型、.NET 原生工具链甚至编程语言而异。 But in the worst case, approximately 10kHz can be achieved.但在最坏的情况下,可以达到大约 10kHz。
I haven't tested on the latest IoT Redstone 1 release, but I'm guessing it should have similar performance with TH2.我还没有对最新的 IoT Redstone 1 版本进行测试,但我猜它应该具有与 TH2 相似的性能。
So, in general, choose the lightning driver over the default inbox driver , it's supposed to have better performance on GPIO ports.所以,一般来说,选择 Lightning 驱动程序而不是默认的内置驱动程序,它应该在 GPIO 端口上有更好的性能。
Also disabling the .NET native toolchain will have noticeably better performance as well.此外,禁用 .NET 本机工具链也将具有明显更好的性能。
I'm seeing you're using the GPIO pin to drive the servo, the software timing should be good enough in this case.我看到您正在使用 GPIO 引脚来驱动伺服,在这种情况下,软件时序应该足够好。 However if you want to use it for clock source that needs high precision, don't trust on the software timing(lighting provider), the software jitter is always unpredictable .但是,如果要将其用于需要高精度的时钟源,请不要相信软件时序(照明供应商),软件抖动总是不可预测的。 One good alternative is to use the build-in DMA controller , which uses hardware timing and should have precision within 1 micro-second.一种不错的选择是使用内置DMA 控制器,它使用硬件定时,精度应在 1 微秒内。
How did you measure 100ms?你是如何测量100ms的? Is 100ms how long it took to run the two Write() calls, or was there other code in there?运行两次 Write() 调用需要 100 毫秒,还是那里有其他代码?
We measured each Write() call at 3.6 microseconds (from a C++ app).我们以 3.6 微秒(来自 C++ 应用程序)测量了每个 Write() 调用。
The first Write() call after you open a pin and set drive mode may take longer than subsequent calls due to the way the underlying stack works.由于底层堆栈的工作方式,打开引脚并设置驱动模式后的第一次 Write() 调用可能比后续调用花费的时间更长。 Did your measurement include the first Write() call?您的测量是否包括第一个 Write() 调用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.