1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

電子回路入門 PWM出力

Last updated at Posted at 2018-02-21

はじめに

前回と同様にPSoCを使用して書籍を参考にしながら進めていきます。

PWMとは?

疑似的アナログ出力のことです。なぜPWMが必要なのかと言うと、アナログ出力することができないマイコン等(ラズベリーパイとか)があり、そんなマイコン等でもアナログ出力のような変化する出力をさせてあげたい場合があるからです。
疑似的でないアナログ出力をしたい場合はD/Aコンバータを使用するらしいです。
また、PWMにはソフトウェアPWMとハードウェアPWMが存在する。

仕組みとしては、高速でON(5V)とOFF(0V)を繰り返し、ONの時間が長ければ長いほどLEDが明るく見える(人間は)ようになります。

計算式 ONの時間 ÷ ( ONの時間 + OFFの時間 ) × 最大出力電圧(V) = 出力電圧(V)

秒単位はあり得ないですが…
1秒 ÷ ( 1秒 + 4秒 ) × 5V = 1V 図上
4秒 ÷ ( 4秒 + 1秒 ) × 5V = 4V 図下
PWM.png

回路図

前回と同様

プログラム

ソフトウェアPWM
暗い

# include "project.h"

int main(void)
{
    CyGlobalIntEnable;

    for(;;)
    {
     LED_Write(1);
     CyDelay(1);

     LED_Write(0);
     CyDelay(10);
    }
}

明るい

# include "project.h"

int main(void)
{
    CyGlobalIntEnable;

    for(;;)
    {
     LED_Write(1);
     CyDelay(10);

     LED_Write(0);
     CyDelay(1);
    }
}

ハードウェアPWM
PSoCでは簡単にPWMを使用することができるようなので、こちらを参考に、明るさを変化させていく。

# include "project.h"

int main(void)
{
    CyGlobalIntEnable;
    PWM_Start();
    int i;
    for(i=0;i<255;i++)
    {
      PWM_WriteCompare1(i);
      CyDelay(10);
    }
}
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?