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.
Dependencies: mbed
TB6612.cpp@2:9885740002da, 2019-11-08 (annotated)
- Committer:
- KINU
- Date:
- Fri Nov 08 16:54:04 2019 +0000
- Revision:
- 2:9885740002da
Drivemoter completed
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| KINU | 2:9885740002da | 1 | /** |
| KINU | 2:9885740002da | 2 | * Motor Driver TB6612 Control Library |
| KINU | 2:9885740002da | 3 | * |
| KINU | 2:9885740002da | 4 | * -- TB6612 is a device of the TOSHIBA. |
| KINU | 2:9885740002da | 5 | * |
| KINU | 2:9885740002da | 6 | * Copyright (C) 2012 Junichi Katsu (JKSOFT) |
| KINU | 2:9885740002da | 7 | */ |
| KINU | 2:9885740002da | 8 | |
| KINU | 2:9885740002da | 9 | |
| KINU | 2:9885740002da | 10 | #include "TB6612.h" |
| KINU | 2:9885740002da | 11 | |
| KINU | 2:9885740002da | 12 | // TB6612 Class Constructor |
| KINU | 2:9885740002da | 13 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
| KINU | 2:9885740002da | 14 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
| KINU | 2:9885740002da | 15 | |
| KINU | 2:9885740002da | 16 | _fwd = 0; |
| KINU | 2:9885740002da | 17 | _rev = 0; |
| KINU | 2:9885740002da | 18 | _pwm = 0.0; |
| KINU | 2:9885740002da | 19 | _pwm.period(0.001); |
| KINU | 2:9885740002da | 20 | } |
| KINU | 2:9885740002da | 21 | |
| KINU | 2:9885740002da | 22 | // Speed Control |
| KINU | 2:9885740002da | 23 | // arg |
| KINU | 2:9885740002da | 24 | // int speed -100 -- 0 -- 100 |
| KINU | 2:9885740002da | 25 | void TB6612::speed(int speed) { |
| KINU | 2:9885740002da | 26 | |
| KINU | 2:9885740002da | 27 | if( speed > 0 ) |
| KINU | 2:9885740002da | 28 | { |
| KINU | 2:9885740002da | 29 | _pwm = ((float)speed) / 100.0; |
| KINU | 2:9885740002da | 30 | _fwd = 1; |
| KINU | 2:9885740002da | 31 | _rev = 0; |
| KINU | 2:9885740002da | 32 | } |
| KINU | 2:9885740002da | 33 | else if( speed < 0 ) |
| KINU | 2:9885740002da | 34 | { |
| KINU | 2:9885740002da | 35 | _pwm = -((float)speed) / 100.0; |
| KINU | 2:9885740002da | 36 | _fwd = 0; |
| KINU | 2:9885740002da | 37 | _rev = 1; |
| KINU | 2:9885740002da | 38 | } |
| KINU | 2:9885740002da | 39 | else |
| KINU | 2:9885740002da | 40 | { |
| KINU | 2:9885740002da | 41 | _fwd = 1; |
| KINU | 2:9885740002da | 42 | _rev = 1; |
| KINU | 2:9885740002da | 43 | } |
| KINU | 2:9885740002da | 44 | } |
| KINU | 2:9885740002da | 45 | |
| KINU | 2:9885740002da | 46 | |
| KINU | 2:9885740002da | 47 | // Speed Control with time-out |
| KINU | 2:9885740002da | 48 | // arg |
| KINU | 2:9885740002da | 49 | // int speed -100 -- 0 -- 100 |
| KINU | 2:9885740002da | 50 | // int time 0 |
| KINU | 2:9885740002da | 51 | void TB6612::move(int sspeed , int time) |
| KINU | 2:9885740002da | 52 | { |
| KINU | 2:9885740002da | 53 | speed(sspeed); |
| KINU | 2:9885740002da | 54 | wait_ms(time); |
| KINU | 2:9885740002da | 55 | } |
| KINU | 2:9885740002da | 56 | |
| KINU | 2:9885740002da | 57 |