STM32F302R8 with Konrad's inverter boards for senior design.
Fork of Blue_Board_Ticker by
Diff: main.cpp
- Revision:
- 15:dddb511c39b4
- Parent:
- 14:0f50e85bd463
- Child:
- 16:792055c232a5
--- a/main.cpp Wed Apr 13 18:54:12 2016 +0000 +++ b/main.cpp Wed Apr 13 18:56:08 2016 +0000 @@ -36,10 +36,10 @@ } //original names: CBA CBA, new names: BAC BAC void Brise() //state1, A0 B- C+ -{ +{ phaseAEN = 0; phaseBEN = 1; - + phaseC.write(pwmDuty); phaseCEN = 1; // redLed = ! redLed; @@ -52,7 +52,7 @@ phaseC.write(0); phaseA.write(pwmDuty); phaseAEN = 1; - + phaseBEN = 1; } @@ -60,7 +60,7 @@ { phaseBEN = 0; phaseCEN = 1; - + phaseA.write(pwmDuty); phaseAEN = 1; } @@ -71,7 +71,7 @@ phaseA.write(0); phaseB.write(pwmDuty); phaseBEN = 1; - + phaseCEN = 1; // redLed = ! redLed; } @@ -80,7 +80,7 @@ { phaseCEN = 0; phaseAEN = 1; - + phaseB.write(pwmDuty); phaseBEN = 1; } @@ -91,13 +91,13 @@ phaseB.write(0); phaseC.write(pwmDuty); phaseCEN = 1; - + phaseAEN = 1; } void toggleRedLed() { - redLed = !redLed; + redLed = !redLed; } void jumpStart() @@ -106,33 +106,22 @@ int h2 = hallB.read(); int h3 = hallC.read(); //check where we start - if(h1 == 0 && h2 == 1 && h3 == 1) //state1 - { + if(h1 == 0 && h2 == 1 && h3 == 1) { //state1 // Brise(); Afall(); - } - else if(h1 == 0 && h2 == 0 && h3 == 1) //state2 - { + } else if(h1 == 0 && h2 == 0 && h3 == 1) { //state2 // Afall(); Crise(); - } - else if(h1 == 1 && h2 == 0 && h3 == 1) //state3 - { + } else if(h1 == 1 && h2 == 0 && h3 == 1) { //state3 // Crise(); Bfall(); - } - else if(h1 == 1 && h2 == 0 && h3 == 0) //state4 - { + } else if(h1 == 1 && h2 == 0 && h3 == 0) { //state4 // Bfall(); Arise(); - } - else if(h1 == 1 && h2 == 1 && h3 == 0) //state5 - { + } else if(h1 == 1 && h2 == 1 && h3 == 0) { //state5 // Arise(); Cfall(); - } - else //(h1 == 0 && h2 == 1 && h3 == 0)state6 - { + } else { //(h1 == 0 && h2 == 1 && h3 == 0)state6 // Cfall(); Brise(); } @@ -141,12 +130,9 @@ void activate() { - if(stall == 0) - { + if(stall == 0) { stall = 1; - } - else - { + } else { jumpStart(); // if(reverse == 1) //switch to forward // { @@ -162,7 +148,7 @@ // else if(reverse == 0) //switch to reverse // { // hallA.fall(&Bfall); -// hallA.rise(&Brise); +// hallA.rise(&Brise); // hallB.fall(&Cfall); // hallB.rise(&Crise); // hallC.fall(&Afall); @@ -175,7 +161,8 @@ -int main() { +int main() +{ //wait until button push to start rpmInterrupt.attach(&rpmCalc, 1); button.rise(&activate); @@ -189,22 +176,22 @@ phaseA.period_us(50); phaseB.period_us(50); phaseC.period_us(50); - + phaseA.write(0); phaseB.write(0); - phaseC.write(0); - + phaseC.write(0); + phaseAEN = 0; phaseBEN = 0; phaseCEN = 0; - //begin sensored mode + //begin sensored mode // hallA.fall(&Afall); // hallA.rise(&Arise); // hallB.fall(&Bfall); // hallB.rise(&Brise); // hallC.fall(&Cfall); -// hallC.rise(&Crise); - +// hallC.rise(&Crise); + spinTicker.attach_us(&jumpStart, 50); float ADCSum = 0;; int ADCCount = 0; @@ -212,14 +199,12 @@ led = !led; ADCSum += pot.read(); ADCCount++; - if(ADCCount == 20) - { + if(ADCCount == 20) { pwmDuty = (ADCSum/20) * pwmMax; ADCSum = 0; ADCCount = 0; } - if(rpmPrintFlag == 1) - { + if(rpmPrintFlag == 1) { printf("%d rpm; %f duty\r\n", currentRPM, pwmDuty); rpmPrintFlag = 0; }