0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電子工作メモ - PWMを使ったLED

Last updated at Posted at 2024-03-21
  • PWM(Pulse Width Modulation): パルス幅変調
    デジタル信号を使用してアナログ信号を生成する。
    指定した周波数の矩形波をデジタルピンから出力する。

    • パルス幅: Highレベルの時間

    • デューティ比: 周期のうちパルス幅の割合(1周期のうちHighの時間がどのくらいか?)

    • デューティ比の割合が、アナログ信号としての電圧の割合になる

      デューティ比 アナログ電圧 全電圧
      25% 0.8V 3.3V
      50% 1.6V 3.3V
      75% 2.4V 3.3V
      100% 3.3V 3.3V
    • Pico は16個のPWMチャンネルがある。それぞれ個別に周波数とデューティ比を制御できる。

      • クロック周波数は、7Hz ~ 125MHz
    • PWM Class

      • duty_u16()
        デューティ比を16bit(0~65535) で指定する
  • PWM の使い方

    • 必要なもの
      • GPIOピン番号 : 初期化時に指定
      • 周波数 : 初期化時か freq() で指定
      • デューティー比 : duty_u16() で指定
from machine import Pin, PWM
import time

#set PWM
pwm = PWM(Pin(15)) 
pwm.freq(10000)

try:
    while True:
        for i in range(0, 65535):
            pwm.duty_u16(i)
            time.sleep_us(100)
        for i in range(65535, 0, -1):
            pwm.duty_u16(i)
            time.sleep_us(100)
except:
    pwm.deinit()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?