UVW 3 phases Brushless DC motor control
Dependencies: QEI mbed-rtos mbed
Fork of BLDCmotor by
Revision 4:6ccbf4d3cb6d, committed 2012-11-16
- Comitter:
- kosaka
- Date:
- Fri Nov 16 02:48:01 2012 +0000
- Parent:
- 3:b6b9b8c7dce6
- Child:
- 5:2e53814aae4c
- Commit message:
- minor change
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Nov 16 01:42:30 2012 +0000 +++ b/main.cpp Fri Nov 16 02:48:01 2012 +0000 @@ -5,7 +5,7 @@ #include "QEI.h" #define PI 3.14159265358979 // def. of PI /*********** User setting for control parameters (begin) ***************/ -#define SIMULATION // Comment this line if not simulation +//#define SIMULATION // Comment this line if not simulation #define USE_PWM // H bridge PWM mode: Vref=Vcc, FIN,2 = PWM or 0. Comment if use Vref=analog mode #define CONTROL_MODE 0 // 0:PID control, 1:Frequency response, 2:Step response #define GOOD_DATA // Comment this line if the length of data TMAX/TS2 > 1000 @@ -58,10 +58,11 @@ PwmOut FIN(FIN_PORT); // PWM for FIN, RIN=0 when forward rotation. H bridge driver PWM mode PwmOut RIN(RIN_PORT); // PWM for RIN, FIN=0 when reverse rotation. H bridge driver PWM mode #else // H bridge Vref=analog mode - AnalogOut analog_out(VREF_PORT);// Vref for DC motor H bridge driver. DA converter for control input [0.0-1.0]% in the output range of 0.0 to 3.3[V] DigitalOut FIN(FIN_PORT);// FIN for DC motor H bridge driver. FIN=1, RIN=0 then forward rotation DigitalOut RIN(RIN_PORT);// RIN for DC motor H bridge driver. FIN=0, RIN=1 then reverse rotation #endif +AnalogOut analog_out(VREF_PORT);// Vref for DC motor H bridge driver. DA converter for control input [0.0-1.0]% in the output range of 0.0 to 3.3[V] + unsigned long _count; // sampling number float _time; // time[s] float _r; // reference signal @@ -114,6 +115,7 @@ } #ifdef USE_PWM // H bridge PWM mode: Vref=Vcc, FIN,2 = PWM or 0 FIN = duty*(float)f_in; RIN = duty*(float)r_in; // setting pwm FIN & RIN + analog_out = 1; // setting Vref=UMAX, but Vref=Vcc is better. #else // Analog mode: Vref=analog, FIN, RIN = 1 or 0) FIN = f_in; RIN = r_in; // setting FIN & RIN analog_out = duty; // setting Vref : PID write DA, range is 0-1. Output voltage 0-3.3v