STM32F302R8 with Konrad's inverter boards for senior design.
Fork of Blue_Board_Ticker by
Diff: main.cpp
- Revision:
- 16:792055c232a5
- Parent:
- 15:dddb511c39b4
- Child:
- 17:5e27edd3d8e6
--- a/main.cpp Wed Apr 13 18:56:08 2016 +0000 +++ b/main.cpp Wed Apr 13 19:09:10 2016 +0000 @@ -42,7 +42,6 @@ phaseC.write(pwmDuty); phaseCEN = 1; -// redLed = ! redLed; revCount++; } @@ -73,7 +72,6 @@ phaseBEN = 1; phaseCEN = 1; -// redLed = ! redLed; } void Arise() //state5, A- B+ C0 @@ -106,24 +104,41 @@ int h2 = hallB.read(); int h3 = hallC.read(); //check where we start - if(h1 == 0 && h2 == 1 && h3 == 1) { //state1 -// Brise(); - Afall(); - } else if(h1 == 0 && h2 == 0 && h3 == 1) { //state2 -// Afall(); - Crise(); - } else if(h1 == 1 && h2 == 0 && h3 == 1) { //state3 -// Crise(); - Bfall(); - } else if(h1 == 1 && h2 == 0 && h3 == 0) { //state4 -// Bfall(); - Arise(); - } else if(h1 == 1 && h2 == 1 && h3 == 0) { //state5 -// Arise(); - Cfall(); - } else { //(h1 == 0 && h2 == 1 && h3 == 0)state6 -// Cfall(); - Brise(); + + if (reverse == 0) + { + if(h1 == 0 && h2 == 1 && h3 == 1) { //state1 + Afall(); + } else if(h1 == 0 && h2 == 0 && h3 == 1) { //state2 + Crise(); + } else if(h1 == 1 && h2 == 0 && h3 == 1) { //state3 + Bfall(); + } else if(h1 == 1 && h2 == 0 && h3 == 0) { //state4 + Arise(); + } else if(h1 == 1 && h2 == 1 && h3 == 0) { //state5 + Cfall(); + } else { //(h1 == 0 && h2 == 1 && h3 == 0)state6 + Brise(); + } + } + else if (reverse == 1) + { + // A -> C + // B -> A + // C -> B + if(h1 == 0 && h2 == 1 && h3 == 1) { //state1 + Cfall(); + } else if(h1 == 0 && h2 == 0 && h3 == 1) { //state2 + Brise(); + } else if(h1 == 1 && h2 == 0 && h3 == 1) { //state3 + Afall(); + } else if(h1 == 1 && h2 == 0 && h3 == 0) { //state4 + Crise(); + } else if(h1 == 1 && h2 == 1 && h3 == 0) { //state5 + Bfall(); + } else { //(h1 == 0 && h2 == 1 && h3 == 0) state6 + Arise(); + } } toggleRedLed(); } @@ -133,34 +148,13 @@ if(stall == 0) { stall = 1; } else { - jumpStart(); -// if(reverse == 1) //switch to forward -// { -// hallA.fall(&Afall); -// hallA.rise(&Arise); -// hallB.fall(&Bfall); -// hallB.rise(&Brise); -// hallC.fall(&Cfall); -// hallC.rise(&Crise); -// redLed = !redLed; -// reverse = 0; -// } -// else if(reverse == 0) //switch to reverse -// { -// hallA.fall(&Bfall); -// hallA.rise(&Brise); -// hallB.fall(&Cfall); -// hallB.rise(&Crise); -// hallC.fall(&Afall); -// hallC.rise(&Arise); -// redLed = !redLed; -// reverse = 1; -// } + if (pwmDuty < 0.2f) + { + reverse = reverse ^ 1; + } } } - - int main() { //wait until button push to start @@ -184,16 +178,9 @@ phaseAEN = 0; phaseBEN = 0; phaseCEN = 0; - //begin sensored mode -// hallA.fall(&Afall); -// hallA.rise(&Arise); -// hallB.fall(&Bfall); -// hallB.rise(&Brise); -// hallC.fall(&Cfall); -// hallC.rise(&Crise); spinTicker.attach_us(&jumpStart, 50); - float ADCSum = 0;; + float ADCSum = 0; int ADCCount = 0; while(1) { led = !led; @@ -205,7 +192,7 @@ ADCCount = 0; } if(rpmPrintFlag == 1) { - printf("%d rpm; %f duty\r\n", currentRPM, pwmDuty); + printf("%d rpm; %f duty; reverse: %d\r\n", currentRPM, pwmDuty, reverse); rpmPrintFlag = 0; } wait(0.05);