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.
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 3:e3d12393adb1
- Parent:
- 2:bbaa6fca2ab1
- Child:
- 4:36e32ddf2443
--- a/main.cpp Wed Oct 02 11:22:51 2019 +0000
+++ b/main.cpp Wed Oct 02 12:45:18 2019 +0000
@@ -3,21 +3,24 @@
#include "FastPWM.h"
#include "QEI.h"
+MODSERIAL pc(USBTX, USBRX);
DigitalOut motor2_direction(D4);
PwmOut motor2_pwm(D5);
+QEI encoder (D11, D12, NC, 8400, QEI::X4_ENCODING);
+
+int enc_count;
+int prev_count = 0;
+
int main() {
+ pc.baud(115200);
+ pc.printf("initializing\r\n");
+
while (true) {
- motor2_direction = 1;
- for (float i = 0; i < 1; i+=0.01) {
- motor2_pwm = i;
- wait(0.1);
- }
- motor2_direction = 0;
- for (float i = 0; i < 1; i+=0.01) {
- motor2_pwm = i;
- wait(0.1);
- }
+ enc_count = encoder.getPulses();
+ pc.printf("%f\r\n", float(enc_count-prev_count)*360/(8400*0.025));
+ prev_count = enc_count;
+ wait_ms(25);
}
}
\ No newline at end of file