oHBridgeH Object

Main Index
Object List
Back to top of pageDescription:
 

The oHBridgeH Object is an I/O Function Objects that control electronic devices called "H-Bridges".

The oHBridgeH Object is configurable so that it can handle any type of H-Bridge.  It use three digital I/O lines to communicate with the H-Bridge circuit which will then in turn handle the voltage and current requirements of the load that it is connected to. 

The oHBridgeH Object controls the power output's level and polarity with a single value.  This single value is the Power property which controls the level and polarity with a value that has a range of -128 to +127.  When this value is 0, the power is turned off.  When the value is a positive number from 1 to 127, the power is output with a positive polarity indicated by the value.  The higher the value, the higher the positive power output.  When the value is a negative number from -1 to -128, the power is output with a negative polarity.  The lower the number, the higher the negative power output.

H-Bridge Tutorial:

An H-Bridge is an electronic device consisting of four switches (solid-state or mechanical) that are closed and opened in order to reverse the power supplied to a load. The term "H-Bridges" is derived from the typical graphical representation of such a circuit which contains a large "H" with switches on each of its four legs. (See diagram)

Assuming switch S0 stays closed, when switches S1 and S4 are closed and S2 and S3 are open a positive voltage will be applied across the load. By opening S1 and S4 switches and closing S2 and S3 switches, the polarity of the voltage is reversed. (See diagrams)

In addition to the two polarity configurations, two load-shorting configurations are also possible.  When switches S1 and S3 are closed and S2 and S4 are open the two leads of the load are shorted together.  This is also the case when S2 and S4 are closed and S1 and S3 are open. (See diagrams) The load-shorting configurations are useful for DC Motors because when the leads of a DC Motor are shorted together, the motor will come to an abrupt stop.  Because of this, load-shorting configurations are typically referred to as Braking.

Warning: It is also possible to short out the power supply with an H-Bridge. This is of course something that one would not want to do.  It is however important to understand how to avoid such a situation.  When either pair of switches S1 and S2 or S3 and S4 are closed the power lines are connected together.  Therefore, it is necessary to avoid these situations.  The oHBridgeH Object automatically prevents this situation.

Several different solid-state H-Bridges exist.  Some allow control of the switches directly. Some have inputs that logically configure the switches automatically. Some H-Bridges include the S0 switch, some do not.  The H-Bridges that do include the S0 switch typically expect that this switch will be driven by a pulse modulated signal which would allow the level of the power flowing to the load to be controlled.

 The following table lists the size and availability of the oHBridgeH Object.
 ObjectSizeDescriptionA1A2B1B2C1
oHBridgeH5 BytesManages the I/O for driving an H Bridge using hardware specific I/O lines for the PWM.xxx
Back to top of pageOperation:
 When operating, the value of the Power property is used for the PWM.DutyCycle.  If the Power property is a positive number, then Polarity is set to 0 and if the Power property is a negative number then the Polarity property is set to 1. 

The Option property selects whether the drive circuit has built in logic or not.  When Option is 0, the H-Bridge is expected to take PWM, Direction and Brake inputs and internally configure its switches accordingly.  When option is 1, the H-Bridge is expected to be composed of two drivers.  Note that the Option property was added in Firmware B.2

The Mode property selects variations in the drive circuit.  When the H-Bridge has built in logic (Option 0) then Mode selects the output state of the PWM Line when the braking logic is on.  When the H-Bridge is composed of two drivers, the Mode selects whether or not the drivers have an enable line.

Together the Operate and Mode properties represent 4 selectable H-Bridge circuits.

  • Circuit 1 is designed for the LMD18200T. 
  • Circuit 2 is also designed for the LMD18200T
    The oDCMotor uses these configurations.

The difference between these two is the level the PWM line gets set to when braking.  Circuit 1 will set the PWM level to 0 and Circuit 2 will set it to 1.

  • Circuit 3 is designed for two drivers. 
    The oDCMotor3 uses this configuration.
  • Circuit 4 is designed for two drivers with enables like the L293D.
    The oDCMotor2 uses this configuration.


The following table shows the output levels for the different circuits during different power output levels.
Note that InvertOutA and InvertOutB are assumed to be 0.

SpeedDescription

IOLineP    

IOLineA

    IOLineB  

Circuit 1,2,4

Circuit 3

Circuit 1,2,3,4

Circuit 4

Circuit 1,2,3

-128Full Reverse
-96 
-64Half Reverse
-32 
0Stopped
32 
64Half Forward
96 
127Full Forward
-Brakes

In circuits 1,2 and 4 the duration of the PWM pulse is based on the absolute value of the Speed property.  In Circuit 3, the duration of the pulse is based on the raw bit value of the Speed property.

In all circuits, the state of the Polarity property is outputted to the I/O Line specified by the IOLineA property. Therefore, IOLineA outputs 0 Volts when the Power property is a positive number and 5 Volts when it is a negative number.  This can be reversed by setting the InvertOutA property. 

In the first 3 circuits, the state of the Brake property is outputted to the I/O Line specified by the IOLineB property. Therefore, IOLineB outputs 0 Volts when the Brake property is 0 and outputs 5 Volts when it is 1.  This can be reversed by setting the InvertOutB property.  In circuit 4 however, IOLineB outputs the inverse of IOLineA unless the Brake property is 1.

When the Brake property is set to 1, the H-Bridge is configured to do a load-short.  Circuits 1 and 2 expect the H-Bridge's internal logic to do this, while Circuits 3 and 4 set the outputs of IOLineA and IOLineB to the same level.  In addition to the load-short, the PWM line is configured to discontinue the high-going pulses.  In Circuit 3, the output of the PWM is set to the same level as IOLineA to accomplish load-shorting.

The Operate property specifies if the H-Bridge drives its load.  When the Operate property is set to 1 the IOLineP generates 5 Volt pulses. When the Operate property is set to 0 the pulses are discontinued and IOLineP is set to 0 Volts. If a current pulse was in progress it is cut short and the I/O line is immediately set to 0 Volts.  The state of the I/O lines specified by IOLineA and IOLineB are not changed when Operate is set to 0.

The PWM property is an instance of the oPWM Object which the H-Bridge Objects use to maintain the PWM output.  It configures the PWM's properties so that it uses the IOLine specified by the IOLineP property. Since all instances of the oPWM Object use the same two PIC PWM hardware modules, then all instances of the H-Bridge Objects will use one of the two PWM modules.  (see oPWM Object for more detail).

Back to top of pageProperties:

The following table lists the properties of the oHBridgeH Object:

Property

Description

PowerA value that specifies the polarity and level of the output power.
Object Class: oPower Value Range: -128 to +127
Data Type: Numeric Default Value: 0
When operating, a 0 in the Power property will cause the load to receive a zero power level. When the Power property is greater than 0, the load will receive positive power at a level specified by the magnitude of the Power property. The higher the number (up to 127), the greater the level. If the Power property is less than 0, the load will receive a negative power at a level specified by the magnitude of the Speed property. The lower the number (down to negative 128), the greater the reverse level.
PowerDescription
-128Full Reverse
-96 
-64Half Reverse
-32 
0Stopped
32 
64Half Forward
96 
127Full Forward

The Power property is an oPower object which has properties and methods such as SetFullForward and Stop that can also be used to control the power level. 

Examples: 

  • X.Power =  64 
  • X.Power.SetFullForward
  • X.Power.Stop
  • X.Power++
  • X.Power.Value.Dec

 

Brake
A value that selects if the braking logic is on or off.
Object Class: oSelect0to1L Value Range: 0 - 1
Data Type: Numeric Default Value: 0
BrakeBrake Output
0Braking logic is off.
1Braking logic is on.
Option
A value that selects whether the drive circuit has built in logic or not.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
Added in firmware Version B.2.0.  If firmware versions prior to B.2.0 the Option worked as 0.
This property combined with the mode property selects the H-Bridge circuit type.
OptionModeCircuitI/O Configuration

Running

Braking


0

0

1
H-Bridges that have built in logic controls. (LMD18200T)
IOLineP = PWM line.PWM(ABS(Speed)*2)0
IOLineA = Polarity line.Polarity Xor InvertOutAPolarity Xor InvertOutA
IOLineB = Braking line.Brake Xor InvertOutBBrake Xor InvertOutB
 

0

1

2
H-Bridges that have built in logic controls. (LMD18200T)
IOLineP = PWM line.PWM(ABS(Speed)*2)1
IOLineA = Polarity line.Polarity Xor InvertOutAPolarity Xor InvertOutA
IOLineB = Braking line.Brake Xor InvertOutBBrake Xor InvertOutB
 

1

0

3
H-Bridges that are two drivers without enables.
IOLineP = First drive line.PWM(Speed)1
IOLineA = Second drive line.Polarity Xor InvertOutA1
IOLineB = Braking line.Brake Xor InvertOutBBrake Xor InvertOutB
 

1

1

4
H-Bridges that are two drivers with enables. (L293D)
IOLineP = Enable line.PWM(ABS(Speed)*2)1
IOLineA = First drive line.Polarity Xor InvertOutABrake Xor InvertOutB
IOLineB = Second drive line.Not(IOLineA)Brake Xor InvertOutB
Mode
A value that selects the variation of the drive circuit selected by the Option property.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
In Firmware versions prior to B.2.0, the Mode property selected the output state of the PWM when the braking logic was on.  (Same as Option 0)
See the Option property for details.
IOLineA
A value that specifies which I/O Line is used as the first control 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.
InvertA
A value that selects if the first control signal output is inverted.
Object Class: oSelect0to1L Value Range: 0 - 1
Data Type: Numeric Default Value: 0
InvertOutADescription
0The output of IOLineA is not inverted.
1The output of IOLineA is inverted.
IOLineB
A value that specifies which I/O Line is used as the second control 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.
InvertB
A value that selects if the second control signal output is inverted.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
InvertOutBDescription
0The output of IOLineB is not inverted.
1The output of IOLineB is inverted.
IOLineP
A value that specifies which PWM I/O Line is use to output the PWM power signal.
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.

Operate
A value that selects if the H-Bridge is to drive it's load or not.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe H-Bridge is not driving it's load.
1cvOnThe H-Bridge is driving it's load.
Polarity
A value that indicates the H-Bridge's drive polarity.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
PWM
The PIC Hardware object used to output the PWM signal.
Object Class: oPWM Value Range: 0 - 255
Data Type: Numeric Default Value: 0
When the oHBridgeH object is created, it configures its oPWM Object to have a clock cycle resolution of 254 by setting its properties to:
  • PWM.Period = 254

Other attributes of the oHBridgeH's operation can be adjusted by directly manipulating the oPWM object, but note that doing so may change the way the oHBridgeH 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 examples, the oHBridgeH object is used.
Visual Basic Syntax C and Java Syntax
' This program ramps a DC Motor's speed
' up and down / forwards and backwards.

Dim A As New oHBridgeH

Sub Main() 
  A.IOLineP = 17
  A.IOLineA = 27
  A.IOLineB = 25
  A.Brake = cvOff
  A.Operate = cvOn
  Do
    For A.Power = -100 To 100
      ooPIC.Delay = 2
    Next A.Power 
    For A.Power = 100 To -100 Step -1
      ooPIC.Delay = 2
    Next A.Power 
  Loop 
End Sub
// This program ramps a DC Motor's speed
// up and down / forwards and backwards.

oHBridgeH A = New oHBridgeH; 

Void Main(Void){ 
  A.IOLineP = 17;
  A.IOLineA = 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;
    }
  } 
}
Basic Syntax 
' This program ramps a DC Motor's speed
' up and down / forwards and backwards.

A As oHBridgeH(27,,25,,17,,,,,,1)

Do
  For A.Power = -100 To 100
    ooPIC.Delay = 2
  Next A.Power 
  For A.Power = 100 To -100 Step -1
    ooPIC.Delay = 2
  Next A.Power
Loop
 
Back to top of page Related Items:
 The following table lists objects that use the oHBridgeH Object.
 ObjectDescriptionA1A2B1B2C1
oDCMotorControls a DC motor that is driven by an LMD18200 H-Bridge driver.xxx
oDCMotor2Controls a DC motor that is driven by an L293 H-Bridge driver.xx
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
Back to top of page Version History and Bug List:
 Firmware Ver B.1.0: Introduced.
Firmware Ver B.2.0: Added the Option property which provides the ability to control an H-Bridge's switches directly.

Bugs: No known bugs.


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