Brad VanderWilp
/
Blue_Board_Test_2
Senior design sensored code to run freescale motor with IM07M1
Diff: main.cpp
- Revision:
- 6:e401c592d2c3
- Parent:
- 5:6110655353ad
- Child:
- 7:9d90184335aa
diff -r 6110655353ad -r e401c592d2c3 main.cpp --- a/main.cpp Wed Apr 06 20:36:41 2016 +0000 +++ b/main.cpp Mon Apr 11 16:38:16 2016 +0000 @@ -17,11 +17,22 @@ InterruptIn hallB(PB_3); //H2, Blue InterruptIn hallC(PB_10); //H3, White -Ticker interrupt; +Ticker rpmInterrupt; +int revCount = 0; +int rpmPrintFlag = 0; +int currentRPM; float pwmMax = 0.9; float pwmDuty; int stall = 0; + +void rpmCalc() +{ + currentRPM = revCount * 60; + revCount = 0; + rpmPrintFlag = 1; +} + void activate() { stall = 1; @@ -35,6 +46,7 @@ phaseC.write(pwmDuty); phaseCEN = 1; redLed = ! redLed; + revCount++; } void Bfall() //state2, A+ B- C0 @@ -131,6 +143,7 @@ int main() { //wait until button push to start + rpmInterrupt.attach(&rpmCalc, 1); button.rise(&activate); while(stall == 0) { led = !led; @@ -227,7 +240,11 @@ ADCSum = 0; ADCCount = 0; } -// pwmDuty = pot.read() * 0.7; + if(rpmPrintFlag == 1) + { + printf("%d rpm\r\n", currentRPM); + rpmPrintFlag = 0; + } wait(0.05); } }