如果我尝试打开PWM引脚,Windows 10 Iot Core应用程序将崩溃

时间:2019-05-30 13:03:25

标签: c# windows-10-iot-core pwm

我想打开蜂鸣器的PWM引脚。但是,如果我尝试调用N=60; t=3; K=130; M = 0:0.1:1.4; r = zeros(size(M)); for i = 1:length(M) f=le(1/K,M(i)); c=le(M(i),3*N/K); if f || c R2 = @(s) -(s-(s./ floor(N./s)).*M(i)); LB = 1; UB = min(N, K); options = optimoptions('fmincon','Algorithm','interior-point'); % run interior-point algorithm [sopt, ropt] = fmincon(R2,1,[],[],[],[],LB,UB,[],options); r(i) = -ropt; end end plot(0:0.1:1.4,r,'r-','LineWidth',2); xlabel('Cache Capacity (M)'); ylabel('Delivery Rate (R)'); 方法,则该应用程序会因pwmController.OpenPin(6)而崩溃。

我已经仔细检查了ms-iot-samples之类的样本来源。但是我看不出我的问题。

一个想法是缺少某些权限,但是如果我尝试添加示例System.Runtime.InteropServices.SEHException,则无法再构建该应用程序。

来源

<iot:Capability Name="lowLevelDevices" />

我也尝试了以下tip to reduce the min required Windows version,但这也无济于事。

1 个答案:

答案 0 :(得分:1)

PWM控制器需要闪电支持。因此,您需要将控制器驱动程序设置为Direct Memory Mapped DriverHere是有关Raspberry Pi上PWM的示例。

enter image description here

您还需要修改以下代码:

    private async void InitAsync()
    {
        Logger.Log(this, "Init");

        // Setup PWM controller.
        if (LightningProvider.IsLightningEnabled)
        {
            var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());
            if (pwmControllers == null || pwmControllers.Count < 2)
            {
                throw new OperationCanceledException("Operation canceled due missing GPIO controller");
            }

            pwmController = pwmControllers[1];
            pwmController.SetDesiredFrequency(50);

            // Setup buzzer
            buzzerPin = pwmController.OpenPin(13);
            buzzerPin.SetActiveDutyCyclePercentage(0.05);
            buzzerPin.Start();
        }
    }