c# – 如何使用MS-IoT Lightning使用Raspberry Pi2设置/获取PWM
我想获得两个PWM信号(即PWM输入)的频率和占空比,并根据输入将它们设置为另一个(即PWM输出).这些PWM信号的占空比为50%,而其频率范围为1kHz至20kHz.
我检查了一下网页,我从Windows 10 IoT Core找到了Microsoft IoT Lightning库(即总线提供商).即使使用PWM Consumer示例,这个库似乎也是我需要的! 因此,我用谷歌搜索寻找答案,我发现this question比以前的两个问题更让我困惑. 您知道是否可以以及如何使用MS-IoT Lightning Library在Raspberry Pi2上设置/获取1kHz至20kHz的PWM信号? 这里,示例中的几行代码: public async void Run(IBackgroundTaskInstance taskInstance) { if (!LightningProvider.IsLightningEnabled) { // Lightning provider is required for this sample return; } var deferral = taskInstance.GetDeferral(); // Use the PAC9685 PWM provider,LightningPCA9685PwmControllerProvider pwmController = (await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()))[0]; motorPin = pwmController.OpenPin(0); secondMotorPin = pwmController.OpenPin(1); //// To use the software PWM provider,LightningSoftwarePwmControllerProvider,with GPIO pins 5 and 6,//// uncomment the following lines and comment the ones above //pwmController = (await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()))[1]; //motorPin = pwmController.OpenPin(5); //secondMotorPin = pwmController.OpenPin(6); pwmController.SetDesiredFrequency(50); motorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth); motorPin.Start(); secondMotorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth); secondMotorPin.Start(); timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick,TimeSpan.FromMilliseconds(500)); } private void Timer_Tick(ThreadPoolTimer timer) { iteration++; if (iteration % 3 == 0) { currentPulseLength = ClockwisePulseLength; secondPulseLength = CounterClockwisePulseLegnth; } else if (iteration % 3 == 1) { currentPulseLength = CounterClockwisePulseLegnth; secondPulseLength = ClockwisePulseLength; } else { currentPulseLength = 0; secondPulseLength = 0; } double desiredPercentage = currentPulseLength / (1000.0 / pwmController.ActualFrequency); motorPin.SetActiveDutyCyclePercentage(desiredPercentage); double secondDesiredPercentage = secondPulseLength / (1000.0 / pwmController.ActualFrequency); secondMotorPin.SetActiveDutyCyclePercentage(secondDesiredPercentage); } 一切顺利,洛伦佐 解决方法
物联网闪电框架似乎对PWM控制器输出频率有软件限制,请参见
file.
不确定这是否有效,但值得一试的是复制闪电repository,修改Max / MinFrequency常量,构建项目,并直接在源项目中引用它,而不是引用nuget包. 我期待这种方法用范围进行测试. 或者,使用默认的收件箱驱动程序,而不是使用Lightning驱动程序,可以在here找到pwm设备驱动程序,尝试查看是否可以使用1kHz以上的更高频率. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |