form of HeloWorld_IHM04A1

Dependencies:   FastPWM mbed ST_INTERFACES

Fork of HelloWorld_IHM04A1 by ST

Revision:
9:b7fc55bf70b2
Parent:
8:05340e740644
--- a/main.cpp	Wed May 24 15:36:18 2017 +0000
+++ b/main.cpp	Fri Jul 21 11:19:39 2017 +0000
@@ -68,8 +68,8 @@
 {
     L6206_CONF_PARAM_PARALLE_BRIDGES,
     {L6206_CONF_PARAM_FREQ_PWM1A, L6206_CONF_PARAM_FREQ_PWM2A, L6206_CONF_PARAM_FREQ_PWM1B, L6206_CONF_PARAM_FREQ_PWM2B},
-    {100,100,100,100},
-    {FORWARD,FORWARD,BACKWARD,FORWARD},
+    {0,0,0,0},
+    {FORWARD,FORWARD,FORWARD,FORWARD},
     {INACTIVE,INACTIVE,INACTIVE,INACTIVE},
     {FALSE,FALSE}
 };
@@ -94,6 +94,7 @@
   gLastError = error;
   
   /* Enter your own code here */
+  printf("Error: %u\r\n\n",error);
 }
 
 /**
@@ -164,14 +165,21 @@
 
     /* Initializing Motor Control Component. */
     motor = new L6206( D2, A4, D5, D4, A0, A1);
-
+    DigitalIn Pin_d4(D4);
+    DigitalIn Pin_a0(A0);
+    DigitalIn Pin_a1(A1);
+    
+    Pin_d4.mode(PullNone);
+    Pin_a0.mode(PullNone);
+    Pin_a1.mode(PullNone);
+    
     /* When init method is called with NULL pointer, the L6206 parameters are set   */
     /* with the predefined values from file l6206_target_config.h, otherwise the    */
-    /* parameters are set using the init structure values.          */
+    /* parameters are set using the init structure values.  */        
     if (motor->init(&init) != COMPONENT_OK) {
         exit(EXIT_FAILURE);
     }
-
+    
     /* Attach the function my_flag_irq_handler (defined below) to the flag interrupt */
     motor->attach_flag_interrupt(my_flag_irq_handler);
 
@@ -183,63 +191,82 @@
 
     /* Select the configuration with no bridge paralleling, two unidirectionnal motors on bridge A 
        and two unidirectionnal motors on bridge B */
-    motor->set_dual_full_bridge_config(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
+    //motor->set_dual_full_bridge_config(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
+    motor->set_dual_full_bridge_config(PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR);
  
     /* Set PWM Frequency of bridge A inputs to 1000 Hz */ 
-    motor->set_bridge_input_pwm_freq(0,1000);
+   // motor->set_bridge_input_pwm_freq(0,10000);
   
     /* Set PWM Frequency of bridge B inputs to 2000 Hz */ 
-    motor->set_bridge_input_pwm_freq(1,2000);
+    //motor->set_bridge_input_pwm_freq(1,2000);
+    motor->set_bridge_input_pwm_freq(0,1000);
+    //motor->set_bridge_input_pwm_freq(1,50000);
+    Pin_d4.mode(PullNone);
+    Pin_a0.mode(PullNone);
+    Pin_a1.mode(PullNone);
   
     // Attach my_button_pressed function to Irq
     my_button_irq.fall(&my_button_pressed);
 
     /* Infinite loop */
     while (true) {
+        
+        if (gStep == 0) {
+            printf("stopping motor 0\r\n");
+            /* Set speed of motor 0 to 5% */
+            motor->hard_hiz(0);  
+        }
 
-        if (gStep > 0) {
+        
+        
+        if (gStep == 1) {
+            printf("Running motor 0 at 1%% of the maximum speed\r\n");
+            /* Set speed of motor 0 to 5% */
+            motor->set_speed(0,100);
+            /* start motor 0 */
+            motor->run(0, BDCMotor::FWD);
+
+        }
+
+        if (gStep == 2) {
             printf("Running motor 0 at 5%% of the maximum speed\r\n");
-            /* Set speed of motor 0 to 5% */
-            motor->set_speed(0,5);
-            /* start motor 0 */
+            /* Set speed of motor 1 to 10 % */
+            motor->set_speed(0,500);
+            /* start motor 1 */
+            //motor->run(1, BDCMotor::FWD);
             motor->run(0, BDCMotor::FWD);
         }
 
-        if (gStep > 1) {
-            printf("Running motor 1 at 10%% of the maximum speed\r\n");
-            /* Set speed of motor 1 to 10 % */
-            motor->set_speed(1,10);
-            /* start motor 1 */
-            motor->run(1, BDCMotor::FWD);
-        }
-
-        if (gStep > 2) {
-            printf("Running motor 2 at 15%% of the maximum speed\r\n");
+        if (gStep == 3) {
+            printf("Running motor 0 at 10%% of the maximum speed\r\n");
             /* Set speed of motor 2 to 15 % */
-            motor->set_speed(2,15);
+            motor->set_speed(0,1000);
             /* start motor 2 */
-            motor->run(2, BDCMotor::FWD);
+            //motor->run(2, BDCMotor::FWD);
+            motor->run(0, BDCMotor::FWD);
         }
 
-        if (gStep > 3)  {
-            printf("Running motor 3 at 20%% of the maximum speed\r\n");
+        if (gStep == 4)  {
+            printf("Running motor 0 at 50%% of the maximum speed\r\n");
             /* Set speed of motor 3 to 20 % */
-            motor->set_speed(3,20);
+            motor->set_speed(0,5000);
             /* start motor 3 */
-            motor->run(3, BDCMotor::FWD);      
+            //motor->run(3, BDCMotor::FWD);      
+            motor->run(0, BDCMotor::FWD);
         }
 
-        if (gStep > 0) {
+        if (gStep >= 0) {
             wait_ms(1000);
         
-            motor->hard_hiz(0);   
-            motor->hard_hiz(1);   
-            motor->hard_hiz(2);   
-            motor->hard_hiz(3);
+            //motor->hard_hiz(0);   
+            //motor->hard_hiz(1);   
+            //motor->hard_hiz(2);   
+            //motor->hard_hiz(3);
             
-            wait_ms(1000);
+            //wait_ms(1000);
         }
     }
 }
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+