ADCHS and DAC programming with LPC-Link 2 + LabTool
Dirceu Rodrigues, Jr. - Oct. 2013
Dirceu Rodrigues, Jr. is a computer engineer with a master's degree in electrical engineering. As an independent consultant, he tests new products with particular interest in the areas of wireless sensor networks, ARM processors, DSP, motor control, and medical applications.
When I got involved with this campaign, my initial idea was to use the NXP LPC4370 microcontroller available on the LPC-Link 2 to implement a multicore FIR filter. Combined with the analog processing capabilities present on LabTool add-on board, would be ideal to put in place a structure which I discussed on ESC Brazil 2013 (Multicore Microcontrollers in Instrumentation and Control). But after a time studying the schematics of these boards, I realized that understanding the signal conditioning circuits, gain settings, input calibration and the correct use of ADCHS (12 bit High Speed ADC) peripheral and external DAC, deserve a whole article. For me, the most important feature of the board LPC-Link 2 (in addition to being a programmer/debugger for the target) is able to program a generic application on LPC4370 memory, since there are several analog/digital pins available on expansion connectors.
Firstly, I downloaded the latest version of the ARM Keil µVision (V220.127.116.11). At time, I had not experienced the new LPCOpen library, so I changed the LPC43xx.h provided by the compiler to add a raw support for ADCHS peripheral - renaming it to LPC43xx_new.h. The change consists primarily in define register addresses, enabling references such as “LPC_ADCHS->xxx”. Before attach LPC-Link 2 on top of LabTool board, I connected the 10 pin SWD cable on J2 of LPC-Link 2, according Figure 1. Will look like the cable is squeezed between the boards, but that is quite normal. Also, the user must to ensure the other connectors are not slightly misaligned.
LabTool - Analog Inputs
Next I tried to unveil the structure around the high speed analog to digital converter. The reason for the presence of the BNC connectors on LabTool is to implement a complete two channel oscilloscope, whose features are far from modest, since the LPC4370 includes a 12 bit ADC, and can operate up to 80 MHz. Note that the two 10 bit ADC modules are absent on LPC4370 TFBGA100 package used in LabTool. A very simplified schematic of input conditioning circuit for each channel is shown on Figure 2. The complete design, provided by Embedded Artists, includes several other components, including capacitors for shaping the frequency response.
All settings are controlled via the SPI interface, including the DC/AC coupling. The input (0.5 V) is provided by a proper MCU pin related to ADCHS, as I will explain later. Two analog multiplexers allow set the gain when changing the operational amplifier feedback resistor. From the nominal values of components on figure, we can write some equations for the DC model:
The LPC4370 ADC is a flash type with differential input - Figure 3.
The value converted to digital domain, as presented on page 1287 of LPC43xx User Manual (2013 draft version), is:
Through the DCINNEG and DCINPOS bits on ADCHS POWER_CONTROL register, the user can add a 0.5 V DC offset to the differential inputs. In the case of Labtool board, is convenient make DCINNEG = 1 and DCINPOS = 0, considering the presence of amp op with the non-inverting input voltage
according Figure 2. With these settings:
Also, note that
Substituting these results on Eq. 4: , and:
The value of GA depends on position of two multiplexers (feedback resistor selection 1 out 8) and SPDT switch (divided input voltage selection VU or VD). So, I can create the Table 1, which allow me to calculate the analog input value or VCH1, for each selection.
Non-inverting Amp. Op. gain
2k87 // 158R
2k87 // 536R
2k87 // 1k65
1k33 // 270R
1k33 // 1k07
10 ( 9.86)
In order to obtain a value of acceptable precision it's required to compensate the ADC readings (NADC) for component tolerances and other deviations associated with the input conditioning circuit. This is done in software. An affine function (gain and offset) makes the correction based on the current reading and previous calibration data – Listing 1.
Remember that a measuring instrument is not only as good as its components, but also as the calibration method used.
LabTool - Analog Outputs
The Digital to Analog section is more straightforward. Since the 10 bit DAC module is absent on LPC4370 TFBGA100 package, the LabTool board relies on external DAC102S085 from National to output two analog voltages. As before, the simpler schematic on Figure 4 shows the essential components for the DC model.
On LabTool board, the LPC4370 SSP1 peripheral has three usages:
- Settings for the ADCHS conditioning circuit.
- Writing on DAC
- Communication with an EEPROM
The sharing is carried out through appropriate slave selection signals (SSEL and GPIOs) from MCU. The DAC has two channels with internal data register including controls for update/refresh timing.
The relevant equations are:
Substituting Eq. 7 in Eq. 8:
Application: Filtering an ECG
In order to test the ADCHS and related equations obtained from the LabTool manufacturer schematics, I decided to program the ARM Cortex-M4 on LPC4370 to implement a stop-band FIR (Finite Impulse Response) filter with 127 taps. The idea is to filter an ECG signal corrupted by 60 Hz hum. To avoid building a circuit around an instrumentation amplifier (something I've done a few times) and waste some skin electrodes; I thought using the computer sound card to generate the desired signal. So, the following tasks were performed:
- Find an ECG signal database in audio format .
- Select the file ecg.wav (60s duration, 16 bit, 1 kSa/s).
- Extract the file data on Matlab, insert a 60 Hz noise and rewrite it in wav format .
- Play the file on computer line-out using a software for audio editing like GoldWave.
This will allow some experimentation, as repeat intervals, invert polarity, attenuate and many other useful transformations - Figure 6.
- Design a notch FIR filter in Matlab and simulate the result.
- Make a header file with the generated 127 coefficients.
For this application, I used DC coupling on input (capacitor short-circuited on Figure 2). Also, the ADCHS was configured to present the result in two’s complement format (other option is offset binary) . Figure 7 shows a diagram for the FIR filter - coefficients and output labeled as c and NFILT, respectively.
To check the result, the filtered signal is sent to the analog output in real time. For this it’s necessary to perform a conversion between the ADCHS and DAC102S085 ranges using appropriate equations. Here I have at least two options:
- 1. Taking advantage of maximum available resolution (not used):
In this case, the conversion is performed through the Equation 10 and Figure 8.
Substituting Eq. 10 on Eq. 9:
In order to ensure compatibility with the amplitude of sound card output it is appropriate to select the gain 10 for the ADC non-inverting amplifier (last row of Table 1). Therefore, the equation for the analog to digital conversion is:
This leads to a maximum input voltage around +/- 2.5V, when -2048 <= NFILT < +2048. Combining Eq.11 and Eq. 12, the relationship b etween input and output is given by:
- 2. Equal amplitudes (input/output):
In the ECG filtering applicatioon it is desirable that the original and filtered signals had the same amplitude, or a 1:1 relationship. Therefore, I've carried a different conversion in order to meet VEXT_AOUT1 = VCH1. Still maintaining the gain 10 between VCH1 and NFILT and equating Eq. 12 and Eq. 9:
Thus resulting in the equation responsible for the conversion:
Armed wiht this modeling I did a simulation on Matlab. The plots on Figure 9 allowed me to check the filter performance by comparing the input, the noisy signal and the output. Note an approximate delay of 64ms between the input and output (representing taps/2 samples).
With this set of equations and the FIR itself coded on LPC4370, the final result is shown following.
The sampling and output rates both are equal to 1k/s. Note an approximate delay of 64 ms between input and output (representing taps/2 samples). This powerful microcontroller and its high speed ADC are able to handle sample rates much higher than the one I used here, including multichannel audio. As I mentioned earlier, the purpose of this simple application is just to introduce the analog resources available on LabTool board.
The ADCHS has many other configuration options. It works through a state machine with a dedicated timer and a set of eight descriptors, for which it is possible to establish how and when a conversion occurs, generating interrupts, filling a 16 position FIFO or transferring data through DMA
The clock for this application was adjusted to 180 MHz, a value more than sufficient. In a next installment, I intend to wake-up the other two Cortex-M0 cores on the LPC4370, implementing a truly multicore filter through IPC (Inter-process Communication), running at a lower clock; something like 60 MHz and compare the results with the single core solution – for example, analyzing the power consumption. Stay tuned .