Wiki

The most recent version of this page is a draft.DiffThis version is outdated by a newer approved version.DiffThis version (29 Jan 2016 20:31) was approved by Brandon Bushey.The Previously approved version (23 Dec 2015 13:37) is available.Diff

This is an old revision of the document!


pH Monitor with Temperature Compensation Demo

The ADuCM360_demo_cn0326 is a pH monitor with automatic temperature compensation demo project, for the EVAL-ADICUP360 base board with additional EVAL-CN0326-PMDZ pmod, created using the GNU ARM Eclipse Plug-ins in Eclipse environment.


General description


This project is a good example for how to use EVAL-ADICUP360 board in different combinations with pmod boards. It expand the list of possible applications that can be done with the base board.

The ADuCM360_demo_cn0326 project uses the EVAL-CN0326-PMDZ pmod which is a pH sensor signal conditioner and digitizer with automatic temperature compensation.


The CN0326 circuit provides a complete solution for pH sensors with internal resistance between 1 MΩ and several . It consist of pH probe buffer, Pt1000 RTD for temperature compensation and 24-bits ADC with 3 differential analog inputs.

The pH probe consists of a glass measuring electrode and a reference electrode, which is analogous to a battery. When the probe is place in a solution, the measuring electrode generates a voltage depending on the hydrogen activity of the solution, which is compared to the potential of the reference electrode. As the solution becomes more acidic (pH < 7) the potential of the glass electrode becomes more positive (+mV) in comparison to the reference electrode; and as the solution becomes more alkaline (pH > 7) the potential of the glass electrode becomes more negative (−mV) in comparison to the reference electrode.

The change in temperature of the solution changes the activity of its hydrogen ions. When the solution is heated, the hydrogen ions move faster which result in an increase in potential difference across the two electrodes. In addition, when the solution is cooled, the hydrogen activity decreases causing a decrease in the potential difference. Electrodes are designed ideally to produce a zero volt (0 V) potential when placed in a buffer solution with a pH of 7 (neutral pH).


The EVAL-CN0326-PMDZ comes with an evaluation software which can help you to test and to calibrate your pmod before you use it.

Please visit CN0326 Software User Guide page to find out how to get and how to use the CN0326 evaluation software.

The potential changes are outputted as ADC 24-bits value which is received via SPI interface of the EVAL-ADICUP360 board. The ADC analog differential channels are:

  • AIN1(+)/AIN1(-) - pH probe (voltage full range: ±414 mV at 25°C to ±490 mV at 80°C)
  • AIN2(+)/AIN2(-) - Pt1000 RTD (voltage full range: 210 mV to 290 mV with 210 μA excitation current)
  • AIN3(+)/AIN3(-) - Bias current (used to minimized tne voltage errors)

The ADuCM360_demo_cn0326 application purchase ADC outputs from input channels, calculates voltage, temperature and pH values. You can choose to use internal excitation current of the ADC (IOUT2) or calculate bias current of the circuit (see USE_IOUT2 parameter).

A UART interface (9600 baud rate and 8-bits data length) is used, as a command line interpreter, to send the results to terminal window: temperature and ph values. Beside this two the interpreter process other three commands: help, calibrate channel/channels and ADC reset.

To start the command line interpreter you need to press ENTER key (CR) from the keyboard and after that just type in <help> to see available commands. The output data are send via UART using semihosting mechanism.

The project uses below formula to determine output ADC code for an input voltage on either channel:


AIN - analog input voltage
GAIN - gain value in the in-amp setting
N - ADC resolution (24)
The temperature value is calculated using RTD resistance value and it varies from 0°C (1000 Ω) to 100°C (1385 Ω):


Rrtd - RTD resistance at T°C
Rmin - RTD resistance at 0°C
α - temperature coefficient (0.00385 Ω/Ω/°C)


To calculate pH value is used Nernst equation:

E - voltage of the hydrogen electrode with unknown activity
α - zero point tolerance (±30 mV)
T - ambient temperature in °C
n - valence, number of charges on ion (1 at 25 °C)
F - Faraday constant (96485 coulombs/mol)
R - Avogadro's number (8314 mV-coulombs /°K mol)
pHiso - reference hydrogen ion concentration (7)


Semihosting with ARM


Semihosting is a mechanism that connect the target firmware's standard IO (printf, scanf/fgets, open, write, read, close, etc) to your host PC via JTAG or SWD. It’s easy to configure it with open source tooling - the newlib C standard library and OpenOCD JTAG implementation.

You can automatic enable semihosting and configure it by using the project ADuCM36x C/C+ + Project template, which offer you the ability to select how do you want to use semihosting.

This example present the possibility to use semihosting to output messages with printf() by using a physical serial connection as UART. It uses the newlib GNU ARM library which actually links the UART physical port to standard C functions. You need only to overwrite _write() function, which is marked as weak function in the GNU ARM library, with your own function that write characters to UART (the same for _read() function when you want to use scanf() in your code).


Setting up the hardware


Connect the EVAL-CN0326-PMD to the SPI_PMOD connector of the EVAL-ADICUP360 board. In order to program the base board you need to use the DEBUG USB. After you program the board you can switch to USER USB and you are set to use the application. The important jumpers and switches configuration are highlighted in red.


The ADuCM360_cn0326_demo use UART connection via P0.6/P0.7 and SPI0 channel of the ADuCM360 to communicate with CN0326 board.

Obtaining the source code


We recommend not opening the project directly, but rather import it into Eclipse and make a local copy in your Eclipse workspace.

The source code and include files of the ADuCM360_demo_cn0326 can be found on Github:


Importing the ADuCM360_demo_cn0326 project


The necessary instructions on how to import the ADuCM360_demo_cn0326 project form the projects examples in the Git repository, can be found in How to import existing projects from the GIT Repository page.


Debugging the ADuCM360_demo_cn0326 project


  • A debug configuration must be set up for this project in order to have the possibility to program and to debug the ADuCM360_demo_cn0326 project. To do this, follow the instructions from Setting up a Debug Configuration Page.
  • Make sure the target board is connected to the computer (via DEBUG USB) and using the tool bar, navigate to the small Debug icon and select the debugging session you created. The application will programmed and the program execution will stop at the beginning of the main() function.

  • Use step-by-step execution or directly run the program.

After completion of the steps above the program will remain written into the system flash and it will run by default every time the board is powered up.


Project structure


The ADuCM360_demo_cn0326 project use ADuCM36x C/C++ Project structure.

This project contains: system initialization part - disabling watchdog, setting system clock, enabling clock for peripherals; port configuration for SPI0, UART via P0.6/P0.7; SPI, UART read/write functions; AD7793 control, voltage conversion, command interpreter, temperature and pH calculations.

In the src and include folders you will find the source and header files related to CN0326 software application. The Communication.c/h files contain SPI and UART specific data, meanwhile the AD7793.c/h files contain the ADC control data and the CN0326.c/h files contain the pH monitor application data.


In the appropriate header files you can configure next parameters:

  • ADC gain - AD7793_GAIN - POWER_DOWN set gain value for AD7793 converter (AD7793.h).
   #define AD7793_GAIN              AD7793_GAIN_1
  • Excitation current - USE_IOUT2 - select if you want to use bias current from the AIN3 channel: YES or you want to use internal excitation current, 210 µA: NO(CN0326.h).
   #define  USE_IOUT2         NO
  • Zero point tolerance - TOLERANCE - tolerance used in Nernst equation (CN0326.h).
    #define  TOLERANCE            0



The system folder contains system related files (try not to change these files):

  • ADuCM360 – contains low levels drivers for ADuCM360 microcontroller.
  • CMSIS – contains files related to ADuCM360 platform, such as: ADuCM360.h (registers definitions), system_ADuCM360.c/h (system clock), vectors_ADuCM360.c (interrupt vector table).
  • cortexm – contains files for system management (start-up, reset, exception handler).



Navigation - EVAL-ADICUP360

resources/eval/user-guides/eval-adicup360/reference_designs/demo_cn0326.1454095886.txt.gz · Last modified: 29 Jan 2016 20:31 by Brandon Bushey