Drivers for the mini robot designed for Princeton's MAE 433 course.
Dependencies: mbed-dsp mbed-rtos mbed
Dependents: MAE433_Library_Tester RobotBalancerv2
Diff: FixedRefresh.cpp
- Revision:
- 7:28f3a76792cd
- Parent:
- 6:076fcae78bac
diff -r 076fcae78bac -r 28f3a76792cd FixedRefresh.cpp --- a/FixedRefresh.cpp Wed Jun 29 19:04:28 2016 +0000 +++ b/FixedRefresh.cpp Wed Jun 29 21:41:55 2016 +0000 @@ -10,7 +10,7 @@ FixedRefresh::FixedRefresh() -:waitSemaphore(1) { +:waitSemaphore(0) { // Start the timer that measures the time between successive calls. elapsedTime.start(); } @@ -25,12 +25,10 @@ bool FixedRefresh::refresh_us(uint32_t micros) { /* Capture the elapsed time. */ - uint32_t elapsedTimeCapture = elapsedTime.read_us() + 12; + uint32_t elapsedTimeCapture = elapsedTime.read_us() + 7; // If the elapsed time is less than the set time, then we can wait. if(elapsedTimeCapture < micros) { uint32_t waitTime = micros - elapsedTimeCapture; - // Call the semaphore's wait function, thereby locking it. - waitSemaphore.wait(); // Activate the timer callback. waitTimer.attach_us(this, &FixedRefresh::timerCallback, waitTime); // Call the wait function again. Since we have called wait before, it is locked. @@ -46,6 +44,5 @@ void FixedRefresh::timerCallback() { elapsedTime.reset(); waitSemaphore.release(); - waitSemaphore.release(); }