Browse Source

Signed-off-by: Caner <5658514@qq.com>

Caner 4 years ago
parent
commit
1e458fee37
2 changed files with 44 additions and 0 deletions
  1. 30 0
      index.js
  2. 14 0
      package.json

+ 30 - 0
index.js

@@ -0,0 +1,30 @@
+const PWM = require("rpio-pwm");
+let pwmCh, stepNum = 500, refresh = 50, pinBoardCode = 18
+
+console.log("初始化 PWM 通道");
+PWM.set_log_level(PWM.logLevel.debug);
+
+const cycleTimeUs = (1000 / refresh) * 1000,
+    stepTimeUs = cycleTimeUs / stepNum,
+    steeringPWMCfg = {
+        cycle_time_us: cycleTimeUs,
+        step_time_us: stepTimeUs,
+        delay_hw: 1,
+    };
+
+pwmCh = PWM.create_dma_channel(
+    PWM.host_is_model_pi4() ? 5 : 12,
+    steeringPWMCfg
+);
+
+
+const pin = pwmCh.create_pwm(pinBoardCode);
+
+pin.set_width((256 / 100) * stepNum);
+
+setTimeout(function () {
+    // it's good idea to cleanup before exit.
+    console.log('clear');
+    pwmCh.shutdown();
+}, 2000);
+

+ 14 - 0
package.json

@@ -0,0 +1,14 @@
+{
+  "name": "test-pwm",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "rpio-pwm": "https://github.com/itiwll/rpio-pwm.git"
+  }
+}