BPI-M1+之PWM

QQ图片20160526211018.jpg
首先测试blink

#include <wiringPi.h>
//
// by MikuQ(i@mikuq.com) 2016-5-26
//
int main(void)
{
  wiringPiSetup() ;
  pinMode (7, OUTPUT) ;
  for(;;)
  {
    digitalWrite(7, HIGH) ; delay (500) ;
    digitalWrite(7,  LOW) ; delay (500) ;
  }
}

然后编译执行,没有问题

gcc -Wall -o pwm pwm.c -lwiringPi
sudo ./pwm
#include <wiringPi.h>
//
// by MikuQ(i@mikuq.com) 2016-5-26
//
int main(void)
{
  int bright ;
  wiringPiSetup() ;
  pinMode (7, PWM_OUTPUT) ;
  for (;;)
  {
    for (bright = 0 ; bright < 1024 ; bright+=5)
    {
      pwmWrite (7, bright) ;
      delay (1) ;
    }

    for (bright = 1023 ; bright >= 0 ; bright-=5)
    {
      pwmWrite (7, bright) ;
      delay (1) ;
    }
  }
}

会显示启动了PWM

you choose the hardware PWM:1

让呼吸更顺畅

#include <wiringPi.h>
//
// by MikuQ(i@mikuq.com) 2016-5-26
//
int main(void)
{
  int i ; 
  int breathing_table[128] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255
  };
  wiringPiSetup() ;
  pinMode (7, PWM_OUTPUT) ;
  for (;;)
  {
    for (int i = 0 ; i< 256 ; i++)
    {
      if(i<128)
        pwmWrite (7, breathing_table[i]<<2);
      else
        pwmWrite (7, breathing_table[255-i]<<2);
      delay (5) ;
    }
  }
}

不知道是不是我不太会用,感觉全志的PWM有点儿扯,怎么还不到200Hz,怪不得呼吸怎么都调不匀
53.png

Arduino默认就490Hz还可以再提高
54.png

香蕉直接翻转IO,波形并不好看
55.png

标签: none

添加新评论