モーターを自作ドライバ経由でPWM駆動するためのサンプルプログラム

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
edamame_sky
Date:
Thu Jul 02 09:30:43 2020 +0000
Commit message:
sample_program

Changed in this revision

mbed.bld Show annotated file Show diff for this revision Revisions of this file
pwmsample.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 49d1f99282d0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 02 09:30:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r 49d1f99282d0 pwmsample.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwmsample.cpp	Thu Jul 02 09:30:43 2020 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#define T 50 //周期(us)(period_usを使った場合)
+//#define H_MIN 1000 
+//#define H_MAX 2500 
+#define HIGH 1
+#define LOW 0
+
+PwmOut     pin0(D2);
+DigitalOut pin1(D3);
+PwmOut     pin2(D9);
+DigitalOut pin3(D8);
+//AnalogIn analog_value(A1);
+
+DigitalOut myled(LED1);
+
+int main() {
+    //float anlgIn;
+    int pwmWidth = 45;//PWMのパルスにおけるオン時間(us)(pulsewidth_usを使った場合)
+    pin0.period_us(T);//周波数の設定 ex)period_usの場合、T=100(us)→周波数f=1/T=10(kHz))
+    pin0.pulsewidth_us(0);
+    pin2.period_us(T);//周波数の設定
+    pin2.pulsewidth_us(0);
+  
+    while(1) {
+        //for (int i=0;i<=20;i++){
+            //anlgIn = 0.3;
+            //pwmWidth = (H_MAX-H_MIN)*anlgIn + H_MIN;
+            //前転
+            pin0.pulsewidth_us(pwmWidth);// pwmWidth/T*100(%)のデューティ比でPWMパルスを指定ピンから出力
+            pin1 = HIGH;
+            pin2 = LOW;
+            pin3 = LOW;
+            
+            wait_ms(1500);
+            
+            
+            
+            //後転
+            pin0 = LOW;
+            pin1 = LOW;
+            pin2.pulsewidth_us(pwmWidth);
+            pin3 = HIGH;
+            //printf("スイッチング周波数(kHz): %d\n",1000/T);
+            //printf("デューティ比: %d\n",pwmWidth/T*100);
+            //myled = !myled;   //change the mode of LED1 ここにピンのオンオフやらを入れればいいはず(digitalWrite)
+            
+            wait_ms(1500);
+            
+            
+            
+            /*
+            pin0 = LOW;
+            pin1 = HIGH;
+            pin2 = LOW;
+            pin3 = HIGH;
+            
+            wait_ms(1500);
+            */
+            
+            
+        //}
+    }
+}
\ No newline at end of file