4 OPAMP Initialization
For all the following examples, the OPAMP will use a basic initialization preparing it
for use. The following steps are needed to initialize the OPAMP:
- Disable the digital input buffer of the output pin of the OPAMP to reduce noise and power consumption.
- Set the TIMEBASE register to be ≥ 1 µs.
- Set the ALWAYSON bit to enable the OPAMP to run continuously.
- Set the OUTMODE to NORMAL, to connect the I/O of the OPAMP to their respective pins.
- Activate OPAMP in standby sleep (optional).
- Enable the OPAMP by writing a
‘
1
’ to the ENABLE bit.
The above steps, including optional steps, are implemented in the function below. This function will be used in all the following examples.
#define OPAMP_MAX_SETTLE_TIME 0x7F void op_amp_init() { /*Disable input on op amp output pin*/ PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; /*Set up op amp*/ OPAMP.CTRLA = OPAMP_ENABLE_bm; OPAMP.TIMEBASE = (uint8_t) ceil(CLK_PER*0.000001)-1; /*Number of peripheral clock cycles that amounts to 1us*/ OPAMP.OP0CTRLA = OPAMP_RUNSTBY_bm | OPAMP_ALWAYSON_bm | OPAMP_OP0CTRLA_OUTMODE_NORMAL_gc; OPAMP.OP0SETTLE = OPAMP_MAX_SETTLE_TIME; //As the settle time is unknown, the maximums should be set }