Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: photointerruptRoutines.h
- Revision:
- 53:c703e0bf5e87
- Parent:
- 50:c0c299bf54a6
- Child:
- 57:b1b4e1379613
- Child:
- 59:fcaef23bbaaf
--- a/photointerruptRoutines.h Fri Mar 24 17:30:41 2017 +0000
+++ b/photointerruptRoutines.h Fri Mar 24 18:27:23 2017 +0000
@@ -16,70 +16,76 @@
return stateMap[4*I3 + 2*I2 + I1]; // rotor state. Reports 1/6 positions
}
-void updateDiskPosition() {
- if (CH_state != CH_state_prev) {
- int diff = CH_state - CH_state_prev;
-
- CH_state_prev = CH_state;
- if (abs(diff) == 1 || abs(diff) == 3) {
- if (diff < 0)
- diskPosition += angularResolution;
- else
- diskPosition -= angularResolution;
- }
- else if (abs(diff) == 2) {
- if (diff < 0)
- diskPosition += 2.0f * angularResolution;
- else
- diskPosition -= 2.0f * angularResolution;
- }
-
- if (diskPosition >= 360.0f) {
- diskPosition -= 360.0f;
- } else if (diskPosition < -360.0f) {
- diskPosition += 360.0f;
- }
- }
-}
-
-inline void updateRelativeState() {
- CH_state = relativeStateMap[CHB_state + 2*CHA_state];
-}
+//void updateDiskPosition() {
+// if (CH_state != CH_state_prev) {
+// int diff = CH_state - CH_state_prev;
+//
+// CH_state_prev = CH_state;
+// if (abs(diff) == 1 || abs(diff) == 3) {
+// if (diff < 0)
+// diskPosition += angularResolution;
+// else
+// diskPosition -= angularResolution;
+// }
+// else if (abs(diff) == 2) {
+// if (diff < 0)
+// diskPosition += 2.0f * angularResolution;
+// else
+// diskPosition -= 2.0f * angularResolution;
+// }
+//
+// if (diskPosition >= 360.0f) {
+// diskPosition -= 360.0f;
+// } else if (diskPosition < -360.0f) {
+// diskPosition += 360.0f;
+// }
+// }
+//}
+//
+//inline void updateRelativeState() {
+// CH_state = relativeStateMap[CHB_state + 2*CHA_state];
+//}
-inline void CHA_rise() {
- CHA_state = 1;
- updateRelativeState();
- updateDiskPosition();
-}
-
-// Takes 5-6us
-inline void CHA_fall() {
- CHA_state = 0;
- updateRelativeState();
- updateDiskPosition();
-}
-inline void CHB_rise() {
- CHB_state = 1;
- updateRelativeState();
- updateDiskPosition();
-}
-inline void CHB_fall() {
- CHB_state = 0;
- updateRelativeState();
- updateDiskPosition();
-}
+//inline void CHA_rise() {
+// CHA_state = 1;
+// updateRelativeState();
+// updateDiskPosition();
+//}
+//
+//// Takes 5-6us
+//inline void CHA_fall() {
+// CHA_state = 0;
+// updateRelativeState();
+// updateDiskPosition();
+//}
+//inline void CHB_rise() {
+// CHB_state = 1;
+// updateRelativeState();
+// updateDiskPosition();
+//}
+//inline void CHB_fall() {
+// CHB_state = 0;
+// updateRelativeState();
+// updateDiskPosition();
+//}
void i_edge(){
state = updateState();
motorOut((state-orState+lead+6)%6, velocityDuty);
}
-
-inline void i3rise(){
+Mutex mutex;
+void i3rise(){
+ mutex.lock();
+ w3 = 1/dt_I3.read(); //Calc angular velocity
+ mutex.unlock();
+
+ dt_I3.reset();
+
+ if (I2.read() == 1){ //Only count revolutions if the
+ mutex.lock();
+ count_i3++; // rotor spins forward
+ mutex.unlock();
+ }
state = updateState();
motorOut((state-orState+lead+6)%6, velocityDuty);
- w3 = 1/dt_I3.read(); //Calc angular velocity
- dt_I3.reset();
-
- if (I2.read() == 1) //Only count revolutions if the
- count_i3++; // rotor spins forward
}
\ No newline at end of file
