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.
Dependents: experiment_example motor_shield_example Position_ctrl Lab3_experiment_example ... more
Diff: MotorShield.cpp
- Revision:
- 5:d2dffc88e94d
- Parent:
- 4:2b45973bdc67
- Child:
- 7:e3a2ade56b79
diff -r 2b45973bdc67 -r d2dffc88e94d MotorShield.cpp
--- a/MotorShield.cpp Wed Aug 26 02:49:34 2020 +0000
+++ b/MotorShield.cpp Wed Aug 26 14:37:16 2020 +0000
@@ -22,47 +22,58 @@
}
-void MotorShield::motorAWrite(double duty_cycle, int direction) {
+void MotorShield::motorAWrite(float duty_cycle, int direction) {
+ int tick = (int)(periodTickVal * duty_cycle);
+
if (direction){
- TIM12->CCR2 = int(periodTickVal * duty_cycle);
- TIM12->CCR1 = 0;
+
+ TIM15->CCR2 = tick;
+ TIM15->CCR1 = 0;
+
}
else {
- TIM12->CCR2 = 0;
- TIM12->CCR1 = int(periodTickVal * duty_cycle);
+ TIM15->CCR2 = 0;
+ TIM15->CCR1 = tick;
}
}
-void MotorShield::motorBWrite(double duty_cycle, int direction) {
+void MotorShield::motorBWrite(float duty_cycle, int direction) {
+ int tick = (int)(periodTickVal * duty_cycle);
+
if (direction){
- TIM15->CCR2 = int(periodTickVal * duty_cycle);
- TIM15->CCR1 = 0;
+ TIM12->CCR2 = tick;
+ TIM12->CCR1 = 0;
}
else {
- TIM15->CCR2 = 0;
- TIM15->CCR1 = int(periodTickVal * duty_cycle);
+ TIM12->CCR2 = 0;
+ TIM12->CCR1 = tick;
}
+
}
-void MotorShield::motorCWrite(double duty_cycle, int direction) {
+void MotorShield::motorCWrite(float duty_cycle, int direction) {
+ int tick = (int)(periodTickVal * duty_cycle);
+
if (direction){
- TIM13->CCR1 = int(periodTickVal * duty_cycle);
- TIM14->CCR1 = 0;
+ TIM13->CCR1 = 0;
+ TIM14->CCR1 = tick;
}
else {
- TIM13->CCR1 = 0;
- TIM14->CCR1 = int(periodTickVal * duty_cycle);
+ TIM13->CCR1 = tick;
+ TIM14->CCR1 = 0;
}
}
-void MotorShield::motorDWrite(double duty_cycle, int direction) {
+void MotorShield::motorDWrite(float duty_cycle, int direction) {
+ int tick = (int)(periodTickVal * duty_cycle);
+
if (direction){
- TIM16->CCR1 = int(periodTickVal * duty_cycle);
+ TIM16->CCR1 = tick;
TIM17->CCR1 = 0;
}
else {
TIM16->CCR1 = 0;
- TIM17->CCR1 = int(periodTickVal * duty_cycle);
+ TIM17->CCR1 = tick;
}
}