Skip to content

Linux PWM implementation throws during construction/setting frequency in some cases #757

Closed

Description

@krwq

Repro:

using (var pwm = PwmChannel.Create(0, 0, 500))
{
   // duty cycle is 0.5 by default
   pwm.Frequency = 10000; // throws
}

from now constructing pwm channel with frequency 10k Hz is not possible without manually editing duty cycle (sysfs).

This is happening because duty cycle still has the old value in the driver (measured in nanosecond) and updating frequency causes that duty cycle gets out of range

Activity

  1. added
    bug
    on Oct 1, 2019
  2. self-assigned this
    on Oct 1, 2019
  3. shaggygi commented on Oct 1, 2019

    @shaggygi
    Contributor

    I noticed this when we were updating to the new PwmChannel. I believe it is because there is not enough time delayed when opening the port (via file) before interacting with the DC/freq. I mentioned it then, but we couldn't figure out a good approach on timing.

    I could duplicate using the PwmPinOutput command in the DeviceTesterApi.

    After the exception occurs, you can still see the channel opened by reading the file. And writing the DC/freq works by then, as well.

  4. krwq commented on Oct 2, 2019

    @krwq
    MemberAuthor

    @shaggygi, I've added a fix in #758 - I got 100% repro before and now doesn't repro with the fix.

    In some scenarios this is not particularly obvious:

    • you create PWM with one frequency and dispose
    • you create PWM with different frequency and it throws when constructing

    The issue is with duty cycle being out of range (also IO exception suggests that: Invalid argument)

  5. added
    area-System.Device.Gpio
    on Oct 10, 2019
  6. added this to the milestone on Oct 10, 2019
  7. joperezr commented on Oct 10, 2019

    @joperezr
    Member

    Would we want to service 1.0 with this?

  8. krwq commented on Oct 10, 2019

    @krwq
    MemberAuthor

    I don't have strong opinion either way. On one hand this is relatively rare but on the other it's super annoying when it affects you

  9. ghost locked as resolved and limited conversation to collaborators on Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Device.Gpiobug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions