[英]UWP: Cannot load PWM Controllers using Lightning on Raspberry Pi 2?
[英]How to use MS-IoT Lightning to set/get PWM with Raspberry Pi2?
我想獲得兩個PWM信號(即PWM輸入)的頻率和占空比,並根據輸入將它們設置為另一個(即PWM輸出)。 這些PWM信號的占空比為50%,而其頻率范圍為1kHz至20kHz。
我檢查了一下網頁,我從Windows 10 IoT Core找到了Microsoft IoT Lightning Library(即Bus Providers)。 即使使用PWM Consumer示例,這個庫似乎也是我需要的!
然而,當我在測試基於PWM Consumer 1的第一個示例時,我注意到PWM控制器的頻率范圍限制在40Hz到1kHz之間。 因此,第一個問題:似乎不支持頻率范圍。
此外,當PWM控制器屬性“ActualFrequency”返回通過“SetDesiredFrequencyMethod”設置的頻率時,PWMPin對象僅提供有關當前占空比的信息。
因此,我用谷歌搜索尋找答案,我發現這個問題比以前的兩個問題更令我困惑。
您知道是否可以以及如何使用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);
}
一切順利,洛倫佐
Raspberry PI不是一個實時系統(它具有緩存和分支預測),因此它不能像這樣處理PWM信號。 當指令導致高速緩存刷新時,它無法准確地測量微秒時序,如果語句未能通過預測,則無法准確測量微秒時序。 Microsoft IoT Lightning以arduino為例,它是實時的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.