npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ezpwmforraspberry

v1.0.1

Published

a pwm library

Downloads

4

Readme

ezPWMForRaspberry

本模块使用了node-rpio, 所以,请配置以下环境。

由于使用pwm,需要sudo权限。 或者把pi用户放入gpio用户组。

Disable GPIO interrupts

If running a newer Raspbian release, you will need to add the following line to /boot/config.txt and reboot:

dtoverlay=gpio-no-irq

Without this you may see crashes with newer kernels when trying to poll for pin changes.

Enable /dev/gpiomem access

By default the module will use /dev/gpiomem when using simple GPIO access. To access this device, your user will need to be a member of the gpio group, and you may need to configure udev with the following rule (as root):

$ cat >/etc/udev/rules.d/20-gpiomem.rules <<EOF
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
EOF

For access to i²c, PWM, and SPI, or if you are running an older kernel which does not have the bcm2835-gpiomem module, you will need to run your programs as root for access to /dev/mem.

安装

npm i ezpwmforraspberry --save

初始化

const ezPWM = require('ezpwmforraspberry');

const pwm = new ezPWM();

设置占空比

1.百分比方式(精度100, 从0~100)

// 打开PWM
pwm.openPWMByPercent(ezPWM.PWMPin.PIN12);

// 更新占空比
pwm.updatePWMByPercent(ezPWM.PWMPin.PIN12,0);

// 从0到100
for (let index = 0; index < 100; index++) {
    rpio.sleep(0.1);
    console.log('updatePWMByPercent', ezPWM.PWMPin.PIN12 ,index);
    pwm.updatePWMByPercent(ezPWM.PWMPin.PIN12,index);
}

2.高精度方式

// 打开PWM
pwm.openPWM(ezPWM.PWMPin.PIN12, 0, total=1024);

// 更新占空比
pwm.updatePWM(ezPWM.PWMPin.PIN12, 0)

// 从0到100
for (let index = 0; index < 1024; index++) {
    rpio.sleep(0.1);
    console.log('updatePWMByPercent', ezPWM.PWMPin.PIN12 ,index);
    pwm.updatePWMByPercent(ezPWM.PWMPin.PIN12,index);
}

PWM频率说明

树莓派4B之前的版本,时钟频率是19.2MHz, 4B的时钟频率是54MHz。

给PWM口分配频率

通过divosor来设置PWM口的时钟频率的,

const pwm = new ezPWM('physical', 2048); 

如上,设置了2048, 则divosor=54e6/2048,约2.6367MHz频率。

设置了时钟频率后,再设置精度, 也可称为分辨率。 假设我们设置精度为1024

那么,2.6367Mhz/1024 ~= 25Hz, 也就是每秒25个1024分辨率的PWM信号。

设置占空比

pwm.openPWM(ezPWM.PWMPin.PIN12, low=0, total=1024); 

pwm.updatePWM(ezPWM.PWMPin.PIN12, low=800);

参考博文:

https://raspberrypi.stackexchange.com/questions/4906/control-hardware-pwm-frequency/9725#9725

https://github.com/jperkin/node-rpio/issues/2