Roger Weng
/
MotorControl
Motor control on mbed
Revision 1:f47edcd44466, committed 2016-07-23
- Comitter:
- roger5641
- Date:
- Sat Jul 23 16:00:05 2016 +0000
- Parent:
- 0:f76be6916639
- Commit message:
- CN interrupt
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f76be6916639 -r f47edcd44466 main.cpp --- a/main.cpp Sat Jul 23 13:47:47 2016 +0000 +++ b/main.cpp Sat Jul 23 16:00:05 2016 +0000 @@ -8,10 +8,12 @@ void init_CN(void); void CN_interrupt(void); -int8_t stateA=0, stateB=0, stateC=0, stateB_2=0; +int8_t stateA=0, stateB=0, stateC=0; int8_t state_1 = 0, state_1_old = 0; +int vCount; int main() { + init_CN(); while(1) { @@ -19,6 +21,66 @@ } } +void CN_interrupt(void) +{ + //Motor 1 + stateA = HallA.read(); + stateB = HallB.read(); + stateC = HallC.read(); + + ///code for state determination/// + if (stateA == 1) + { + if (stateB == 1) + if(stateC == 0) + { + state_1 = 2; + } + else + { + ; + } + else + if(stateC == 1) + { + state_1 = 6; + } + else + { + state_1 = 1; + } + } + else + { + if (stateB == 1) + if(stateC == 1) + { + state_1 = 4; + } + else + { + state_1 = 3; + } + else + if(stateC == 1) + { + state_1 = 5; + } + else + { + ; + } + } + + //Forward: vCount +1 + //Inverse: vCount -1 + if ( (state_1 == (state_1_old + 1)) || (state_1 == 1 && state_1_old == 6) ) + vCount++; + else if ( (state_1 == (state_1_old - 1)) || (state_1 == 6 && state_1_old == 1)) + vCount--; + + state_1_old = state_1; +} void init_CN(void) { @@ -31,38 +93,6 @@ stateA = HallA.read(); stateB = HallB.read(); - stateC = HallC.read(); -} - -void CN_interrupt(void) -{ - //Motor 1 - stateA = HallA.read(); - stateB = HallB.read(); stateC = HallC.read(); - ///code for state determination/// - if (stateA == 0) - { - if (stateB == 0) - state_1 = 0; - else - state_1 = 1; - } - else - { - if (stateB_1 == 1) - state_1 = 2; - else - state_1 = 3; - } - - //Forward: v1Count +1 - //Inverse: v1Count -1 - if ( (state_1 == (state_1_old + 1)) || (state_1 == 0 && state_1_old == 3) ) - v1Count++; - else if ( (state_1 == (state_1_old - 1)) || (state_1 == 3 && state_1_old == 0)) - v1Count--; - - state_1_old = state_1; } \ No newline at end of file