Michael Snelling / Mbed OS Triangle_By_Time
Revision:
4:4aa46b70064a
Parent:
2:3ecc1de21269
Child:
5:fdc550ee3b6e
--- a/main.cpp	Tue Nov 05 12:57:15 2019 +0000
+++ b/main.cpp	Tue Nov 05 14:29:05 2019 +0000
@@ -1,5 +1,5 @@
 /*  
- Version 4 – Mike's edit 
+ Version 5 – Mike's edit 
 */  
 
 #include "mbed.h"  
@@ -30,7 +30,7 @@
 DigitalOut probe(D10);  
 //Duty cycles  
 float dutyA = 1.0f; //100%  
-float dutyB = 0.99f; //100%  
+float dutyB = 1.0f; //100%  
 int main()  
 {  
         //Configure the terminal to high speed  
@@ -53,7 +53,7 @@
     for(float ramp = 0.0f; ramp <= 1.0f ; ramp += 0.1)  
         {  
             PWMA.write(ramp);          //Set duty cycle y  
-            PWMB.write(ramp-0.011);          //Set duty cycle y  
+            PWMB.write(ramp);          //Set duty cycle y  
             wait(1);  
         }  
     PWMA.write(dutyA);          //Set duty cycle hyp  
@@ -84,66 +84,66 @@
     timer.reset();  
     timer.start();    
 
-        //*********************************************************************  
+    //*********************************************************************  
 
-        //FIRST TIME - SYNCHRONISE (YOU SHOULD NOT NEED THIS ONCE IT's RUNNING)  
+    //FIRST TIME - SYNCHRONISE (YOU SHOULD NOT NEED THIS ONCE IT's RUNNING)  
 
-        //*********************************************************************  
+    //*********************************************************************  
 
-        //Wait for rising edge of A1 and log time  
-        while (HEA1 == NOPULSE);  
-        //Wait for rising edge of A2 and log time (30 degrees?)  
-        while (HEA2 == NOPULSE);  
-        //Wait for falling edge of A1  
-        while (HEA1 == PULSE);  
-        //Wait for falling edge of A2  
-        while (HEA2 == PULSE);  
-        //*********************** 
-        //TIME THE FULL SEQUENCE  
-        //**********************  
-        //Wait for rising edge of A1 and log time  
-        while (HEA1 == NOPULSE);  
-        tA1[0] = timer.read_us();  
-        //Wait for rising edge of A2 and log time (30 degrees?)  
-        while (HEA2 == NOPULSE);  
-        tA2[0] = timer.read_us();  
-        //Wait for falling edge of A1  
-        while (HEA1 == PULSE);  
-        tA1[1] = timer.read_us();  
-        //Wait for falling edge of A2  
-        while (HEA2 == PULSE);  
-        tA2[1] = timer.read_us();  
-        terminal.printf("tA1(0) = %d\n", tA1[0]);  
-        terminal.printf("tA1(1) = %d\n", tA1[1]);  
-        terminal.printf("tA2(0) = %d\n", tA2[0]);  
-        terminal.printf("tA2(1) = %d\n", tA2[1]);  
-        //Calculate the frequency of rotation  
-        float TA1 = 2.0f * (tA1[1]-tA1[0]);  
-        float TA2 = 2.0f * (tA2[1]-tA2[0]);  
-        float TA = (TA1 + TA2) * 0.5f;  
-        float fA = 1.0f/ (TA *(float)3.0E-6);  
-        terminal.printf("Average A2 Shaft: %6.2fHz \t Wheel: %6.2f\n", fA, fA/20.2f);  
-        //Reset timers  
-        timer.stop();  
-        //Wait for button press  
-        while (SW1 == 1);  
-        wait(0.2);  
-        while (SW1 == 0);  
-        wait(0.1);  
-        //******************************************  
+    //Wait for rising edge of A1 and log time  
+    while (HEA1 == NOPULSE);  
+    //Wait for rising edge of A2 and log time (30 degrees?)  
+    while (HEA2 == NOPULSE);  
+    //Wait for falling edge of A1  
+    while (HEA1 == PULSE);  
+    //Wait for falling edge of A2  
+    while (HEA2 == PULSE);  
+    //*********************** 
+    //TIME THE FULL SEQUENCE  
+    //**********************  
+    //Wait for rising edge of A1 and log time  
+    while (HEA1 == NOPULSE);  
+    tA1[0] = timer.read_us();  
+    //Wait for rising edge of A2 and log time (30 degrees?)  
+    while (HEA2 == NOPULSE);  
+    tA2[0] = timer.read_us();  
+    //Wait for falling edge of A1  
+    while (HEA1 == PULSE);  
+    tA1[1] = timer.read_us();  
+    //Wait for falling edge of A2  
+    while (HEA2 == PULSE);  
+    tA2[1] = timer.read_us();  
+    terminal.printf("tA1(0) = %d\n", tA1[0]);  
+    terminal.printf("tA1(1) = %d\n", tA1[1]);  
+    terminal.printf("tA2(0) = %d\n", tA2[0]);  
+    terminal.printf("tA2(1) = %d\n", tA2[1]);  
+    //Calculate the frequency of rotation  
+    float TA1 = 2.0f * (tA1[1]-tA1[0]);  
+    float TA2 = 2.0f * (tA2[1]-tA2[0]);  
+    float TA = (TA1 + TA2) * 0.5f;  
+    float fA = 1.0f/ (TA *(float)3.0E-6);  
+    terminal.printf("Average A2 Shaft: %6.2fHz \t Wheel: %6.2f\n", fA, fA/20.2f);  
+    //Reset timers  
+    timer.stop();  
+    //Wait for button press  
+    while (SW1 == 1);  
+    wait(0.2);  
+    while (SW1 == 0);  
+    wait(0.1);  
+    //******************************************  
 
-        //Adapt duty to meet 1 revolution per second  
+    //Adapt duty to meet 1 revolution per second  
 
-        //******************************************  
-        float wA = fA/20.2f;            //Wheel speed  
-        float deltaA = 1.0f-wA;         //Error  
-        dutyA = dutyA + deltaA*0.1f;    //Increase duty in proportion to the error  
-        //Clamp the max and min values of duty and 0.0 and 1.0 respectively  
-        dutyA = (dutyA>1.0f) ? 1.0f : dutyA;  
-        dutyA = (dutyA<0.05f) ? 0.05f : dutyA;  
-        //Update duty cycle to correct in the first direction  
-        PWMA.write(dutyA);                    
-        //Echo to the terminal  
+    //******************************************  
+    float wA = fA/20.2f;            //Wheel speed  
+    float deltaA = 1.0f-wA;         //Error  
+    dutyA = dutyA + deltaA*0.1f;    //Increase duty in proportion to the error  
+    //Clamp the max and min values of duty and 0.0 and 1.0 respectively  
+    dutyA = (dutyA>1.0f) ? 1.0f : dutyA;  
+    dutyA = (dutyA<0.05f) ? 0.05f : dutyA;  
+    //Update duty cycle to correct in the first direction  
+    PWMA.write(dutyA);                    
+    //Echo to the terminal  
      terminal.printf("Adapting duty cycle to %6.2f\n", dutyA);  
     }  
 }