This program manipulates the speed of a DC motor using PWM for the KL46Z

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
philliptran011
Date:
Sat Nov 25 23:31:24 2017 +0000
Commit message:
Lab 6 for Microprocessor's Lab to control the speed of a DC Motor using a KL46Z Microcontroller

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7465d24798a5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 25 23:31:24 2017 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+PwmOut motorc(PTB19);
+DigitalOut dir1(PTC11);
+DigitalOut dir2(PTC10);
+
+Serial pc(USBTX, USBRX);
+float duty[8] = {1, 0.75, 0.5, 0.25, 0.25, 0.5, 0.75, 1};
+int index = 0;
+char entry;
+
+int main()
+{
+    pc.baud(115200);
+    pc.printf("Connection Established\n");
+    while (true) {
+        entry = 'A';
+        while (entry != '+' && entry != '-') {
+            pc.printf("Enter a key\n");
+            pc.scanf("%c", &entry);
+            pc.printf("\n%c\n", entry);
+            if(entry == '+' && index < 7)
+            {
+                index=index + 1;
+                pc.printf("Increase Speed, current speed %f\n", duty[index]);
+            }
+            if(entry == '-' && index > 0)
+            {
+                index=index - 1;
+                pc.printf("Decrease Speed, current speed %f\n", duty[index]);
+            }
+        }
+        if(index <=3)
+        {
+            dir1 = 0;
+            dir2 = 1;
+        }
+        if(index >3)
+        {
+            dir1 = 1;
+            dir2 = 0;
+        }
+        motorc.write(duty[index]);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 7465d24798a5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 25 23:31:24 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/b484a57bc302
\ No newline at end of file