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.
pwm.cpp@1:12f18cede014, 2018-02-15 (annotated)
- Committer:
- Weranest
- Date:
- Thu Feb 15 20:17:42 2018 +0000
- Revision:
- 1:12f18cede014
- Parent:
- 0:62e51b80d738
- Child:
- 3:c9df852ad9ac
Working motor pwm complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Weranest | 0:62e51b80d738 | 1 | //this defines motor setup and movement |
Weranest | 0:62e51b80d738 | 2 | #include "mbed.h" |
Weranest | 0:62e51b80d738 | 3 | #include "C12832.h" |
Weranest | 1:12f18cede014 | 4 | #include "pins.h" |
Weranest | 1:12f18cede014 | 5 | #include "pwm.h" |
Weranest | 0:62e51b80d738 | 6 | //will have to determine real pulsewidths by testing with encoder |
Weranest | 0:62e51b80d738 | 7 | //constants to be utilized in the buggy, can be changed as required |
Weranest | 0:62e51b80d738 | 8 | #define NORMAL_PWM 0.5f |
Weranest | 0:62e51b80d738 | 9 | #define FAST_PWM 0.7f |
Weranest | 0:62e51b80d738 | 10 | #define SLOW_PWM 0.3f |
Weranest | 0:62e51b80d738 | 11 | #define RIGHT_MOTOR_CONST 1 |
Weranest | 0:62e51b80d738 | 12 | #define LEFT_MOTOR_CONST 1 |
Weranest | 0:62e51b80d738 | 13 | #define MOTOR_PERIOD 1.0f |
Weranest | 0:62e51b80d738 | 14 | //currently the setup uses unipolar mode, hence the need for direction |
Weranest | 0:62e51b80d738 | 15 | |
Weranest | 0:62e51b80d738 | 16 | |
Weranest | 0:62e51b80d738 | 17 | void motorSetup(){ |
Weranest | 0:62e51b80d738 | 18 | motorRight.period_ms(MOTOR_PERIOD); |
Weranest | 0:62e51b80d738 | 19 | motorLeft.period_ms(MOTOR_PERIOD); |
Weranest | 1:12f18cede014 | 20 | motorDirLeft.write(0); |
Weranest | 1:12f18cede014 | 21 | motorDirRight.write(0); |
Weranest | 1:12f18cede014 | 22 | motorModeLeft.write(0); //1 =bipolar, 0 = unipolar |
Weranest | 1:12f18cede014 | 23 | motorModeRight.write(0); |
Weranest | 0:62e51b80d738 | 24 | driveBoard.write(1); |
Weranest | 0:62e51b80d738 | 25 | } |
Weranest | 0:62e51b80d738 | 26 | void buggyGoF(){ //drives forward |
Weranest | 0:62e51b80d738 | 27 | motorRight.write(NORMAL_PWM); |
Weranest | 0:62e51b80d738 | 28 | motorLeft.write(NORMAL_PWM); |
Weranest | 0:62e51b80d738 | 29 | } |
Weranest | 0:62e51b80d738 | 30 | |
Weranest | 0:62e51b80d738 | 31 | void buggyGoLeft(){// drives left |
Weranest | 0:62e51b80d738 | 32 | motorRight.write(FAST_PWM); |
Weranest | 0:62e51b80d738 | 33 | motorLeft.write(SLOW_PWM); |
Weranest | 0:62e51b80d738 | 34 | } |
Weranest | 0:62e51b80d738 | 35 | void buggyGoRight(){ //drives fast |
Weranest | 0:62e51b80d738 | 36 | motorRight.write(SLOW_PWM); |
Weranest | 0:62e51b80d738 | 37 | motorLeft.write(FAST_PWM); |
Weranest | 0:62e51b80d738 | 38 | } |
Weranest | 0:62e51b80d738 | 39 | void buggyStop(){// no power |
Weranest | 0:62e51b80d738 | 40 | motorRight.write(0.0f); |
Weranest | 0:62e51b80d738 | 41 | motorLeft.write(0.0f); |
Weranest | 0:62e51b80d738 | 42 | } |