Senior design censored code to run freescale motor with X-NUCLEO-IM07M1. REFACTORED
Fork of Blue_Board_Test_2 by
Diff: main.cpp
- Revision:
- 3:2bcc36fe4de5
- Parent:
- 2:0fbba327c44f
- Child:
- 4:ab4d51b5b1c8
--- a/main.cpp Wed Apr 06 19:45:47 2016 +0000 +++ b/main.cpp Wed Apr 06 20:01:18 2016 +0000 @@ -29,6 +29,8 @@ phaseAEN = 0; phaseBEN = 1; + phaseC.write(pwmDuty); + phaseCEN = 1; redLed = ! redLed; } @@ -38,12 +40,17 @@ phaseC.write(0); phaseA.write(pwmDuty); phaseAEN = 1; + + phaseBEN = 1; } void Arise() //state3, A+ B0 C- { phaseBEN = 0; phaseCEN = 1; + + phaseA.write(pwmDuty); + phaseAEN = 1; } void Cfall() //state4, A0 B+ C- @@ -53,6 +60,7 @@ phaseB.write(pwmDuty); phaseBEN = 1; + phaseCEN = 1; redLed = ! redLed; } @@ -60,6 +68,9 @@ { phaseCEN = 0; phaseAEN = 1; + + phaseB.write(pwmDuty); + phaseBEN = 1; } void Afall() //state5, A- B0 C+ @@ -68,6 +79,8 @@ phaseB.write(0); phaseC.write(pwmDuty); phaseCEN = 1; + + phaseAEN = 1; } int count = 0; @@ -120,38 +133,43 @@ led = !led; wait(2); } + button.detach(); - //startup with open loop +// //startup with open loop +// phaseA.period_us(10); +// phaseB.period_us(10); +// phaseC.period_us(10); +// interrupt.attach(&intcall, .01); +// +// +// phaseA.write(0); +// phaseB.write(pwmDuty); +// phaseC.write(0); +// +// phaseAEN = 0; +// phaseBEN = 1; +// phaseCEN = 1; +// +// for(int i = 0; i < 4; i++) +// { +// i++; +// led = !led; +// wait(0.5); +// } +// interrupt.detach(); + phaseA.period_us(10); phaseB.period_us(10); phaseC.period_us(10); - interrupt.attach(&intcall, .01); - phaseA.write(0); - phaseB.write(pwmDuty); + phaseB.write(0); phaseC.write(0); phaseAEN = 0; - phaseBEN = 1; - phaseCEN = 1; - - for(int i = 0; i < 4; i++) - { - i++; - led = !led; - wait(0.5); - } - interrupt.detach(); - //begin sensored mode - -// hallA.fall(&Arise); -// hallA.rise(&Afall); -// hallB.fall(&Brise); -// hallB.rise(&Bfall); -// hallC.fall(&Crise); -// hallC.rise(&Cfall); - + phaseBEN = 0; + phaseCEN = 0; + //begin sensored mode hallA.fall(&Afall); hallA.rise(&Arise); hallB.fall(&Bfall); @@ -159,6 +177,40 @@ hallC.fall(&Cfall); hallC.rise(&Crise); + int h1 = hallA.read(); + int h2 = hallB.read(); + int h3 = hallC.read(); + //check where we start + if(h1 == 0 && h2 == 1 && h3 == 1) //state1 + { + Crise(); + Bfall(); + } + else if(h1 == 0 && h2 == 0 && h3 == 1) //state2 + { + Bfall(); + Arise(); + } + else if(h1 == 1 && h2 == 0 && h3 == 1) //state3 + { + Arise(); + Cfall(); + } + else if(h1 == 1 && h2 == 0 && h3 == 0) //state4 + { + Cfall(); + Brise(); + } + else if(h1 == 1 && h2 == 1 && h3 == 0) //state5 + { + Brise(); + Crise(); + } + else //state6 + { + Afall(); + } + while(1) { led = !led; wait(0.2);