oDCMotorMT Object
An Object that controls a DC motor using a Mondo-tronics H-Bridge.
Description:
 

An oDCMotorMT 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, and optionally controls a mechanical braking device.  The H-Bridge that the oDCMotorMT Object is designed to work with has 2 drive channels with no enable.  Both the Mondo-tronics Mini and the Mondo-tronics Maxi dual H-Bridges are configured in this way.

The oDCMotorMT 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 value which can be configured to have a range of 0 to 255 or -128 to +127.

When the speed value is configured with a range of -128 to +127, the speed value is then also used to specify 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.  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.

When the speed value is configured with a range of 0 to 255, the motor turn in a direction specified by a direction value at the rate specified by the speed value. When this value is 0, the motor is at free-spinning rest.  When the value is 1 to 255, the motor turns forward at the speed indicated by the value.  The higher the value, the faster the motor turns. 

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 value is used to apply brakes and when this value is set to 1, 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 maximum number of oDCMotorMT Objects that can be dimensioned in a single application program is 2, limited only be the number of PWM channels available in the OOPic which are used to control the speed of the DC Motors.

Each PWM channel's cycle rate can be set as high as 5-Mhz or as low as 312.5-Khz.

Operation:
  The oDCMotorMT Object monitors its properties, and based on their numeric values controls the direction, speed, and braking of a DC Motor by outputting control signals to a H-Bridge motor driver circuit such as the Mondo-tronics Mini and the Mondo-tronics Maxi.  To control the speed of the motor, a Pulse-Width-Modulated (PWM) clock cycle is outputted on the I/O line specified by the IOLineP property.  The direction that the motor spins is controlled by outputting a 0 or a 1 on the I/O line specified by the IOLineD property.  Whether or not the brakes are applied is controlled by by outputting a 0 or a 1 on the I/O line specified by the IOLineB property and by setting both the PWM and Direction I/O lines to 1.  The Mondo-tronics H-Bridge monitors the state of the PWM and the Direction control lines and controls the DC motor accordingly.  The Brake control line can be used to activate mechanical braking.

In normal operation, a 0 in the Value property will cause the PWM line and the Direction line to output 0 Volts, causing the motor to be at a free-spinning full stop.  If the Value property is greater than 0, then the Pulse-Width of the PWM output is set to correspond to the Value property * 2, the Direction property is set to 0 and the I/O line specified by the IOLineD property is set to 0 Volts. This will cause the DC Motor to go forward at a speed specified by the Value property.  The higher the number (up to 127), the faster the motor will turn.  If the Value property is less than 0, then the Pulse-Width of the PWM output is set to correspond to 256 - the absolute value of the Value property * 2, the Direction property is set to 1 and the I/O line specified by the IOLineD property is set to 5 Volts. This will cause the DC Motor to go backwards at a speed specified by the Value property.  The lower the number (down to negative 128), the faster the motor will turn in reverse.

If the Unsigned property is set to 1, then the operation is modified so that the application program is expected to set the Direction property, and the Value property is always expected to be a positive value. 

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

When the Brake property is set to 1, the I/O line specified by the IOLineB property is set to the value specified by the InvertOutB property, the I/O line specified by the IOLineD property is set to 5 Volts and the PWM output is set to 5 Volts.  This will cause the Motor to generate power back into itself, effectively driving the motor back the other way which causes the motor to come to an abrupt stop.  The I/O line specified by the IOLineB property can optionally be connected to a mechanical braking system to physically stop the motor.

The combination of the Period and the PreScale properties specify the PWM clock cycle's frequency. The PreScale property specifies how many times a 5-Mhz clock is divided. This scaled down 5-Mhz clock is used to increment a Period-Duration Counter. A full PWM clock cycle has been reached when the Period-Duration Counter reaches the value specified by the Period property. The PreScale property can be set to divide the 5-Mhz clock by 1, 4, or 16, giving frequencies of 5-Mhz, 1.25-Mhz, and 312.5-Khz. The Period property can be set to any value from 1 to 255. This results in 765 possible frequencies.

The Speed of the DC Motor is controlled by the Pulse-Width determined by the Value property. At the beginning of each PWM clock cycle, the I/O Line specified by the IOLineP property is set to 5 Volts. Each time the Period-Duration Counter is incremented it is compared to the value specified by the Value property. When the Period-Duration Counter reaches the value specified by the Value property the I/O Line is set to 0-Volts.

The Period property also dictates the resolution of the PWM pulse. If the Period property is set to 255 then the Value property's range is 0 - 255. Likewise, if the Period property is set to 10, then the Value property's effective range is 0 - 10, because any value above 10 will never be reached by the Period-Duration Counter.

The Operate property specifies if the High going PWM pulse is generated. When the Operate property is set to 1 the oPWM Object starts generating PWM pulses. When the Operate property is set to 0 the PWM pulses are discontinued and the I/O Line specified by the IOLineP is set to 0-Volts. If a current PWM pulse was in progress it is cut short and the I/O line is immediately set to 0-Volts.  The Direction and Brake lines are not changed when Operate is set to 0.

Remarks:
  Two physical Pulse-Width-Modulators are implemented within the OOPic.

The oDCMotorMT Object is functionally identical to the oDCMotor object with the exception of how the PWM output works.

Storage size & Availability:
 

The following table lists the size and availability of the oDCMotorMT Object:

ObjectSizeFirmware VersionCompiler Version
oDCMotorMT 5 Bytes B.2.0 5.00
Properties:
 

The following table lists the Properties of the oDCMotorMT Object:

Property Description
Address

Returns a pointer to the address of the oDCMotorMT Object instance.

Data-Type: Address, Read-Only

Data-Range: 0 - 127

Brake

A value that specifies if the brake output is on.

When the Brake property is set to 1 the brake output goes active, the PWM output is set to 5 Volts and the Direction output is set to 5 Volts. 

The active output level of the Brake output depends on the value of the InvertOutB property.

Data-Type: Bit, Flag

Data-Range: 0 - 1

BrakeInvertOutBBrake Output
00 0 Volts
01 5 Volts
10 5 Volts
11 0 Volts
Direction

Specifies the direction that the motor will turn or indicates the direction that the motor is turning.

If the Unsigned property is 0 the direction output and the direction property will be set or cleared depending on if the Value property is negative or not.
If the Unsigned property is 1 the direction output will be set to the direction property.

The active output level of the Direction output depends on the value of the InvertOutD property.

Data-Type: Bit, Flag

Data-Range: 0 - 1

DirectionInvertOutDDirection Output
00 0 Volts
01 5 Volts
10 5 Volts
11 0 Volts
InvertOutB

A value that specifies if the brake output is inverted.

The InvertOutB property specifies what logic level the brake output gets set to when the brake output goes active.

Data-Type: Bit

Data-Range: 0 - 1

InvertOutBBrakeBrake Output
00 0 Volts
01 5 Volts
10 5 Volts
11 0 Volts
InvertOutD

A value that specifies if the direction output is inverted.

The InvertOutD property specifies what logic level the direction output gets set to when the direction output is set.

Data-Type: Bit, Flag

Data-Range: 0 - 1

InvertOutDDirectionDirection Output
00 0 Volts
01 5 Volts
10 5 Volts
11 0 Volts
IOLineB

A value that specifies the physical I/O Line to use for the brake output.

Data-Type: Byte

Data-Range: 0 - 31

IOLineD

A value that specifies the physical I/O Line to use for the direction output.

Data-Type: Byte

Data-Range: 0 - 31

IOLineP

A value that specifies the physical I/O Line to use for the PWM output.

Data-Type: Bit

Data-Range: 0 - 1

The following table list the values of the IOLineP Property.
IOLinePConstantDescription
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.

Operate

A value that specifies if the motor operates.

Data-Type: Bit, Flag

Data-Range: 0 - 1

Period

A value that specifies the frequency of the PWM cycle.

Data-Type: Byte

Data-Range: 0 - 255

PreScale

A value that specifies the base frequency of the Period property.

Data-Type: Nibble

Data-Range: 0 - 3

The following table list the values of the PreScale Property.
PreScaleDescription
0

The base frequency is 5-Mhz

1

The base frequency of 5-Mhz is divided by 4 to get 1.25Mhz

2

The base frequency of 5-Mhz is divided by 16 to get 312 500hz

3

The base frequency of 5-Mhz is divided by 16 to get 312 500hz (same as 2)

Unsigned

A value that specifies if the Value property is signed or unsigned.

Data-Type: Bit

Data-Range: 0 - 1

UnsignedValue Range
0 -127 to +127
1 0 to 255
Value

A value that specifies how fast and optionally in what direction the motor turns.

Data-Type: Byte, Default

Data-Range: 0 to 255 or -128 to +127

ValueUnsignedPWM OutputDirection
1270 Set to 255 (full-speed) Set to 0
1 to 1260 Set to Value * 2 Set to 0
00 Set to 0 (off) Set to 0
-1 to -1270 Set to abs(Value) * 2  Set to 1
-1280 Set to 255 (full-speed) Set to 1
01 Set to 0 (full-stop) unchanged
1 to 2541 Set to Value unchanged
2551 Set to 255 (full-speed) unchanged
Connections:
  The Mondo-tronics H-Bridges use 2 power lines and each half uses 2 I/O lines. 
IOLineD can be any I/O line of the OOPic's 31 I/O lines.  The IOLineP can be I/O line 17 or 18. 
The Mondo-tronics Mini H-Bridge requires 5 volts with enough current to dive the attached DC motor.
The Mondo-tronics Maxi H-Bridge requires 10 volts with enough current to dive the attached DC motor.
Mondo-tronics MAXI H-Bridge Driver and DC Motor.
Wiring for first of two possible motors.
PinNameDescriptionI/O NameOOPic
I/O Line
1 G Power Ground   Gnd
2 B1 Motor B Drive 1 IOLineP 17 or 18
3 A1 Motor A Drive 1 IOLineP 17 or 18
4 + Power Voltage   + 5 Volts
5 A2 Motor A Drive 2 IOLineD Any*
6 B2 Motor B Drive 2 IOLineD Any*
7 G Power Ground   Gnd
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.

Example:
  In the following example, the oDCMotorMT Object is used.
' This program ramps a DC Motor's speed
' up and down / forwards and backwards.

Dim A As New oDCMotorMT 

Sub Main() 
  A.IOLineP = 17
  A.IOLineD = 24
  A.Operate = cvTrue
  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
See Also:
 

oDCMotor - An Object that controls a DC motor using a LMD18200T H-Bridge.
oDCMotor2
- An Object that controls a DC motor using a L293 H-Bridge.
oDCMotorWZ - An Object that controls a DC motor using a Wirz 203 H-Bridge.
oNavCon
- An Object that provides navigation control for two Motor Objects.
oNavConIE - An Object that provides navigation control for two Motor Objects using two quadrant encoders.