PWM Pins behaving inconsistently

kwollmankwollman New Member Posts: 2

I'm on an Up Board. When I type uname -a:

Linux splash 4.15.0-37-generic #40~upboard04-Ubuntu SMP Thu Feb 14 13:49:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I'm trying to use the 2 PWM pins to control the GB value on an RGB LED, but the PWM pins are behaving inconsistently.

I'm following the example from the pinout guide:

echo 0 > /sys/class/pwm/pwmchip0/export
echo 3413333 > /sys/class/pwm/pwmchip0/pwm0/period
echo 1706667 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable

My understanding is that when I echo 1 into the "enable" folder it should enable that pin and that "echo 0" into that pin should disable it. The behavior that I'm expecting is that the LED will be turned on when the pin is enabled and turned off when the pin is disabled. This is not always the case however. Sometimes if the enable folder contains a 1 and I echo a 0 into it, the LED will get brighter rather than turning off. Sometimes if the file contains a 1 and I echo a 1 and then echo a 0 it will turn the LED off.

I need the LED to turn on and off reliably and get the PWM pins to behave in a predictable manner. Are my assumptions about the enable/disable functionality correct, and if so any ideas about why it is not behaving consistently? Is there something about trying to use both PWM pins that could be causing erratic behavior?

Thanks.

Tagged:

Comments

  • Dan O'DonovanDan O'Donovan Emutex Posts: 230 mod

    @kwollman
    I vaguely remember a hardware bug in the PWM controller on the UP Board Cherry-Trail SoC which could cause the PWM disable to be unreliable. Can you try setting the duty_cycle to 0 before disabling the PWM output to see if that helps?

  • ccaldeccalde Administrator, Moderator, Emutex Posts: 348 admin

    Hi @kwollman ,

    Could you give more information about your setup?
    Ubuntu version
    kernel version: Are you using the official supported version right?
    BIOS version
    Setup for testing PWM pin
    Used PWM0 or PWM1?

  • kwollmankwollman New Member Posts: 2

    @Dan O'Donovan thanks for letting me know about the potential bug. The article you linked is unavailable and searching google for "CHT36 atom z8000" returns only that dead link. When I put the duty cycle to 0 there is still a little bit of light on the LED, which goes against my expectation that the light wouldn't be on at all.

    @ccalde thanks for responding. I am using ubuntu 18.04.3. I installed the up board linux kernel following the instructions on the Ubuntu UpWiki. I am trying to use both PWM pins at the same time to control the green and blue values of a RGB Led. The following is the output of the command "sudo dmidecode" :

    BIOS Information
    Vendor: American Megatrends Inc.
    Version: UPC1DM17
    Release Date: 02/20/2019
    Address: 0xF0000
    Runtime Size: 64 kB
    ROM Size: 4096 kB
    Characteristics:
    PCI is supported
    BIOS is upgradeable
    BIOS shadowing is allowed
    Boot from CD is supported
    Selectable boot is supported
    BIOS ROM is socketed
    EDD is supported
    5.25"/1.2 MB floppy services are supported (int 13h)
    3.5"/720 kB floppy services are supported (int 13h)
    3.5"/2.88 MB floppy services are supported (int 13h)
    Print screen service is supported (int 5h)
    Serial services are supported (int 14h)
    Printer services are supported (int 17h)
    ACPI is supported
    USB legacy is supported
    BIOS boot specification is supported
    Targeted content distribution is supported
    UEFI is supported
    BIOS Revision: 5.11

    The way that I've been testing the disable functionality for the two pins was to put an ohm meter inline while trying to activate the LED. When enable the pin it reads either 3.3 or 1.7 volts, and sometimes (but not always and not in a predictable manner) when I disable it, the voltage goes to 0 volts and the LED turns off.

  • ccaldeccalde Administrator, Moderator, Emutex Posts: 348 admin

    Hi @kwollman ,

    Thank you for the information about your setup.
    We will try to replicate the issue here locally as soon as possible to get a solution.

  • ccaldeccalde Administrator, Moderator, Emutex Posts: 348 admin

    Hi @kwollman ,

    That is the issue information in the Intel Atom specifications about the PWM:

    "CHT36 Disabling PWM[1:0] Signals May Not Work

    Problem: Clearing PWM_Enable field (bit 31) in PWMCTRL registers (Bus 0; Device 30; Function
    1,2; Offset 10H) should disable PWM (Pulse Width Modulation) Output. However, due
    to this erratum, the PWM[1:0] signals may remain enabled after clearing PWM_Enable
    under certain conditions.

    Implication: Hardware connected to the PWM signals may not behave as expected.

    Workaround: Intel has identified PWM driver workaround for this erratum. The driver should write
    all ‘0’s to PWM_Base_Unit field (bits 23:8) of PWMCTRL register, followed by setting
    PWM_SW_Update to ‘1’ before clearing PWM_Enable field.

    Status: No fix."

    Does it make sense for your case?

  • ccaldeccalde Administrator, Moderator, Emutex Posts: 348 admin

    Hi again,

    I just tested the pwmchip0 and pwmchip1 on UP board.
    For all cases, I enable and disable the PWM pin checking the voltage directly in the pin using a multimeter:
    1.6V enabled, 0V disabled all time.

Sign In or Register to comment.