In the previous post code-oriented post, we got the DAC generating waveforms of reasonable frequencies. Unfortunately, a DAC usually has a high output impedance, which will distort our signals if we place it in the wrong circuit. Fortunately, we can make up for this using the on-board operational amplifiers as 'buffers' or 'voltage followers'. Their job is to simply take the input voltage and reflect it on the output with a low output impedance. This post will focus on getting the op-amps running in this mode.
As mentioned in the last post, there were some schematic errors. We aren't going to go into all of the changes, just the necessary ones to make this board work. We did 3 things:
Performing these operations shunts our opamp outputs to the desired outputs. More changes will be made later.
The buffer amplifier is likely the simplest opamp circuit out there. If you don't understand how it works, follow the link. The simplest idea is that Vout always equals Vin.
The on-chip amplifier is very configurable. We are going to use the PINSEL and NINSEL registers to make our on-chip amplifier conform to the buffer connections above. See the blue lines below. The OAxOUT pins are our pins 7 and 26 on our device.
We can use just a couple of lines of code to configure the opamp pins. Looking at the datasheet AMPxCON:
We could load these all at once, but I am not certain that the compiler would recognize and optimize sequential register manipulations, so we will simply look at all of the 1's and calculate the hex value, which is 0x002d.
The final statement is to turn the opamps on using the AMPEN bit.
1 2 3 4 5
TRISBbits.TRISB3 = TRISBbits.TRISB15 = TRISBbits.TRISB14 = DIO_INPUT; ANSBbits.ANSB3 = ANSBbits.ANSB15 = DIO_ANALOG; AMP1CON = AMP2CON = 0x002D; AMP1CONbits.AMPEN = AMP2CONbits.AMPEN = 1;
The scope output shows that our buffer amplifiers are working perfectly!