oDCMotor2 Object

Main Index
Object List
Back to top of pageDescription:
 An oDCMotor2 Object is a Hardware Object that uses three digital I/O lines to control the direction, speed, and braking of a DC Motor by communicating with an H-Bridge circuit which handles the voltage and current requirements of the DC Motor it is connected to. 

The oDCMotor2 Object uses three digital I/O lines to communicate with an H-Bridge circuit which handles the voltage and current requirements of the DC Motor it is connected to.  The H-Bridge that the oDCMotor2 Object is designed to work with has 2 drive inputs that have a shared enable line.  The L293 and L298 H-Bridges are configured in this way.  An optional I/O line controls a mechanical braking device. 

The oDCMotor2 Object is capable of driving a DC Motor at 255 different speeds, in forward or reverse plus free spinning, active braking, and friction braking modes.  The speed at which the motor spins is specified by a single signed value which has a range of -128 to +127.  This signed value also specifies the direction that the motor turns.  When this value is 0, the motor is at free-spinning rest.  When the value is a positive number from 1 to 127, the motor turns forward at the speed indicated by the value.   When the value is a negative number from -1 to -128, the motor turns backwards at the speed indicated by the value. 

The physical direction that the motor will turn can be set to:  forward turns clockwise and reverse turns counter-clockwise  or  forward turns counter-clockwise and reverse turns clockwise.

A brake property can be used to apply brakes which when set, the speed value is ignored and the motor will quickly stop. 

 The following table lists the size and availability of the oDCMotor2 Object.
 ObjectSizeDescriptionA1A2B1B2C1
oDCMotor25 BytesControls a DC motor that is driven by an L293 H-Bridge driver.xx
Back to top of pageOperation:
 The oDCMotor2 Object monitors the Speed and the Brake properties, and based on their numeric values controls the power, polarity, and braking properties of a oHBridgeH object which in turn control a physical H-Bridge motor driver circuit connected to the motor.  

When the oDCMotor2 object is initialized, it configures the oHBridgeH object to use the L293D H-Bridge by setting the oHBridgeH object's properties. It then sets the oDCMotor2 object's properties as specified in the arguments to the Init method.

The Speed property controls the speed of the motor.  When operating, a 0 in the Speed property will cause the motor to be at a full stop. If the Speed property is greater than 0, then the DC Motor will go forward at a speed specified by the Speed property. The higher the number (up to 127), the faster the motor will turn. If the Speed property is less than 0, then the DC Motor will go backwards at a speed specified by the Speed property. The lower the number (down to negative 128), the faster the motor will turn in reverse.

The actual direction that the DC Motor spins when going in the "forward" direction can be reversed by setting the Invert property.

When the Brake property is set to 1, the L293D H-Bridge is set in such a way that the motor to generate power back into itself, effectively driving itself back the other way which causes it to come to an abrupt stop without the need for mechanical braking.

The Operate property specifies if the motor is on or off.  When the Operate property is set to 1 the L293D H-Bridge is set to drive the motor. When the Operate property is set to 0 the L293D H-Bridge is reconfigured and the motor stops.

The HBridge property is an instance of the oHBridgeH object which is created when the oDCMotor2 object is.  The oDCMotor2 object configures the oHBridgeH object in such a way that it will provide the proper I/O control of the L293D H-Bridge that is connected to the DC Motor.  Attributes of the motor's operation can be adjusted by directly manipulating the oHBridgeH object. Note that doing so may change the way the motor behaves to something different than the way described in this document.  (see oHBridgeH object for more detail)

The maximum number of oDCMotor objects that can be dimensioned in a single application program is 2, limited only be the number of PWM channels available in the ooPIC.

Back to top of pageProperties:
 

The following table lists the properties of the oDCMotor2 Object:

Property

Description

Speed
A value that specifies how fast and in what direction the motor turns.
Object Class: oPower Value Range:-128 to +127
Data Type: Numeric Default Value: 0
When operating, a 0 in the Speed property will cause the motor to be at a full stop. When the Speed property is greater than 0, the motor will go forward at a speed specified by the magnitude of the Speed property. The higher the number (up to 127), the faster the motor will turn. If the Speed property is less than 0, then the motor to go backwards at a speed specified by the magnitude of the Speed property. The lower the number (down to negative 128), the faster the motor will turn in reverse.
SpeedDescription
-128Full Reverse
-96 
-64Half Reverse
-32 
0Stopped
32 
64Half Forward
96 
127Full Forward
The Speed property is an oPower object which has properties and methods such as SetFullForward and Stop that can also be used to control the speed of the motor.  Examples: 

 

IOLineP
A value that specifies which PWM I/O Line is connected to the motor driver's Enable line.
Object Class: oIOLineP Value Range: 0 - 1
Data Type: Numeric Default Value: 0
IOLinePDescription
0

The PWM signal is outputted on I/O Line 18. 
18 can be assigned to IOLineP in place of 0 but it will read back as 0.

1

The PWM signal is outputted on I/O Line 17. 
17 can be assigned to IOLineP in place of 1 but it will read back as 1.

IOLine1
A value that specifies which I/O Line is connected to the motor driver's first drive line.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
IOLine2
A value that specifies which I/O Line is connected to the motor driver's second drive line.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
Invert
A value that selects if the physical direction the motor turns is inverted.
Object Class: oSelect0to1L Value Range: 0 - 1
Data Type: Numeric Default Value: 0
InvertDescription
0Motor turns in the direction specified by the Speed property.
1Motor turns in the direction opposite the one specified by the Speed property.
Brake
A value that selects if the brake is on or off.
Object Class: oSelect0to1L Value Range: 0 - 1
Data Type: Numeric Default Value: 0
When the Brake property is set to 1, the I/O lines specified by the IOLineA and IOLineB properties are set to 0 volts and IOLineP is set to 5 Volts.  Setting the Brake property will cause the motor to generate power back into itself, effectively driving the it back the other way which causes it to come to an abrupt stop without the need for mechanical braking.
BrakeBrake Output
0Brakes are off.
1Brakes are on.
Operate
A value that selects if the motor is on or off.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe motor is off.
1cvOnThe motor is on.
Direction
A value that indicates the direction that the motor is turning.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
The Direction property will be set or cleared depending on if the Speed property is negative or not.
HBridge
The I/O function object used to control the Motor Driver.
Object Class: oHBridgeH Value Range: 
Data Type: Numeric Default Value: 0
When the oDCMotor2 object is created, it configures its oHBridgeH object to use L293D H-Bridge by setting its properties to:
  • HBridge.PWM.Period = 254
  • HBridge.Mode = 1
  • HBridge.Option = 1

Attributes of the motor's operation can be adjusted by directly manipulating the oHBridgeH object, but note that doing so may change the way the motor behaves to something different than the way described in this document.

Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of pageExamples:
 In the following example, the oDCMotor2 Object is used.
' This program ramps a DC Motor's speed
' up and down / forwards and backwards.

Dim A As New oDCMotor2

Sub Main() 
  A.IOLineP = 17
  A.IOLine1 = 27
  A.IOLine2 = 25
  A.Operate = 1
  A.Brake = cvOff
  Do
    For A = -100 To 100
      ooPIC.Delay = 2
    Next A
    For A = 100 To -100 step -1
      ooPIC.Delay = 2
    Next A
  Loop 
End Sub
Back to top of pageConnections:
 The L293D H-Bridge is a dual H-Bridge and each one of its H-Bridges is a set of 2 push-pull drivers that use a total of 3 I/O lines.  IOLine1 and IOLine2 can be any 2 I/O lines of the ooPIC's 31 I/O lines.  IOLineP can be I/O line 17 or 18.  The L293D H-Bridge requires a power supply that is capable of handling enough current to dive the attached DC motor.

Caution: Do NOT connect the outputs of the ooPIC directly to a DC Motor. The TTL circuitry of the ooPIC is not designed to drive the power requirements of a DC Motor.  Doing so can potentially damage the ooPIC's TTL outputs.

L293D H-Bridge Driver and DC Motor.
L293D
Pin
NameDescriptionFirst set
I/O Name
Second set
I/O Name
ooPIC
I/O Line
1Enable 1Output Enable for Outputs 1 and 2IOLineP 17 or 18
2Input 1Control Line for Output 1IOLine1 Any*
3Output 1Output 1   
4GndGndGnd Gnd
5GndGndGnd Gnd
6Output 2Output 2   
7Input 2Control Line for Output 2IOLine2 Any*
8VsSupply Voltage of up to 36   
9Enable 2Output Enable for Outputs 3 and 4 IOLineP17 or 18
10Input 3Control Line for Output 3 IOLine1Any*
11Output 3Output 3   
12GndGnd GndGnd
13GndGnd GndGnd
14Output 4Output 4   
15Input 4Control Line for Output 4 IOLine2Any*
16VssLogic Supply Voltage volts   
Caution:
 Do NOT connect the outputs of the ooPIC directly to a DC Motor. The TTL circuitry of the ooPIC is not designed to drive the power requirements of a DC Motor.  Doing so can potentially damage the ooPIC's TTL outputs.

*Caution: I/O lines 16 through 23 are used for special purposes.  Be sure not to specify any of these I/O lines if these special functions are in use.

Back to top of page Related Items:
 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oDCMotorControls a DC motor that is driven by an LMD18200 H-Bridge driver.xxx
oDCMotor3Controls a DC motor that is driven by two drivers.xx
oDCMotorMTControls a DC motor that is driven by a Wirz 203 Motor Driver.xx
oDCMotorWZControls a DC motor that is driven by a Mondo-Tronics H-Bridge driver.xx
oNavConAn Object that provides differential steering calculations.xxx
Back to top of page Version History and Bug List:
 Firmware Ver B2: Introduced.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.