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.
main.cpp@1:c855dee2c6d4, 2015-09-28 (annotated)
- Committer:
- yohoo15
- Date:
- Mon Sep 28 12:33:24 2015 +0000
- Revision:
- 1:c855dee2c6d4
- Parent:
- 0:70a6fd5751a6
- Child:
- 2:f0215a034e04
Volatitle bool doet het niet?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yohoo15 | 0:70a6fd5751a6 | 1 | #include "mbed.h" |
| yohoo15 | 0:70a6fd5751a6 | 2 | #include "QEI.h" |
| yohoo15 | 0:70a6fd5751a6 | 3 | |
| yohoo15 | 0:70a6fd5751a6 | 4 | Serial pc(USBTX, USBRX); |
| yohoo15 | 0:70a6fd5751a6 | 5 | QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in) |
| yohoo15 | 0:70a6fd5751a6 | 6 | |
| yohoo15 | 0:70a6fd5751a6 | 7 | // Define pin for motor control |
| yohoo15 | 0:70a6fd5751a6 | 8 | DigitalOut directionPin(D4); |
| yohoo15 | 0:70a6fd5751a6 | 9 | PwmOut PWM(D5); |
| yohoo15 | 0:70a6fd5751a6 | 10 | |
| yohoo15 | 0:70a6fd5751a6 | 11 | |
| yohoo15 | 0:70a6fd5751a6 | 12 | |
| yohoo15 | 0:70a6fd5751a6 | 13 | // 8400 counts per revolution |
| yohoo15 | 0:70a6fd5751a6 | 14 | // so 8400 / (2 *pi) is counts/pi |
| yohoo15 | 0:70a6fd5751a6 | 15 | |
| yohoo15 | 0:70a6fd5751a6 | 16 | |
| yohoo15 | 0:70a6fd5751a6 | 17 | Ticker tellen; |
| yohoo15 | 1:c855dee2c6d4 | 18 | volatile bool stoppen = false; |
| yohoo15 | 0:70a6fd5751a6 | 19 | |
| yohoo15 | 0:70a6fd5751a6 | 20 | void GOTO() |
| yohoo15 | 0:70a6fd5751a6 | 21 | { |
| yohoo15 | 1:c855dee2c6d4 | 22 | double Offset = 10511 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over |
| yohoo15 | 1:c855dee2c6d4 | 23 | double resolution = Offset / (2 * 3.14159265); |
| yohoo15 | 0:70a6fd5751a6 | 24 | double Rotation = 4; // rotation in pi |
| yohoo15 | 0:70a6fd5751a6 | 25 | double movement = Rotation * resolution; |
| yohoo15 | 0:70a6fd5751a6 | 26 | |
| yohoo15 | 0:70a6fd5751a6 | 27 | // pc.printf("The number of real rotation is %i \n",Rotation); |
| yohoo15 | 0:70a6fd5751a6 | 28 | |
| yohoo15 | 0:70a6fd5751a6 | 29 | |
| yohoo15 | 0:70a6fd5751a6 | 30 | if (wheel.getPulses() <= movement) { |
| yohoo15 | 0:70a6fd5751a6 | 31 | directionPin.write(1); |
| yohoo15 | 0:70a6fd5751a6 | 32 | PWM.write(0.3); |
| yohoo15 | 0:70a6fd5751a6 | 33 | pc.printf("Pulses is: %i\n", wheel.getPulses()); |
| yohoo15 | 0:70a6fd5751a6 | 34 | } else { |
| yohoo15 | 0:70a6fd5751a6 | 35 | PWM.write(0); |
| yohoo15 | 0:70a6fd5751a6 | 36 | //pc.printf("The motor turned %i rotations \n",Rotation); |
| yohoo15 | 0:70a6fd5751a6 | 37 | pc.printf("Pulses is: %i\n The motor turned %.2f rotations\n", wheel.getPulses(),Rotation); |
| yohoo15 | 0:70a6fd5751a6 | 38 | stoppen = true; |
| yohoo15 | 0:70a6fd5751a6 | 39 | |
| yohoo15 | 0:70a6fd5751a6 | 40 | |
| yohoo15 | 0:70a6fd5751a6 | 41 | } |
| yohoo15 | 0:70a6fd5751a6 | 42 | |
| yohoo15 | 0:70a6fd5751a6 | 43 | |
| yohoo15 | 0:70a6fd5751a6 | 44 | |
| yohoo15 | 0:70a6fd5751a6 | 45 | |
| yohoo15 | 0:70a6fd5751a6 | 46 | } |
| yohoo15 | 0:70a6fd5751a6 | 47 | |
| yohoo15 | 0:70a6fd5751a6 | 48 | |
| yohoo15 | 0:70a6fd5751a6 | 49 | |
| yohoo15 | 0:70a6fd5751a6 | 50 | int main() |
| yohoo15 | 1:c855dee2c6d4 | 51 | |
| yohoo15 | 0:70a6fd5751a6 | 52 | { |
| yohoo15 | 0:70a6fd5751a6 | 53 | int proberen = 1000; |
| yohoo15 | 0:70a6fd5751a6 | 54 | pc.printf("The number of rotation is %i \n",proberen); |
| yohoo15 | 0:70a6fd5751a6 | 55 | |
| yohoo15 | 0:70a6fd5751a6 | 56 | |
| yohoo15 | 0:70a6fd5751a6 | 57 | |
| yohoo15 | 0:70a6fd5751a6 | 58 | |
| yohoo15 | 1:c855dee2c6d4 | 59 | while(stoppen == false){ |
| yohoo15 | 0:70a6fd5751a6 | 60 | tellen.attach(&GOTO, 0.1); |
| yohoo15 | 1:c855dee2c6d4 | 61 | } |
| yohoo15 | 0:70a6fd5751a6 | 62 | |
| yohoo15 | 0:70a6fd5751a6 | 63 | |
| yohoo15 | 0:70a6fd5751a6 | 64 | |
| yohoo15 | 0:70a6fd5751a6 | 65 | |
| yohoo15 | 0:70a6fd5751a6 | 66 | |
| yohoo15 | 0:70a6fd5751a6 | 67 | |
| yohoo15 | 0:70a6fd5751a6 | 68 | |
| yohoo15 | 0:70a6fd5751a6 | 69 | |
| yohoo15 | 0:70a6fd5751a6 | 70 | } |