L9110S H-Bridge Driver
Fork of L9110S by
L9110S.h@0:1a9b998e0ec1, 2015-10-31 (annotated)
- Committer:
- HMFK03LST1
- Date:
- Sat Oct 31 15:22:33 2015 +0000
- Revision:
- 0:1a9b998e0ec1
- Child:
- 3:695e0c6881c5
L9110S H-Bridge driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HMFK03LST1 | 0:1a9b998e0ec1 | 1 | #include "mbed.h" |
HMFK03LST1 | 0:1a9b998e0ec1 | 2 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 3 | /** L9110S H-Brigh Driver Interface |
HMFK03LST1 | 0:1a9b998e0ec1 | 4 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 5 | * By Sebastian Donner |
HMFK03LST1 | 0:1a9b998e0ec1 | 6 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 7 | * Permission is hereby granted, free of charge, to any person |
HMFK03LST1 | 0:1a9b998e0ec1 | 8 | * obtaining a copy of this software and associated documentation |
HMFK03LST1 | 0:1a9b998e0ec1 | 9 | * files (the "Software"), to deal in the Software without |
HMFK03LST1 | 0:1a9b998e0ec1 | 10 | * restriction, including without limitation the rights to use, |
HMFK03LST1 | 0:1a9b998e0ec1 | 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell |
HMFK03LST1 | 0:1a9b998e0ec1 | 12 | * copies of the Software, and to permit persons to whom the |
HMFK03LST1 | 0:1a9b998e0ec1 | 13 | * Software is furnished to do so, subject to the following |
HMFK03LST1 | 0:1a9b998e0ec1 | 14 | * conditions: |
HMFK03LST1 | 0:1a9b998e0ec1 | 15 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 16 | * The above copyright notice and this permission notice shall be |
HMFK03LST1 | 0:1a9b998e0ec1 | 17 | * included in all copies or substantial portions of the Software. |
HMFK03LST1 | 0:1a9b998e0ec1 | 18 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
HMFK03LST1 | 0:1a9b998e0ec1 | 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
HMFK03LST1 | 0:1a9b998e0ec1 | 21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
HMFK03LST1 | 0:1a9b998e0ec1 | 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
HMFK03LST1 | 0:1a9b998e0ec1 | 23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
HMFK03LST1 | 0:1a9b998e0ec1 | 24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
HMFK03LST1 | 0:1a9b998e0ec1 | 25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
HMFK03LST1 | 0:1a9b998e0ec1 | 26 | * OTHER DEALINGS IN THE SOFTWARE. |
HMFK03LST1 | 0:1a9b998e0ec1 | 27 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 28 | * @code |
HMFK03LST1 | 0:1a9b998e0ec1 | 29 | * #include "mbed.h" |
HMFK03LST1 | 0:1a9b998e0ec1 | 30 | * #include "L9110S.h" |
HMFK03LST1 | 0:1a9b998e0ec1 | 31 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 32 | * Serial debug(USBTX,USBRX); |
HMFK03LST1 | 0:1a9b998e0ec1 | 33 | * L9119S motor_x(p21, p22); |
HMFK03LST1 | 0:1a9b998e0ec1 | 34 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 35 | * int main() |
HMFK03LST1 | 0:1a9b998e0ec1 | 36 | * { |
HMFK03LST1 | 0:1a9b998e0ec1 | 37 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 38 | * int power = 0; |
HMFK03LST1 | 0:1a9b998e0ec1 | 39 | * int step = 1; |
HMFK03LST1 | 0:1a9b998e0ec1 | 40 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 41 | * debug.baud(115200); |
HMFK03LST1 | 0:1a9b998e0ec1 | 42 | * debug.printf("L9110S Motor Test"); |
HMFK03LST1 | 0:1a9b998e0ec1 | 43 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 44 | * while(1) |
HMFK03LST1 | 0:1a9b998e0ec1 | 45 | * { |
HMFK03LST1 | 0:1a9b998e0ec1 | 46 | * power += step; |
HMFK03LST1 | 0:1a9b998e0ec1 | 47 | * motor_x.drive(power); |
HMFK03LST1 | 0:1a9b998e0ec1 | 48 | * debug.printf("Power: %i\n\r", power ); |
HMFK03LST1 | 0:1a9b998e0ec1 | 49 | * wait(0.10); |
HMFK03LST1 | 0:1a9b998e0ec1 | 50 | * if ((power > 99)||(power < -99)) step *= -1; |
HMFK03LST1 | 0:1a9b998e0ec1 | 51 | # } |
HMFK03LST1 | 0:1a9b998e0ec1 | 52 | * } |
HMFK03LST1 | 0:1a9b998e0ec1 | 53 | * @endcode |
HMFK03LST1 | 0:1a9b998e0ec1 | 54 | */ |
HMFK03LST1 | 0:1a9b998e0ec1 | 55 | class L9110S { |
HMFK03LST1 | 0:1a9b998e0ec1 | 56 | public: |
HMFK03LST1 | 0:1a9b998e0ec1 | 57 | //! Min Power in PWM% for clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 58 | int cw_min; |
HMFK03LST1 | 0:1a9b998e0ec1 | 59 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 60 | //! Max Power in PWM% for clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 61 | int cw_max; |
HMFK03LST1 | 0:1a9b998e0ec1 | 62 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 63 | //! Min Power in PWM% for counter clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 64 | int ccw_min; |
HMFK03LST1 | 0:1a9b998e0ec1 | 65 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 66 | //! Max Power in PWM% for counter clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 67 | int ccw_max; |
HMFK03LST1 | 0:1a9b998e0ec1 | 68 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 69 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 70 | /** Create a new interface for an L9110S |
HMFK03LST1 | 0:1a9b998e0ec1 | 71 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 72 | * @param cw_r is the pin for clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 73 | * @param ccw_r is the pin for counter clockwise rotate |
HMFK03LST1 | 0:1a9b998e0ec1 | 74 | */ |
HMFK03LST1 | 0:1a9b998e0ec1 | 75 | L9110S(PinName cw_r, PinName ccw_r); |
HMFK03LST1 | 0:1a9b998e0ec1 | 76 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 77 | /** sets Pulswidth |
HMFK03LST1 | 0:1a9b998e0ec1 | 78 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 79 | * positiv in clockwise Dir |
HMFK03LST1 | 0:1a9b998e0ec1 | 80 | * negativ in counter clockwise Dir |
HMFK03LST1 | 0:1a9b998e0ec1 | 81 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 82 | * in % of range from min_(cw/ccw) to max_(cw/ccw) |
HMFK03LST1 | 0:1a9b998e0ec1 | 83 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 84 | */ |
HMFK03LST1 | 0:1a9b998e0ec1 | 85 | void drive(int power); |
HMFK03LST1 | 0:1a9b998e0ec1 | 86 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 87 | /** sets Pulswidth |
HMFK03LST1 | 0:1a9b998e0ec1 | 88 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 89 | * positiv dir is clockwise direction |
HMFK03LST1 | 0:1a9b998e0ec1 | 90 | * negativ dir is counter clockwise direction |
HMFK03LST1 | 0:1a9b998e0ec1 | 91 | * zero is stop |
HMFK03LST1 | 0:1a9b998e0ec1 | 92 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 93 | * power in % of range from min_(cw/ccw) to max_(cw/ccw) |
HMFK03LST1 | 0:1a9b998e0ec1 | 94 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 95 | */ |
HMFK03LST1 | 0:1a9b998e0ec1 | 96 | void drive(int dir, int power); |
HMFK03LST1 | 0:1a9b998e0ec1 | 97 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 98 | /** sets the PWM frequency |
HMFK03LST1 | 0:1a9b998e0ec1 | 99 | * |
HMFK03LST1 | 0:1a9b998e0ec1 | 100 | * @param hz is the PWM frequency (default 2000 Hz) |
HMFK03LST1 | 0:1a9b998e0ec1 | 101 | */ |
HMFK03LST1 | 0:1a9b998e0ec1 | 102 | void frequency(int hz); |
HMFK03LST1 | 0:1a9b998e0ec1 | 103 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 104 | private: |
HMFK03LST1 | 0:1a9b998e0ec1 | 105 | PwmOut _cw; |
HMFK03LST1 | 0:1a9b998e0ec1 | 106 | PwmOut _ccw; |
HMFK03LST1 | 0:1a9b998e0ec1 | 107 | int periode; |
HMFK03LST1 | 0:1a9b998e0ec1 | 108 | |
HMFK03LST1 | 0:1a9b998e0ec1 | 109 | }; |