Scheda Motori
Dependencies: X_NUCLEO_IHM12A1 mbed
Fork of HelloWorld_IHM12A1 by
main.cpp@5:21a4085d2057, 2017-02-15 (annotated)
- Committer:
- DonatoSt
- Date:
- Wed Feb 15 11:09:44 2017 +0000
- Revision:
- 5:21a4085d2057
- Parent:
- 2:1e4061cedf1d
Scheda motori
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Manu_L | 0:773e2a2be16f | 1 | #include "mbed.h" |
Manu_L | 0:773e2a2be16f | 2 | #include "stspin240_250_class.h" |
Manu_L | 0:773e2a2be16f | 3 | |
Manu_L | 0:773e2a2be16f | 4 | /* Initialization parameters of the motor connected to the expansion board. */ |
Manu_L | 0:773e2a2be16f | 5 | Stspin240_250_Init_t initDeviceParameters = |
Manu_L | 0:773e2a2be16f | 6 | { |
Manu_L | 0:773e2a2be16f | 7 | 20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 8 | 20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 9 | 20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 10 | 50, /* Duty cycle of PWM used for Ref pin (from 0 to 100) */ |
Manu_L | 0:773e2a2be16f | 11 | TRUE /* Dual Bridge configuration (FALSE for mono, TRUE for dual brush dc) */ |
Manu_L | 0:773e2a2be16f | 12 | }; |
Manu_L | 0:773e2a2be16f | 13 | |
Manu_L | 0:773e2a2be16f | 14 | /* Motor Control Component. */ |
Manu_L | 0:773e2a2be16f | 15 | STSPIN240_250 *motor; |
Manu_L | 0:773e2a2be16f | 16 | |
Manu_L | 0:773e2a2be16f | 17 | int main() |
Manu_L | 0:773e2a2be16f | 18 | { |
Manu_L | 0:773e2a2be16f | 19 | uint8_t demoStep = 0; |
DonatoSt | 5:21a4085d2057 | 20 | |
Manu_L | 0:773e2a2be16f | 21 | /* Initializing Motor Control Component. */ |
Manu_L | 0:773e2a2be16f | 22 | #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8) |
Manu_L | 0:773e2a2be16f | 23 | motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A2); |
Manu_L | 0:773e2a2be16f | 24 | #elif (defined TARGET_NUCLEO_L152RE) |
Manu_L | 0:773e2a2be16f | 25 | motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A3); |
Manu_L | 0:773e2a2be16f | 26 | #else |
Manu_L | 0:773e2a2be16f | 27 | motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0); |
Manu_L | 0:773e2a2be16f | 28 | #endif |
Manu_L | 0:773e2a2be16f | 29 | if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE); |
Manu_L | 0:773e2a2be16f | 30 | |
Manu_L | 0:773e2a2be16f | 31 | /* Set dual bridge enabled as two motors are used*/ |
Manu_L | 2:1e4061cedf1d | 32 | motor->SetDualFullBridgeConfig(1); |
Manu_L | 0:773e2a2be16f | 33 | |
Manu_L | 0:773e2a2be16f | 34 | |
Manu_L | 0:773e2a2be16f | 35 | /* Set PWM Frequency of Ref to 15000 Hz */ |
Manu_L | 0:773e2a2be16f | 36 | motor->SetRefPwmFreq(0, 15000); |
Manu_L | 0:773e2a2be16f | 37 | |
Manu_L | 0:773e2a2be16f | 38 | /* Set PWM duty cycle of Ref to 60% */ |
Manu_L | 0:773e2a2be16f | 39 | motor->SetRefPwmDc(0, 60); |
Manu_L | 0:773e2a2be16f | 40 | |
Manu_L | 0:773e2a2be16f | 41 | /* Set PWM Frequency of bridge A inputs to 10000 Hz */ |
Manu_L | 0:773e2a2be16f | 42 | motor->SetBridgeInputPwmFreq(0,10000); |
Manu_L | 0:773e2a2be16f | 43 | |
Manu_L | 0:773e2a2be16f | 44 | /* Set PWM Frequency of bridge B inputs to 10000 Hz */ |
Manu_L | 0:773e2a2be16f | 45 | motor->SetBridgeInputPwmFreq(1,10000); |
Manu_L | 0:773e2a2be16f | 46 | |
Manu_L | 0:773e2a2be16f | 47 | while (1) |
Manu_L | 0:773e2a2be16f | 48 | { |
Manu_L | 0:773e2a2be16f | 49 | switch (demoStep) |
Manu_L | 0:773e2a2be16f | 50 | { |
Manu_L | 0:773e2a2be16f | 51 | case 0: |
Manu_L | 0:773e2a2be16f | 52 | /* Set speed of motor 0 to 100 % */ |
DonatoSt | 5:21a4085d2057 | 53 | motor->SetSpeed(0,50); |
DonatoSt | 5:21a4085d2057 | 54 | motor->SetSpeed(1,50); |
Manu_L | 0:773e2a2be16f | 55 | /* start motor 0 to run forward*/ |
Manu_L | 0:773e2a2be16f | 56 | /* if chip is in standby mode */ |
Manu_L | 0:773e2a2be16f | 57 | /* it is automatically awakened */ |
Manu_L | 0:773e2a2be16f | 58 | motor->Run(0, BDCMotor::FWD); |
Manu_L | 0:773e2a2be16f | 59 | motor->Run(1, BDCMotor::FWD); |
Manu_L | 0:773e2a2be16f | 60 | break; |
DonatoSt | 5:21a4085d2057 | 61 | case 1: |
DonatoSt | 5:21a4085d2057 | 62 | /* Set speed of motor 0 to 100 % */ |
DonatoSt | 5:21a4085d2057 | 63 | motor->SetSpeed(0,50); |
DonatoSt | 5:21a4085d2057 | 64 | motor->SetSpeed(1,50); |
DonatoSt | 5:21a4085d2057 | 65 | /* start motor 0 to run forward*/ |
DonatoSt | 5:21a4085d2057 | 66 | /* if chip is in standby mode */ |
DonatoSt | 5:21a4085d2057 | 67 | /* it is automatically awakened */ |
DonatoSt | 5:21a4085d2057 | 68 | motor->Run(0, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 69 | motor->Run(1, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 70 | break; |
DonatoSt | 5:21a4085d2057 | 71 | case 2: |
DonatoSt | 5:21a4085d2057 | 72 | /* Set speed of motor 0 to 100 % */ |
DonatoSt | 5:21a4085d2057 | 73 | motor->SetSpeed(0,32); |
DonatoSt | 5:21a4085d2057 | 74 | motor->SetSpeed(1,25); |
DonatoSt | 5:21a4085d2057 | 75 | /* start motor 0 to run forward*/ |
DonatoSt | 5:21a4085d2057 | 76 | /* if chip is in standby mode */ |
DonatoSt | 5:21a4085d2057 | 77 | /* it is automatically awakened */ |
DonatoSt | 5:21a4085d2057 | 78 | motor->Run(0, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 79 | motor->Run(1, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 80 | break; |
DonatoSt | 5:21a4085d2057 | 81 | case 3: |
DonatoSt | 5:21a4085d2057 | 82 | /* Set speed of motor 0 to 100 % */ |
DonatoSt | 5:21a4085d2057 | 83 | motor->SetSpeed(0,25); |
DonatoSt | 5:21a4085d2057 | 84 | motor->SetSpeed(1,40); |
DonatoSt | 5:21a4085d2057 | 85 | /* start motor 0 to run forward*/ |
DonatoSt | 5:21a4085d2057 | 86 | /* if chip is in standby mode */ |
DonatoSt | 5:21a4085d2057 | 87 | /* it is automatically awakened */ |
DonatoSt | 5:21a4085d2057 | 88 | motor->Run(0, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 89 | motor->Run(1, BDCMotor::BWD); |
DonatoSt | 5:21a4085d2057 | 90 | break; |
DonatoSt | 5:21a4085d2057 | 91 | |
DonatoSt | 5:21a4085d2057 | 92 | |
DonatoSt | 5:21a4085d2057 | 93 | |
DonatoSt | 5:21a4085d2057 | 94 | |
Manu_L | 0:773e2a2be16f | 95 | } |
Manu_L | 0:773e2a2be16f | 96 | |
Manu_L | 0:773e2a2be16f | 97 | /* Wait for 5 seconds */ |
Manu_L | 0:773e2a2be16f | 98 | wait_ms(5000); |
Manu_L | 0:773e2a2be16f | 99 | |
Manu_L | 0:773e2a2be16f | 100 | /* Increment demostep*/ |
Manu_L | 0:773e2a2be16f | 101 | demoStep++; |
Manu_L | 0:773e2a2be16f | 102 | if (demoStep > 12) |
Manu_L | 0:773e2a2be16f | 103 | { |
Manu_L | 0:773e2a2be16f | 104 | demoStep = 0; |
Manu_L | 0:773e2a2be16f | 105 | } |
Manu_L | 0:773e2a2be16f | 106 | } |
Manu_L | 0:773e2a2be16f | 107 | } |
DonatoSt | 5:21a4085d2057 | 108 |