Scheda Motori

Dependencies:   X_NUCLEO_IHM12A1 mbed

Fork of HelloWorld_IHM12A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stspin240_250_class.h"
00003 
00004 /* Initialization parameters of the motor connected to the expansion board. */
00005  Stspin240_250_Init_t initDeviceParameters =
00006  {
00007   20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz             */
00008   20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz             */
00009   20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz              */
00010   50,    /* Duty cycle of PWM used for Ref pin (from 0 to 100)                  */
00011   TRUE   /* Dual Bridge configuration  (FALSE for mono, TRUE for dual brush dc) */
00012  };
00013 
00014 /* Motor Control Component. */
00015 STSPIN240_250 *motor;
00016 
00017 int main()
00018 {
00019   uint8_t demoStep = 0;
00020 
00021   /* Initializing Motor Control Component. */
00022   #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8)
00023   motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A2);
00024   #elif (defined TARGET_NUCLEO_L152RE)
00025   motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A3);
00026   #else
00027   motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0);
00028   #endif
00029   if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
00030 
00031   /* Set dual bridge enabled as two motors are used*/
00032   motor->SetDualFullBridgeConfig(1);
00033 
00034 
00035   /* Set PWM Frequency of Ref to 15000 Hz */ 
00036   motor->SetRefPwmFreq(0, 15000); 
00037 
00038   /* Set PWM duty cycle of Ref to 60% */ 
00039   motor->SetRefPwmDc(0, 60); 
00040   
00041   /* Set PWM Frequency of bridge A inputs to 10000 Hz */ 
00042   motor->SetBridgeInputPwmFreq(0,10000); 
00043   
00044   /* Set PWM Frequency of bridge B inputs to 10000 Hz */ 
00045   motor->SetBridgeInputPwmFreq(1,10000); 
00046   
00047   while (1)
00048   {
00049     switch (demoStep)
00050     {  
00051         case 0:
00052           /* Set speed of motor 0 to 100 % */
00053           motor->SetSpeed(0,50);
00054           motor->SetSpeed(1,50); 
00055           /* start motor 0 to run forward*/
00056           /* if chip is in standby mode */
00057           /* it is automatically awakened */
00058           motor->Run(0, BDCMotor::FWD);
00059           motor->Run(1, BDCMotor::FWD);
00060           break;
00061                   case 1:
00062                   /* Set speed of motor 0 to 100 % */
00063                 motor->SetSpeed(0,50);
00064                 motor->SetSpeed(1,50); 
00065                 /* start motor 0 to run forward*/
00066                 /* if chip is in standby mode */
00067                 /* it is automatically awakened */
00068                 motor->Run(0, BDCMotor::BWD);
00069                 motor->Run(1, BDCMotor::BWD);
00070                 break;
00071                    case 2:
00072                   /* Set speed of motor 0 to 100 % */
00073                 motor->SetSpeed(0,32);
00074                 motor->SetSpeed(1,25); 
00075                 /* start motor 0 to run forward*/
00076                 /* if chip is in standby mode */
00077                 /* it is automatically awakened */
00078                 motor->Run(0, BDCMotor::BWD);
00079                 motor->Run(1, BDCMotor::BWD);
00080                 break;
00081                     case 3:
00082                   /* Set speed of motor 0 to 100 % */
00083                 motor->SetSpeed(0,25);
00084                 motor->SetSpeed(1,40); 
00085                 /* start motor 0 to run forward*/
00086                 /* if chip is in standby mode */
00087                 /* it is automatically awakened */
00088                 motor->Run(0, BDCMotor::BWD);
00089                 motor->Run(1, BDCMotor::BWD);
00090                 break;
00091           
00092           
00093             
00094                  
00095     }
00096   
00097     /* Wait for 5 seconds */  
00098     wait_ms(5000);
00099     
00100     /* Increment demostep*/  
00101     demoStep++;
00102     if (demoStep > 12)
00103     {
00104       demoStep = 0;
00105     }
00106   } 
00107 }
00108