Tripple Controller for the TLE5206 H Bridge motor controller

inc/example1.h

Committer:
AjK
Date:
2011-07-05
Revision:
1:e6f43157c7db
Parent:
0:e2433ca2ce59
Child:
2:c5fbe0cb8a97

File content as of revision 1:e6f43157c7db:


#include "mbed.h"
#include "SimpleTLE5206.h"

Serial pc(USBTX, USBRX);

/* NOTE! The SimpleTLE5206 library supports the TLE5206 in 
 * Mode 2 Sign/Magnitude Control using two PWM outputs to
 * control speed and direction. 
 *
 * Pins that be be used are p21, p22, p23, p24, p25 and/or p26
 * in pairs. So the library supports upto 3 TLE5206 devices/motors.
 *
 * All PWM outputs use a common duty cycle which defaults to 100Hz/10ms.
 * There is no way to have differing duty cycles for different output
 * pin pairs as the hardware only supports a common duty cycle in single
 * ended mode. It may be possible to refactor the library to use a different
 * duty cycle system (paired outputs). But single/common duty cycle was the
 * easiest and simplest way to get the library done in a short period of time.
 *
 * Additionally you can use LED1, LED2, LED3 and.or LED4 as mimics.
 * However, if using:-
 *  LED1 you cannot use p26 to drive an in to TLE5206
 *  LED2 you cannot use p25 to drive an in to TLE5206
 *  LED3 you cannot use p24 to drive an in to TLE5206
 *  LED4 you cannot use p23 to drive an in to TLE5206
 *
 * The function SimpleTLE5206::setSpeed() takes a single arg, a double,
 * and should be in the range +1.0 to -1.0 where +1.0 is full speed in
 * a CW direction, -1.0 is full speed in a CCW direction and 0 is stopped.
 */

// Create a motor "A" driven by a TLE5206 on pins 21 and 22.
SimpleTLE5206Output Ain1(p21);      // TLE5206 In1 is connected to p21
SimpleTLE5206Output Ain2(p22);      // TLE5206 In2 is connected to p22
SimpleTLE5206 motorA(&Ain1, &Ain2); // Create the TLE5206 controller using these pins.

// Create a motor "B" driven by a TLE5206 but on LEDs as a mimic.
SimpleTLE5206Output Bin1(LED3);     // TLE5206 In1 is connected to LED3
SimpleTLE5206Output Bin2(LED4);     // TLE5206 In2 is connected to LED4
SimpleTLE5206 motorB(&Bin1, &Bin2); // Create the TLE5206 controller using these pins.

DigitalOut myled(LED1);

Ticker myLedFlasher;

void myLedFlasherCallback(void) {
    myled = !myled;
}

#define PI 3.14159265

int main() {
    double speed;
    
    pc.baud(115200);

    // Just flashes LED1 similar to a normal initial Mbed program.
    myLedFlasher.attach(myLedFlasherCallback, 0.2);

    motorA.setSpeed(0);
    motorB.setSpeed(0);
        
    while(1) {    
        for (double i = 0; i < 360; i++) {
            speed = sin(i * PI / 180.0);
            motorA.setSpeed(speed);
            motorB.setSpeed(speed);
            wait(0.05);
        }
    }
}