Está en la página 1de 5

oDCMotor Object

http://www.oopic.com/odcmotor.htm

oDCMotor Object
Description Operation Properties Methods Description: An oDCMotor Object is a Hardware Object that controls the direction, speed, and braking of a DC Motor. It is capable of driving a DC Motor at multiple speeds, in forward or reverse plus free spinning, active braking, and friction braking modes. The oDCMotor 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, and optionally controls a mechanical braking device. The H-Bridge that the oDCMotor Object is designed to work with is the National LMD18200T H-Bridge which has a direction, a brake and a PWM input. Examples Connections Related Version History & Bug list

Main Index Object List

How fast the motor turns and in which direction it turns is controlled by a single value with a range of -128 to +127. 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. The higher the value, the faster the motor turns. When the value is a negative number from -1 to -128, the motor turns backwards at the speed indicated by the value. The lower the number, the faster the motor turns in reverse. The physical direction that the motor will turn can be configured to: forward turns clockwise and reverse turns counter-clockwise or forward turns counter-clockwise and reverse turns clockwise. Brakes are also controlled by a single value which when activated, the speed value is ignored and the motor will quickly stop. The method used to stop the motor can be either active braking or friction braking. For friction braking, an output is provided to activate a mechanical braking device. The following table lists the size and availability of the oDCMotor Object. Object Size Description A1 A2 B1 B2 C1 x x x

oDCMotor 5 Bytes Controls a DC motor that is driven by an LMD18200 H-Bridge driver. Operation:

The oDCMotor 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 oDCMotor object is initialized, it configures the oHBridgeH object to use the LMD18200T H-Bridge by setting the oHBridgeH object's properties. It then sets the oDCMotor 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 LMD18200 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 LMD18200 H-Bridge is set to drive the motor. When the Operate property is set to 0 the LMD18200 H-Bridge is reconfigured and the motor stops. The HBridge property is an instance of the oHBridgeH object which is created when the oDCMotor object is. The oDCMotor object configures the oHBridgeH object in such a way that it will provide the proper I/O control of the LMD18200 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.

1 of 5

08/09/2008 18:28

oDCMotor Object

http://www.oopic.com/odcmotor.htm

Properties: The following table lists the properties of the oDCMotor Object: Property Description Speed A value that specifies how fast and in what direction the motor turns. Object Class: oPower Data Type: Numeric Value Range: -128 to +127 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. Speed -128 -96 -64 -32 0 32 64 96 127 IOLineP Description Full Reverse Half Reverse Stopped Half Forward Full Forward A.Speed = 64 A.Speed.SetFullForward A.Speed.Stop A.Speed++ A.Speed.Value.Dec 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:

A value that specifies which PWM I/O Line is connected to the motor driver's PWM line. Object Class: oIOLineP Data Type: Numeric IOLineP Description 0 1 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. 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. Value Range: 0 - 1 Default Value: 0

IOLineD

A value that specifies which I/O Line is connected to the motor driver's direction line. Object Class: oIOLine Data Type: Numeric Value Range: 0 - 31 Default Value: 0

Some I/O Lines have special purposes. Be sure to see oIOLine help file for details. IOLineB A value that specifies which I/O Line is connected to the motor driver's brake line. Object Class: oIOLine Data Type: Numeric Value Range: 0 - 31 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 Data Type: Numeric Invert Description 0 1 Brake Motor turns in the direction specified by the Speed property. Motor turns in the direction opposite the one specified by the Speed property. Value Range: 0 - 1 Default Value: 0

A value that selects if the brake is on or off. Object Class: oSelect0to1L Data Type: Numeric Value Range: 0 - 1 Default Value: 0

When the Brake property is set to 1, the I/O line specified by the IOLineB property is set to 5 volts and IOLineP is set to 5 Volts. When the LMD18200 H-Bridge is being used for the motor's brakes, 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. Brake Brake Output 0 1 Brakes are off. Brakes are on.

2 of 5

08/09/2008 18:28

oDCMotor Object

http://www.oopic.com/odcmotor.htm

Operate

A value that selects if the motor is on or off. Object Class: oOperate Data Type: Numeric Operate Constant Description 0 1 cvOff cvOn The motor is off. The motor is on. Value Range: 0 - 1 Default Value: 0

Direction A value that indicates the direction that the motor is turning. Object Class: oLogic Data Type: Numeric Value Range: 0 - 1 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 Data Type: Numeric Value Range: Default Value: 0

When the oDCMotor object is created, it configures its oHBridgeH object to use LMD18200T H-Bridge by setting its properties to: HBridge.PWM.Period = 254 The property HBridge.Mode can be set to control the state that the PWM Line is set to when the motor is braking. Other 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 Data Type: Pointer (Read Only) Methods: The following table lists the Properties of the oDCMotor Object: Method Description Init A method that initializes the oDCMotor object. oMethod When the oDCMotor object is initialized, it configures the oHBridgeH object to use LMD18200T H-Bridge by setting the oHBridgeH object's properties. It then sets the oDCMotor object's properties as specified in the argument list to the Init method in this order: 1. 2. 3. 4. 5. 6. 7. IOLineP IOLineD IOLineB Invert Brake Speed Operate Value Range: 0 - 127 Default Value: Address of Object

Examples: A.Init(18,14,15,1,1,0,1) A As oDCMotor(17,27,25,,,64,1) Connections: The LMD18200T H-Bridge uses 3 I/O lines. IOLineB and IOLineD can be any 2 I/O lines of the ooPIC's 31 I/O lines. The IOLineP can be I/O line 17 or 18. The LMD18200T H-Bridge requires 12 volts or more to operate properly and a 12+ Volt power supply that is capable of handling enough current to dive the attached DC motor is required. 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. 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. LMD18200T H-Bridge Driver and DC Motor.

3 of 5

08/09/2008 18:28

oDCMotor Object

http://www.oopic.com/odcmotor.htm

Pin Name 1 2 3 4 5 6 7 8 9 10 11 Examples: Bootstrap Output 1 Direction In Brake In PWM In VS Power Ground Current Sense Out Thermal Flag Out Output 2 Bootstrap

Description Connect to .01 Cap Output to DC Motor Reverses the direction of the motor. Quickly stops motor. Controls the speed of the motor. Power supply for the motor. Signal and Power Ground Outputs an analog signal that indicates the current that the motor is using. Outputs a signal that indicates the H-Bridge is too hot. Output to DC Motor Connect to .01 Cap

I/O Name

ooPIC I/O Line

IOLineD IOLineB IOLineP

Any* Any* 17 or 18

Gnd

In the following examples, the oDCMotor object is used. Visual Basic Syntax C and Java Syntax

' This program ramps a DC Motor's speed // This program ramps a DC Motor's speed ' up and down / forwards and backwards. // up and down / forwards and backwards. Dim A As New oDCMotor Sub Main() A.IOLineP = 17 A.IOLineD = 27 A.IOLineB = 25 A.Brake = cvOff A.Operate = cvOn Do For A.Speed = -100 To 100 ooPIC.Delay = 2 Next A.Speed For A.Speed = 100 To -100 Step -1 ooPIC.Delay = 2 Next A.Speed Loop End Sub Basic Syntax oDCMotor A = New oDCMotor; Void Main(Void){ A.IOLineP = 17; A.IOLineD = 27; A.IOLineB = 25; A.Brake = cvOff; A.Operate = cvOn; Do{ For(A=-100;A>100;A++){ ooPIC.Delay = 2; } For(A=100;A<-100;A--){ ooPIC.Delay = 2; } } } Initialization Parameters constructor creates with the properties to: = 17 = 27 = 25 64 = 1

' This program ramps a DC Motor's speed ' this object ' up and down / forwards and backwards. ' an oDCMotor ' initialized A Var oDCMotor ' ' A.IOLineP A.IOLineP = 17 ' A.IOLineD A.IOLineD = 27 ' A.IOLineB A.IOLineB = 25 ' A.Speed = A.Brake = cvOff ' A.Operate

4 of 5

08/09/2008 18:28

oDCMotor Object

http://www.oopic.com/odcmotor.htm

A.Operate = cvOn A As oDCMotor(17,27,25,,,64,1) 1: For A.Speed = ooPIC.Delay Next A.Speed For A.Speed = ooPIC.Delay Next A.Speed Goto 1 -100 To 100 = 2 100 To -100 Step -1 = 2 ' The folling line sets the speed to ' 127 and the direction to forward. A.Speed.SetFullForward

Related Items: The following table lists objects that use the oDCMotor Object. Object Description A1 A2 B1 B2 C1 x x x

oDCMotorMGD Controls two DC motors that are driven by a Magnevation Dual Motor driver. The following table lists objects with related functions Object oDCMotor2 oDCMotor3 Description Controls a DC motor that is driven by an L293 H-Bridge driver. Controls a DC motor that is driven by two drivers.

A1 A2 B1 B2 C1 x x x x x x x x x x x

oDCMotorMT Controls a DC motor that is driven by a Wirz 203 Motor Driver. oDCMotorWZ Controls a DC motor that is driven by a Mondo-Tronics H-Bridge driver. oNavCon An Object that provides differential steering calculations.

Version History and Bug List: Firmware Ver B1: Introduced. Bugs: No known bugs. ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.

5 of 5

08/09/2008 18:28

También podría gustarte