oA2D Object

Main Index
Object List
Back to top of pageDescription:
 

An Object that controls the PIC's A2D Convert Module. 

The PIC's A2D Convert Module takes an analog voltage presented to one of the analog input lines and converts it to a digital value.

The following table lists the size and availability of the oA2D Object.
 ObjectSizeDescriptionA1A2B1B2C1
oA2D3 ByteAn Object that controls the PIC's A2D Hardware Module.xxxxx
Back to top of pageOperation:
 

An oA2D Object uses the PIC's A2D Converter Module (PICA2DCM) by first setting the channel select so that it is selecting the I/O Line specified by the IOLine property.  Once selected the PICA2DCM's charge holding capacitor is allowed to fully charge to the input voltage and the conversion is initiated.  The oA2D Object then waits until the PICA2DCM indicates that the conversion is done at which time the oA2D Object will copy the values from the result registers and place them into Result and ResultL.  The Result property holds the upper 8-Bits of the conversion and the ResultL property holds the lower 2-Bits.  Together these properties can yield an 8-Bit or 10-Bit analog conversion.

Each dimensioned instance of an oA2D Object shares the PICA2DCM and therefore must take turns doing conversions. To do this, each dimensioned instance of the oA2D Object with an Operate property set to 1 will in turn request an analog-to-digital conversion be done on its specified I/O Line. The analog-to-digital conversion process takes approximately 14µs and when the conversion is completed the results will be copied to that Object's properties. The next oA2D Object instance will follow the same until all active oA2D Object instances have been addressed. After the last Analog to Digital Object instance has been addressed the process begins again with the first instance. With 7 oA2D Object instances dimensioned (one for each analog IOLine) and all 7 Operate properties set to 1 the entire conversion process takes 98µs.

The IOLine property specifies the channel that the PICA2DCM will use.  The PICA2DCM has eight possible analog inputs, but one is dedicated to the ooPIC Operating system.  Therefore, the IOLine property can specify one of 7 channels while the value of 0 will set the oA2D Object instance into a dormant state.  Firmware versions A1 to B1 can only access the first four A2D channels (I/O Lines 1-4).  See the IOLine property for more detail.

An Operate property is provided to activate the oA2D Object. When set to 1 the oA2D Object continuously performs an analog-to-digital conversion which maintains the Result values at current conversion levels. When the Operate property is cleared to 0 the oA2D Object enters a dormant state thus leaving the Result values at the value of the last conversion.

The ExtVRef and ExtVRef2 properties determines the analog reference voltages.  The positive reference voltage is selectable between +5 volts or the voltage level supplied on I/O line 4 and the negative reference voltage is selectable between 0 volts and the voltage level supplied on I/O line 3.  Depending on the IOLine used, its actual usage can vary.  Refer to Microchip PIC16F877 PCFG3:PCFG0: A/D Port Configuration Control register for more detail.

Caution: the maximum voltage allowed on any I/O Line is 5 Volts DC. Voltages above 5 Volts can damage the input circuitry.

Back to top of pageProperties:
 

The following table lists the properties of the oA2D Object:

Property

Description

Result
The upper 8-Bit digital result of the analog-to-digital conversion.
Object Class: oByte Value Range: 0 - 255
Data Type: Numeric (Read-Only) Default Value: 0
ValueDescription
0

The input voltage is 0 volts.

1 - 254

The input voltage is a percentage of the reference voltage.

255

The input voltage = the reference voltage.

ResultL
The lower 2-Bit digital result of the analog-to-digital conversion.
Object Class: oVar Value Range: 0 - 3
Data Type: Numeric (Read-Only) Default Value: 0
IOLine
A value that specifies which analog input line is evaluated in the analog-to-digital conversion.
Object Class: oIOLineA Value Range: 0 - 3 for firmware up to B.1.0,
 0 - 7 for firmware B.2.0 and up.
Data Type: Numeric Default Value: 0
History:  In firmware version B.2.0, this property was expanded to include I/O Lines 5, 6 and 7.
IOLineVersionDescription
0A.1.0 - B.1.0

The Analog signal on IOLine 4 is evaluated. 4 can be assigned to the IOLine in place of 0 but it will read back as 0.

0B.2.0

The instance of the oA2D Object is dormant.

1 - 3All

The Analog signal on the specified IOLine is evaluated.

4 - 7A.1.0 - B.1.0Values of 4 - 7 will be treated as values 0 - 3.
4 - 7B.2.0

The Analog signal on the specified IOLine is evaluated.

ExtVRef
A value that selects the source of the voltage reference (+) for the analog to digital module.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
ExtVRefDescription
0

+Source = +5 volts

1

+Source = Voltage applied to I/O Line 4

ExtVRef2
A value that selects the source of the voltage reference (-) for the analog to digital module.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
This property modifies Bit-3 of the A/D Port Configuration Control register.  Depending on the IOLine used, its actual usage can vary.  Refer to Microchip PIC16F877 PCFG3:PCFG0: A/D Port Configuration Control register for more detail.
ExtVRef2Description
0

Source = 0 Volts

1

Source = Voltage applied to I/O Line 3

Operate
A value that selects whether or not the analog-to-digital conversions are performed.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe A2D Hardware is not enabled.
1cvOnThe A2D Hardware is enabled.
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 pageHardware Diagram:
 The PIC's A2D Converter Module (PICA2DCM).

Back to top of pageExample:

 In the following example uses the oA2D Object.
Visual Basic SyntaxC and Java Syntax
' This program reads the analog 
' value from I/O line 1 and 
' outputs its binary value to 
' I/O lines 8-15.

Dim A As New oA2D
Dim B As New oDIO8

Sub Main()
  B.IOGroup = 1
  B.Direction = cvOutput
  A.IOLine = 1
  A.Operate = 1
  Do
    B.State = A.Result
  Loop
End Sub
// This program reads the analog 
// value from I/O line 1 and 
// outputs its binary value to 
// I/O lines 8-15.

oA2D A = New oA2D;
oDIO8 B = New oDIO8;

Void Main(Void){
  B.IOGroup = 1;
  B.Direction = cvOutput;
  A.IOLine = 1;
  A.Operate = 1;
  Do{
    B.State = A.Result;
  }
} 
Basic Syntax 
' This program reads the analog 
' value from I/O line 1 and 
' outputs its binary value to 
' I/O lines 8-15.

A As oA2D(1,,,cvOn)
B As oDIO8(1,cvOutput)

Do
  B.State = A.Result
Loop
 

Back to top of pageRelated Items:

 The following table lists objects that use the oA2D Object.
 ObjectDescriptionA1A2B1B2C1
oA2D10Measures the level of the voltage on an input line with an 10-bit result.xx
oA2D8Measures the level of the voltage on an input line with an 8-bit result.xxxxx
oA2DXMeasures the level of the voltage on an input line and detects when it is below a threshold.xxx
Back to top of pageVersion History and Bug List:
 Firmware Ver A1: Introduced with 4 analog input.
Firmware Ver B2: Expanded the IOLine property to address 7 analog inputs.

Bugs: No known bugs.


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