FANDOM


Line 1: Line 1:
==Schematic==
+
<span style="font-size:20px;">Schematic</span>
 
[[File:H-bridgeL293D.png|thumb|left|Schematic with connectors.]]
 
[[File:H-bridgeL293D.png|thumb|left|Schematic with connectors.]]
 
The module utilizes LM293D chip. Its a dual full bridge in one DIP package. 
 
The module utilizes LM293D chip. Its a dual full bridge in one DIP package. 
Line 136: Line 136:
 
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
 
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
   
  switch(divisor) {
+
switch(divisor) {
   
    case 1: mode = 0x01; break;
+
  case 1: mode = 0x01; break;
   
    case 8: mode = 0x02; break;
+
  case 8: mode = 0x02; break;
   
    case 64: mode = 0x03; break;
+
  case 64: mode = 0x03; break;
   
    case 256: mode = 0x04; break;
+
  case 256: mode = 0x04; break;
   
    case 1024: mode = 0x05; break;
+
  case 1024: mode = 0x05; break;
   
    default: return;
+
  default: return;
   
  }
+
}
   
  if(pin == 5 || pin == 6) {
+
if(pin == 5 || pin == 6) {
   
    TCCR0B = TCCR0B & 0b11111000 | mode;
+
  TCCR0B = TCCR0B & 0b11111000 | mode;
   
  } else {
+
} else {
   
    TCCR1B = TCCR1B & 0b11111000 | mode;
+
  TCCR1B = TCCR1B & 0b11111000 | mode;
   
  }
+
}
   
 
} else if(pin == 3 || pin == 11) {
 
} else if(pin == 3 || pin == 11) {
   
  switch(divisor) {
+
switch(divisor) {
   
    case 1: mode = 0x01; break;
+
  case 1: mode = 0x01; break;
   
    case 8: mode = 0x02; break;
+
  case 8: mode = 0x02; break;
   
    case 32: mode = 0x03; break;
+
  case 32: mode = 0x03; break;
   
    case 64: mode = 0x04; break;
+
  case 64: mode = 0x04; break;
   
    case 128: mode = 0x05; break;
+
  case 128: mode = 0x05; break;
   
    case 256: mode = 0x06; break;
+
  case 256: mode = 0x06; break;
   
    case 1024: mode = 0x7; break;
+
  case 1024: mode = 0x7; break;
   
    default: return;
+
  default: return;
   
  }
+
}
   
  TCCR2B = TCCR2B & 0b11111000 | mode;
+
TCCR2B = TCCR2B & 0b11111000 | mode;
   
 
}
 
}

Revision as of 07:42, February 26, 2014

Schematic

H-bridgeL293D

Schematic with connectors.

The module utilizes LM293D chip. Its a dual full bridge in one DIP package. 

Datasheet avaiable here




Pinout

  1. GND
  2. +12V
  3. N/C
  4. PWM A (~1kHz; 5V TTL)
  5. PWM B (~1kHz; 5V TTL)
  6. Encoder (feedback) motor A - freq. varying PWM with 50% D.C.
  7. Encoder (feedback) motor B - freq. varying PWM with 50% D.C.
  8. Direction A (High/Low)
  9. Direction B (High/Low)
  10. +5V

Theory of operation

Enable pin is hooked up to uC PWM output. Direction pin from uC controls the direction. It's hooked up to the inverter therefore one motor can be only spinning e.g. there is no brake possibility. Braking is done by decreasing PWM duty cycle down to zero. How it works still needs to be tested.

Testing

IMG 20140225 115700

Test setup.

Testing was done using Arduino as a controller. Button was used to change direction. Multiturn potmeter was used to control PWM duty cycle.





Arduino code:

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

const int analogOutPin = 3; // Analog output pin that the LED is attached to

const int buttonPin = 2;   

const int dirPin =  13;


int sensorValue = 0;        // value read from the pot

int outputValue = 0;        // value output to the PWM (analog out)


void setup() {

// initialize serial communications at 9600 bps:

Serial.begin(9600); 

setPwmFrequency(3,32); //~1kHz

pinMode(buttonPin, INPUT); 

pinMode(dirPin, OUTPUT); 

}


void loop() {

// read the analog in value:

sensorValue = analogRead(analogInPin);            

// map it to the range of the analog out:

outputValue = map(sensorValue, 0, 1023, 0, 255);  

// change the analog out value:

analogWrite(analogOutPin, outputValue);           


// print the results to the serial monitor:

Serial.print("sensor = " );                       

Serial.print(sensorValue);      

Serial.print("\t output = ");      

Serial.println(outputValue);   


// wait 2 milliseconds before the next loop

// for the analog-to-digital converter to settle

// after the last reading:

delay(2);   

if(digitalRead(buttonPin)==HIGH)

{

digitalWrite(dirPin,HIGH);

}

else

{

digitalWrite(dirPin,LOW);

}


}


void setPwmFrequency(int pin, int divisor) {

byte mode;

if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {

switch(divisor) {

  case 1: mode = 0x01; break;

  case 8: mode = 0x02; break;

  case 64: mode = 0x03; break;

  case 256: mode = 0x04; break;

  case 1024: mode = 0x05; break;

  default: return;

}

if(pin == 5 || pin == 6) {

  TCCR0B = TCCR0B & 0b11111000 | mode;

} else {

  TCCR1B = TCCR1B & 0b11111000 | mode;

}

} else if(pin == 3 || pin == 11) {

switch(divisor) {

  case 1: mode = 0x01; break;

  case 8: mode = 0x02; break;

  case 32: mode = 0x03; break;

  case 64: mode = 0x04; break;

  case 128: mode = 0x05; break;

  case 256: mode = 0x06; break;

  case 1024: mode = 0x7; break;

  default: return;

}

TCCR2B = TCCR2B & 0b11111000 | mode;

}

}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.