我想获得两个PWM信号(即PWM输入)的频率和占空比,并根据输入将它们设置为另一个(即PWM输出).这些PWM信号的占空比为50%,而其频率范围为1kHz至20kHz.
我检查了一下网页,我从Windows 10 IoT Core找到了Microsoft IoT Lightning库(即总线提供商).即使使用PWM Consumer示例,这个库似乎也是我需要的!
然而,当我在测试基于PWM Consumer的第一个示例时,我注意到PWM控制器的频率范围限制在40Hz到1kHz之间.因此,第一个问题:似乎不支持频率范围.
此外,当PWM控制器属性“ActualFrequency”返回通过“SetDesiredFrequencyMethod”设置的频率时,PWMPin对象仅提供有关当前占空比的信息.
因此,我用谷歌搜索寻找答案,我发现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); }
一切顺利,洛伦佐
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。