Tripple Controller for the TLE5206 H Bridge motor controller

Committer:
AjK
Date:
Tue Jul 05 09:27:36 2011 +0000
Revision:
1:e6f43157c7db
Parent:
0:e2433ca2ce59
Child:
2:c5fbe0cb8a97
0.3 Beta (made example1.h use sin() rather than saw ramp)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:e2433ca2ce59 1
AjK 0:e2433ca2ce59 2 #include "mbed.h"
AjK 0:e2433ca2ce59 3 #include "SimpleTLE5206.h"
AjK 0:e2433ca2ce59 4
AjK 0:e2433ca2ce59 5 Serial pc(USBTX, USBRX);
AjK 0:e2433ca2ce59 6
AjK 0:e2433ca2ce59 7 /* NOTE! The SimpleTLE5206 library supports the TLE5206 in
AjK 0:e2433ca2ce59 8 * Mode 2 Sign/Magnitude Control using two PWM outputs to
AjK 0:e2433ca2ce59 9 * control speed and direction.
AjK 0:e2433ca2ce59 10 *
AjK 0:e2433ca2ce59 11 * Pins that be be used are p21, p22, p23, p24, p25 and/or p26
AjK 0:e2433ca2ce59 12 * in pairs. So the library supports upto 3 TLE5206 devices/motors.
AjK 0:e2433ca2ce59 13 *
AjK 0:e2433ca2ce59 14 * All PWM outputs use a common duty cycle which defaults to 100Hz/10ms.
AjK 0:e2433ca2ce59 15 * There is no way to have differing duty cycles for different output
AjK 0:e2433ca2ce59 16 * pin pairs as the hardware only supports a common duty cycle in single
AjK 0:e2433ca2ce59 17 * ended mode. It may be possible to refactor the library to use a different
AjK 0:e2433ca2ce59 18 * duty cycle system (paired outputs). But single/common duty cycle was the
AjK 0:e2433ca2ce59 19 * easiest and simplest way to get the library done in a short period of time.
AjK 0:e2433ca2ce59 20 *
AjK 0:e2433ca2ce59 21 * Additionally you can use LED1, LED2, LED3 and.or LED4 as mimics.
AjK 0:e2433ca2ce59 22 * However, if using:-
AjK 0:e2433ca2ce59 23 * LED1 you cannot use p26 to drive an in to TLE5206
AjK 0:e2433ca2ce59 24 * LED2 you cannot use p25 to drive an in to TLE5206
AjK 0:e2433ca2ce59 25 * LED3 you cannot use p24 to drive an in to TLE5206
AjK 0:e2433ca2ce59 26 * LED4 you cannot use p23 to drive an in to TLE5206
AjK 0:e2433ca2ce59 27 *
AjK 0:e2433ca2ce59 28 * The function SimpleTLE5206::setSpeed() takes a single arg, a double,
AjK 0:e2433ca2ce59 29 * and should be in the range +1.0 to -1.0 where +1.0 is full speed in
AjK 0:e2433ca2ce59 30 * a CW direction, -1.0 is full speed in a CCW direction and 0 is stopped.
AjK 0:e2433ca2ce59 31 */
AjK 0:e2433ca2ce59 32
AjK 0:e2433ca2ce59 33 // Create a motor "A" driven by a TLE5206 on pins 21 and 22.
AjK 0:e2433ca2ce59 34 SimpleTLE5206Output Ain1(p21); // TLE5206 In1 is connected to p21
AjK 0:e2433ca2ce59 35 SimpleTLE5206Output Ain2(p22); // TLE5206 In2 is connected to p22
AjK 0:e2433ca2ce59 36 SimpleTLE5206 motorA(&Ain1, &Ain2); // Create the TLE5206 controller using these pins.
AjK 0:e2433ca2ce59 37
AjK 0:e2433ca2ce59 38 // Create a motor "B" driven by a TLE5206 but on LEDs as a mimic.
AjK 0:e2433ca2ce59 39 SimpleTLE5206Output Bin1(LED3); // TLE5206 In1 is connected to LED3
AjK 0:e2433ca2ce59 40 SimpleTLE5206Output Bin2(LED4); // TLE5206 In2 is connected to LED4
AjK 0:e2433ca2ce59 41 SimpleTLE5206 motorB(&Bin1, &Bin2); // Create the TLE5206 controller using these pins.
AjK 0:e2433ca2ce59 42
AjK 0:e2433ca2ce59 43 DigitalOut myled(LED1);
AjK 0:e2433ca2ce59 44
AjK 0:e2433ca2ce59 45 Ticker myLedFlasher;
AjK 0:e2433ca2ce59 46
AjK 0:e2433ca2ce59 47 void myLedFlasherCallback(void) {
AjK 0:e2433ca2ce59 48 myled = !myled;
AjK 0:e2433ca2ce59 49 }
AjK 0:e2433ca2ce59 50
AjK 1:e6f43157c7db 51 #define PI 3.14159265
AjK 1:e6f43157c7db 52
AjK 0:e2433ca2ce59 53 int main() {
AjK 0:e2433ca2ce59 54 double speed;
AjK 0:e2433ca2ce59 55
AjK 0:e2433ca2ce59 56 pc.baud(115200);
AjK 0:e2433ca2ce59 57
AjK 0:e2433ca2ce59 58 // Just flashes LED1 similar to a normal initial Mbed program.
AjK 0:e2433ca2ce59 59 myLedFlasher.attach(myLedFlasherCallback, 0.2);
AjK 0:e2433ca2ce59 60
AjK 1:e6f43157c7db 61 motorA.setSpeed(0);
AjK 1:e6f43157c7db 62 motorB.setSpeed(0);
AjK 1:e6f43157c7db 63
AjK 0:e2433ca2ce59 64 while(1) {
AjK 1:e6f43157c7db 65 for (double i = 0; i < 360; i++) {
AjK 1:e6f43157c7db 66 speed = sin(i * PI / 180.0);
AjK 0:e2433ca2ce59 67 motorA.setSpeed(speed);
AjK 0:e2433ca2ce59 68 motorB.setSpeed(speed);
AjK 0:e2433ca2ce59 69 wait(0.05);
AjK 0:e2433ca2ce59 70 }
AjK 0:e2433ca2ce59 71 }
AjK 0:e2433ca2ce59 72 }
AjK 0:e2433ca2ce59 73
AjK 0:e2433ca2ce59 74