oMath Object

Back to top of pageDescription:
 An Object that takes the value of two Objects, performs mathematical or Boolean operations on them, and copies the result to the another object.
 The following table lists the size and availability of the oMath Object and its variations.
 ObjectSizeDescriptionA1A2B1B2C1
oMath4 BytesProvides mathematical functions.xxxxx
oMathI5 BytesWith 8-Bit Value on input 2.xxx
oMathOWith 8-Bit Value on Output.xxx
oMathC6 BytesClocked mathematical functions.xxx
oMathICClocked with 8-Bit Value on input 2.xxx
oMathOCClocked with 8-Bit Value on Output.xxx
Back to top of pageOperation:
 The normal operation of the oMath Object is to take the values of the two Objects pointed to by the Input1 & Input2 properties, perform the operation specified by the Mode property, and then store the resulting value in the Object pointed to by the Output property once every Object List Loop.

If the property option "C" is used, then the operation is modified so that this function only occurs once each time an oLogic Object transitions.

Two evaluations are made on the resulting value. The Negative property is set to the result of a Negative-Value evaluation and the NonZero property is set to the result of a Not-Zero-Value evaluation.

An 8-Bit signed Value property can be substituted for the either the Input2 or the Output property by specifying the appropriate property options.

Back to top of pageProperty Options:
 The oMath Object has 6 variants which are selected with 3 different property options: I, O,  and C.  
  • I specifies that the Input2 property is replaced with a Value property.
  • O specifies that the Output property is replaced with a Value property.
  • C specifies that a clocked version of the object is used.
 Continuous
operation
Clocked
operation
Pointers for inputs and output:oMathoMathC
Signed 8-Bit Value on input 2:oMathIoMathIC
Signed 8-Bit Value on the output:oMathOoMathOC
Back to top of pageProperties:
 

The following table lists the properties of the oMath Object:

Property

Description

Operate
A value that selects whether or not the mathematical operation is performed.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe mathematical function is not performed.
1cvOnThe mathematical function is performed.
Value
An 8-Bit value that replaces ether the Input2 or the Output properties.
Object Class: oChar Value Range: -128 to +127
Data Type: Numeric Default Value: 0
Availability: oMathI,  oMathIC,  oMathO,  oMathOC
Input1
A pointer to an object whose value is used in the mathematical operation.
Object Class: oValuePtrI Value Range: Any oValue Object
Data Type: Pointer Default Value: Null
Input2
A pointer to an object whose value is used in the mathematical operation.
Object Class: oValuePtrI Value Range: Any oValue Object
Data Type: Pointer Default Value: Null
Availability: oMath,  oMathC,  oMathO,  oMathOC
Output
A pointer to an object whose Value will be updated with the result of the mathematical operation.
Object Class: oValuePtrO Value Range: Any oValue Object
Data Type: Pointer Default Value: Null
Availability: oMath,  oMathC,  oMathI,  oMathIC
Mode
A value that selects which one of 8 math operations to performed.
Object Class: oSelect0to7 Value Range: 0 - 7
Data Type: Numeric Default Value: 0
ModeConstantDescription
0cvAddAdds the values of Input1 and Input2
1cvSubtractSubtracts the value of Input2 from the value of Input2.
2cvLShiftBit-shifts left the values of Input1 a number of times specified by Input2.
3cvRShiftBit-shifts right the values of Input1 a number of times specified by Input2.
4cvANDInput1 is ANDed with Input2.
5cvOrInput1 is ORed with Input2.
6cvXOrInput1 is XORed with Input2.
7cvLatchInput1 is copied to Output.
Negative
If Mode is 0-3, A value that indicates the result of the Output-value-is-negative evaluation. If Mode is 4-7, A value that specifies if the bits in the result will be inverted.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
NegativeModeConstantDescription
00 - 3cvPositiveOutput is positive in value.
10 - 3cvNegativeOutput is negative in value.
X4 - 7 Not updated.
NonZero
A value that indicates the result of the math function is not zero.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
NonZeroConstantDescription
0cvFalseOutput is zero in value.
1cvTrueOutput is not zero in value.
Process
Clock
See Clocked Objects for detail
Object Class: oClockedOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
Availability: oMathC,  oMathIC,  oMathOC
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 pageExample:
 The following examples use the oMath Object.
Visual Basic SyntaxC and Java Syntax
' This program reads two knob objects
' and adds them together using an
' oMath object and displays
' the result on a 7-Segment display.

Dim D As New o7Seg2
Dim K1 As New oKnob
Dim K2 As New oKnob
Dim M As New oMath

Sub main()
  D.IOGroup = 3
  D.IOLineD = 16
  D.Mode = 1
  D.Operate = cvOn
  K1.IOLine = 1
  K1.Operate = 1
  K2.IOLine = 2
  K2.Operate = 1
  M.Input1.Link(K1)
  M.Input2.Link(K2)
  M.Output.Link(D)
  M.Operate = 1
End Sub
// This program reads two knob objects
// and adds them together using an
// oMath object and displays
// the result on a 7-Segment display.

o7Seg2 D = New o7Seg2;
oKnob K1 = New oKnob;
oKnob K2 = New oKnob;
oMath M = New oMath;

Void main(Void){
  D.IOGroup = 3;
  D.IOLineD = 16;
  D.Mode = 1;
  D.Operate = cvOn;
  K1.IOLine = 1;
  K1.Operate = 1;
  K2.IOLine = 2;
  K2.Operate = 1;
  M.Input1.Link(K1);
  M.Input2.Link(K2);
  M.Output.Link(D);
  M.Operate = 1;
}
Basic Syntax 
' This program reads two knob objects
' and adds them together using an
' oMath object and displays
' the result on a 7-Segment display.

D Var o7Seg2(3,16,1,0,cvOn)
K1 Var oKnob(1,cvOn)
K2 Var oKnob(2,cvOn)
M Var oMath(K1,K2,D,,cvOn)
'This program creates a 
'Virtual Circuit that adds 
'two numbers and outputs 
'the results on I/O line 
'8-15 & 24-31.

Dim M As New oMath
Dim X As New oWord
Dim Y As New oWord
Dim Z As New oDIO16

Sub Main()
  M.Input1.Link(X)
  M.Input2.Link(Y)
  M.Output.Link(Z)
  M.Operate = cvTrue
  Z.Direction = cvOutput
  X = 16
  Y = 4
End Sub
'This program creates a 
'Virtual Circuit that  
'divides an oA2D reading 
'by 4 and then sets the
'position of a servo with
'it.

Dim M As New oMathI
Dim X As New oA2D
Dim Z As New oServo

Sub Main()
  M.Input1.Link(X)
  M.Output.Link(Z)
  M.Mode = cvRShift
  M.Value = 2
  M.Operate = cvTrue
  X.IOLine = 1
  X.Operate = cvTrue
  Z.IOLine = 8
  Z.Center = 26
  Z.Operate = cvTrue
End Sub
'This program creates a 
'Virtual Circuit that adds 
'two numbers and outputs 
'the results on I/O 
'line 8-15.

Dim M As New oMathO
Dim X As New oWord
Dim Y As New oWord
Dim Z As New oDIO8

Sub Main()
  M.Input1.Link(X)
  M.Input2.Link(Y)
  M.Operate = cvTrue
  Z.IOGroup = 1
  Z.Direction = cvOutput
  X = 8
  Y = 4
  Do
    Z = M
  Loop
End Sub

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oNavConAn Object that provides differential steering calculations.xxx
oRampAn Object that calculate a ramp speed for a motor.xx
Back to top of pageVersion History and Bug List:
 Firmware Ver A1: oMath Introduced.
Firmware Ver B1: oMathC, oMathI oMathIC, oMathO, oMathOC Introduced.

Bugs: 
firmware version A1-B2: Linking the oA2D to oMath directly causes the calculation to be incorrect.  
firmware version C1: No known bugs.


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