Brushless motor control program with L293D.
Dependencies: brushlessController_L293D mbed
main.cpp@0:06434e97c4f2, 2015-07-13 (annotated)
- Committer:
- BaserK
- Date:
- Mon Jul 13 14:10:28 2015 +0000
- Revision:
- 0:06434e97c4f2
- Child:
- 1:46f06c96c5f0
A brushless motor is controlled by one L293D
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BaserK | 0:06434e97c4f2 | 1 | #include "mbed.h" |
BaserK | 0:06434e97c4f2 | 2 | |
BaserK | 0:06434e97c4f2 | 3 | /* Digital Outputs */ |
BaserK | 0:06434e97c4f2 | 4 | DigitalOut out1(p21); |
BaserK | 0:06434e97c4f2 | 5 | DigitalOut out2(p22); |
BaserK | 0:06434e97c4f2 | 6 | DigitalOut out3(p24); |
BaserK | 0:06434e97c4f2 | 7 | |
BaserK | 0:06434e97c4f2 | 8 | /* Function Prototype */ |
BaserK | 0:06434e97c4f2 | 9 | void brushlessControl(bool dir, int delay_time); |
BaserK | 0:06434e97c4f2 | 10 | |
BaserK | 0:06434e97c4f2 | 11 | int main() |
BaserK | 0:06434e97c4f2 | 12 | { |
BaserK | 0:06434e97c4f2 | 13 | while(1) |
BaserK | 0:06434e97c4f2 | 14 | { |
BaserK | 0:06434e97c4f2 | 15 | /* It works but slow */ |
BaserK | 0:06434e97c4f2 | 16 | brushlessControl(0,100); |
BaserK | 0:06434e97c4f2 | 17 | brushlessControl(1,100); |
BaserK | 0:06434e97c4f2 | 18 | } |
BaserK | 0:06434e97c4f2 | 19 | } |
BaserK | 0:06434e97c4f2 | 20 | |
BaserK | 0:06434e97c4f2 | 21 | void brushlessControl(bool dir, int delay_time) |
BaserK | 0:06434e97c4f2 | 22 | { |
BaserK | 0:06434e97c4f2 | 23 | /* Digital outputs are initially zero */ |
BaserK | 0:06434e97c4f2 | 24 | out1 = 0; out2 = 0; out3 = 0; |
BaserK | 0:06434e97c4f2 | 25 | |
BaserK | 0:06434e97c4f2 | 26 | /* Magical data_array to drive the brushless motor */ |
BaserK | 0:06434e97c4f2 | 27 | bool data_array[]={1,1,0, 1,0,0, 1,0,1, 0,0,1, 0,1,1, 0,1,0}; |
BaserK | 0:06434e97c4f2 | 28 | bool data_arrayInv[]={0,1,0, 0,1,1, 0,0,1, 1,0,1, 1,0,0, 1,1,0}; |
BaserK | 0:06434e97c4f2 | 29 | |
BaserK | 0:06434e97c4f2 | 30 | if(dir==1) // if dir = 1, reverse the motor direction |
BaserK | 0:06434e97c4f2 | 31 | for(int k=0; k<18; k++) |
BaserK | 0:06434e97c4f2 | 32 | data_array[k] = data_arrayInv[k]; |
BaserK | 0:06434e97c4f2 | 33 | |
BaserK | 0:06434e97c4f2 | 34 | for (int i=0; i<6; i++) |
BaserK | 0:06434e97c4f2 | 35 | { |
BaserK | 0:06434e97c4f2 | 36 | out1 = data_array[3*i]; |
BaserK | 0:06434e97c4f2 | 37 | out2 = data_array[3*i+1]; |
BaserK | 0:06434e97c4f2 | 38 | out3 = data_array[3*i+2]; |
BaserK | 0:06434e97c4f2 | 39 | wait_ms(delay_time); |
BaserK | 0:06434e97c4f2 | 40 | } |
BaserK | 0:06434e97c4f2 | 41 | } |