Test two motors using pwm with an LMD18200 H-Bridge Driver. Ramps both motors in either direction with a pwm frequency of 20kHz.
Fork of Motor by
Motor.cpp@3:bab4eebbf1a0, 2012-11-08 (annotated)
- Committer:
- moose
- Date:
- Thu Nov 08 15:52:42 2012 +0000
- Revision:
- 3:bab4eebbf1a0
- Parent:
- 2:f265e441bcd9
Changed Motor to 2 input - pwm & direction
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:a470311addc4 | 1 | /* mbed simple H-bridge motor controller |
simon | 2:f265e441bcd9 | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
simon | 0:a470311addc4 | 3 | * |
simon | 0:a470311addc4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 0:a470311addc4 | 5 | * of this software and associated documentation files (the "Software"), to deal |
simon | 0:a470311addc4 | 6 | * in the Software without restriction, including without limitation the rights |
simon | 0:a470311addc4 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 0:a470311addc4 | 8 | * copies of the Software, and to permit persons to whom the Software is |
simon | 0:a470311addc4 | 9 | * furnished to do so, subject to the following conditions: |
simon | 0:a470311addc4 | 10 | * |
simon | 0:a470311addc4 | 11 | * The above copyright notice and this permission notice shall be included in |
simon | 0:a470311addc4 | 12 | * all copies or substantial portions of the Software. |
simon | 0:a470311addc4 | 13 | * |
simon | 0:a470311addc4 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 0:a470311addc4 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 0:a470311addc4 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 0:a470311addc4 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 0:a470311addc4 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 0:a470311addc4 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 0:a470311addc4 | 20 | * THE SOFTWARE. |
simon | 0:a470311addc4 | 21 | */ |
simon | 0:a470311addc4 | 22 | |
simon | 0:a470311addc4 | 23 | #include "Motor.h" |
simon | 0:a470311addc4 | 24 | |
simon | 0:a470311addc4 | 25 | #include "mbed.h" |
simon | 0:a470311addc4 | 26 | |
moose | 3:bab4eebbf1a0 | 27 | Motor::Motor(PinName pwm, PinName dir): |
moose | 3:bab4eebbf1a0 | 28 | _pwm(pwm), _dir(dir) { |
simon | 0:a470311addc4 | 29 | |
simon | 0:a470311addc4 | 30 | // Set initial condition of PWM |
moose | 3:bab4eebbf1a0 | 31 | _pwm.period(0.00005); //20kHz |
simon | 0:a470311addc4 | 32 | _pwm = 0; |
simon | 0:a470311addc4 | 33 | |
simon | 0:a470311addc4 | 34 | // Initial condition of output enables |
moose | 3:bab4eebbf1a0 | 35 | _dir = 1; |
moose | 3:bab4eebbf1a0 | 36 | // _rev = 0; |
simon | 0:a470311addc4 | 37 | } |
simon | 0:a470311addc4 | 38 | |
simon | 0:a470311addc4 | 39 | void Motor::speed(float speed) { |
moose | 3:bab4eebbf1a0 | 40 | _dir = (speed > 0.0); |
moose | 3:bab4eebbf1a0 | 41 | // _rev = (speed < 0.0); |
simon | 0:a470311addc4 | 42 | _pwm = abs(speed); |
simon | 0:a470311addc4 | 43 | } |
simon | 0:a470311addc4 | 44 | |
simon | 0:a470311addc4 | 45 | |
simon | 0:a470311addc4 | 46 |