11.3.1 DIRECTION CONTROL
The TRISB register (Register 11-10) controls the PORTB pin output drivers, even when they are being used as analog inputs. The user should ensure the bits in the TRISB register are maintained set when using them as analog inputs. I/O pins configured as analog inputs always read ‘0’.
11.3.6 PORTB FUNCTIONS AND OUTPUT PRIORITIES
Each pin defaults to the PORT latch data after reset. Other functions are selected with the peripheral pin select logic. See Section 12.0 “Peripheral Pin Select (PPS) Module” for more information. Analog input functions, such as ADC and Op Amp inputs, are not shown in the peripheral pin select lists. These inputs are active when the I/O pin is set for Analog mode using the ANSELB register. Digital output functions may continue to control the pin when it is in Analog mode.
My reading of that is to use the analogue functions of a pin (of which OPA is one), you must also enable the corresponding bit in ANSELB. If you do not, the pin still functions as a digital pin, direction as defined by the TRISB bit as normal.
ANSEL=0: Digital I/O. Pin is assigned to port or digital special function.
TRISB=1 digital input, TRISB=0 digital output
In this case what you have programmed in OPAxCON is esentially irrelevant to the functioning of the IO pin, but don’t expect the OPA module to work correctly if you are selecting an external pin as input (edit: internal sources such as FVR_Buffer2 should work fine).
ANSEL=1: Analog input. Pin is assigned as analog input(1). Digital input buffer disabled.
TRISB should be 1
In this case OPAxCON can be used to select the required pin as input to the OPA module.
But that is just my reading of the datasheet. I confess I don’t have any experience of this chip or the OPA modules.
post edited by pcbbc - 2019/04/07 14:57:04