How to use MS-IoT Lightning to install / receive PWM using raspberry Pi2?

I would like to get the frequency and duty cycle of two PWM signals (i.e. PWM inputs) and set them for another (i.e. PWM output) depending on the inputs. These PWM signals have a duty cycle of 50%, and their frequency range is from 1 kHz to 20 kHz.

I checked the network a bit and I found the Microsoft IoT Lightning Library (i.e. bus providers) from Windows IO I Core. I seem to need this library, even with the PWM Consumer example!
However, while I was testing my first example based on the PWM Consumer , I noticed that the frequency range of the PWM controller is limited from 40 Hz to 1 kHz. Therefore, the first question: the frequency range is not supported.
Moreover, while the PWM Controller's “ActualFrequency” property returns the frequency set using the “SetDesiredFrequencyMethod”, PWMPin objects provide only information about the current duty cycle.

Therefore, I googled looking for some kind of answer, and I found this question that bothers me even more than the two previous questions.

Do you know if it is possible and how to use the MS-IoT Lightning Library to set / receive PWM signals from 1 kHz to 20 kHz on raspberry Pi2?

Here are a few lines of code from the example:

    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);
    }

All the best, Lorenzo

+4
source share
2 answers

The IoT lightning infrastructure seems to have a software limitation on the output frequency of the PWM controller, see this file .

, , , , , Max/MinFrequency, , nuget.

, .

Lightning inbox , pwm, , , 1 .

+1

Raspberry PI ( ), PWM . , , . Microsoft IoT Lightning arduino , .

0

Source: https://habr.com/ru/post/1657465/


All Articles