HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
  • SC-3568HA

    • Introduction

      • SC-3568HA Overview
    • Quick Start Guide

      • OpenHarmony Overview
      • Image Flashing
      • Setting Up the Development Environment
      • Hello World Application and Deployment
    • Application Development

      • ArkUI

        • Chapter 1 Introduction to ArkTS Language
        • Chapter 2 Introduction to UI Components and Practical Applications (Part 1)
        • Chapter 3 Introduction to UI Components and Practical Applications (Part 2)
        • Chapter 4 Introduction to UI Components and Practical Applications (Part 3)
      • Expand

        • Chapter 1 Getting Started Guide
        • Chapter 2 Referencing and Using Third-Party Libraries
        • Chapter 3: Application Compilation and Deployment
        • Chapter 4: Command-Line Factory Reset
        • Chapter 5: System Debugging -- HDC (Huawei Device Connector) Debugging
        • Chapter 6 APP Stability Testing
        • Chapter 7 Application Testing
    • Device Development

      • Chapter 1 Environment Setup
      • Chapter 2 Download Source Code
      • Chapter 3 Compiling Source Code
    • Peripheral And Iinterface

      • Raspberry Pi interface
      • GPIO Interface
      • I2C Interface
      • SPI communication
      • PWM (Pulse Width Modulation) control
      • Serial port communication
      • TF Card
      • Display Screen
      • Touch
      • Audio
      • RTC
      • Ethernet
      • M.2
      • MINI-PCIE
      • Camera
      • WIFI&BT
      • Raspberry Pi expansion board
    • Frequently Asked Questions

      • Resource Downloads
  • M-K1HSE

    • Introduction

      • M-K1HSE Introduction
    • Quick Start

      • Development environment construction
      • Source code acquisition
      • Compilation Notes
      • Burning Guide
    • Peripherals and interfaces

      • 01 Audio
      • 02 RS485
      • 03 Display
    • System customization development

      • System transplant
      • System customization
      • Driver Development
      • System Debugging
      • OTA Update

PWM (Pulse Width Modulation) control

1. PWM pins

Taking the SC-3568HA as an example, there are 3 GPIOs with PWM functions on the 40PIN pins of the board. Among them, PWM5 (PIN33) has already been occupied by the backlight of the MIPI1 screen.

TOOL
Boardpin12pin32pin33
SC-3568HApwm0pwm14pwm5

Note

By default, PWM0, PWM5, and PWM14 are all enabled.

2. Check the PWM device

Enter the following commands in the terminal to check whether PWM is enabled

    ls -l /sys/class/pwm/

As shown in the figure:

TOOL

pwmchip1 and pwmchip2 are used for the backlight of the screen and are enabled by default in the system. When multiple PWM device tree overlays are enabled, the smaller the value of the PWM controller, the smaller the pwmchip assigned by the system.

For example, if I enable PWM0, PWM5, and PWM14 simultaneously, the following corresponding relationships will appear.

    pwm0->pwmchip0
    pwm5->pwmchip2
    pwm14->pwmchip3

3. PWM control mode

Next, take the control of PWM14 as an example

    #Export PWM14 to the user space
    echo 0 > /sys/class/pwm/pwmchip3/export

    #Set the PWM period with the unit of ns
    echo 1000000 > /sys/class/pwm/pwmchip3/pwm0/period

    #Set the duty cycle
    echo 500000 > /sys/class/pwm/pwmchip3/pwm0/duty_cycle

    #Set the PWM polarity
    echo "normal" > /sys/class/pwm/pwmchip3/pwm0/polarity

    #Enable PWM
    echo 1 > /sys/class/pwm/pwmchip3/pwm0/enable

    #Cancel the export of PWM14 to the user space
    echo 0 > /sys/class/pwm/pwmchip3/unexport

Tips

When setting the values of period and duty_cycle, it should be noted that under any circumstances, the value of period must be greater than or equal to the value of duty_cycle.


Edit this page on GitHub
Last Updated:
Contributors: zsl, zwhuang
Prev
SPI communication
Next
Serial port communication