Firmware to test ADC ADS1220! Configured to Single Shot Aquisition, Turbo Mode and 2000SPS.

Dependencies:   TI_ADS1220 mbed

Committer:
firewalk
Date:
Thu Oct 13 02:07:47 2016 +0000
Revision:
0:444b87fd373b
Modified by Celso Varella v.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
firewalk 0:444b87fd373b 1 /*CODE TEST ADC ADS1220*/
firewalk 0:444b87fd373b 2 /*ADS1220 LIBRARY MODIFIED OF SANDEEP MALLADI*/
firewalk 0:444b87fd373b 3 /*https://developer.mbed.org/users/sandeepmalladi/code/ADS1220*/
firewalk 0:444b87fd373b 4
firewalk 0:444b87fd373b 5 #include "mbed.h"
firewalk 0:444b87fd373b 6 #include "ADS1220.h"
firewalk 0:444b87fd373b 7
firewalk 0:444b87fd373b 8
firewalk 0:444b87fd373b 9
firewalk 0:444b87fd373b 10 #define PGA 1 // Programmable Gain = 1
firewalk 0:444b87fd373b 11 #define VREFE 5.0 // External reference of 5.00V
firewalk 0:444b87fd373b 12 #define VFSR VREFE/PGA
firewalk 0:444b87fd373b 13 #define FSR (((long int)1<<23))
firewalk 0:444b87fd373b 14 #define LSB_Size (VFSR/FSR)
firewalk 0:444b87fd373b 15
firewalk 0:444b87fd373b 16 Serial pc(USBTX, USBRX);
firewalk 0:444b87fd373b 17 ADS1220 ads1220_com(PTD2, PTD3, PTD1);
firewalk 0:444b87fd373b 18 DigitalIn DRDY(D0);
firewalk 0:444b87fd373b 19
firewalk 0:444b87fd373b 20 Timer t;
firewalk 0:444b87fd373b 21
firewalk 0:444b87fd373b 22 void showvolt(float volts);
firewalk 0:444b87fd373b 23 float code2volt(float c);
firewalk 0:444b87fd373b 24 signed long t1Data, t2Data;
firewalk 0:444b87fd373b 25 float Vout, volt;
firewalk 0:444b87fd373b 26 char AIN1 = 57, AIN2 = 56;
firewalk 0:444b87fd373b 27 int chn;
firewalk 0:444b87fd373b 28
firewalk 0:444b87fd373b 29 int main(){
firewalk 0:444b87fd373b 30 pc.baud (230400); //Set a baudrate to unusual value of the 230400bps
firewalk 0:444b87fd373b 31 pc.printf("ADS1220 Inicializing\n\r");
firewalk 0:444b87fd373b 32 ads1220_com.Config();
firewalk 0:444b87fd373b 33 //Configure ADS1220 to Single Shot, Turbo Mode & 2000sps
firewalk 0:444b87fd373b 34 pc.printf("ADS1220 Configured and Inicialized\n\r");
firewalk 0:444b87fd373b 35
firewalk 0:444b87fd373b 36
firewalk 0:444b87fd373b 37 wait_ms(500);
firewalk 0:444b87fd373b 38
firewalk 0:444b87fd373b 39 while(1) {
firewalk 0:444b87fd373b 40 t.start(); //Start Timer to Count Time Lapse
firewalk 0:444b87fd373b 41
firewalk 0:444b87fd373b 42 ads1220_com.set_MUX(AIN1); //Configure to Sample Channel 1
firewalk 0:444b87fd373b 43 ads1220_com.SendStartCommand(); //Start Aquisition
firewalk 0:444b87fd373b 44 while (DRDY != 0){} // Wait data on Buffer
firewalk 0:444b87fd373b 45 t1Data = ads1220_com.ReadData(); //Read Data Sampled on Channel 1
firewalk 0:444b87fd373b 46
firewalk 0:444b87fd373b 47 ads1220_com.set_MUX(AIN2); //Configure to Sample Channel 2
firewalk 0:444b87fd373b 48 ads1220_com.SendStartCommand(); //Start Aquisition
firewalk 0:444b87fd373b 49 while (DRDY != 0){} // Wait data on Buffer
firewalk 0:444b87fd373b 50 t2Data = ads1220_com.ReadData(); //Read Data Sampled on Channel 2
firewalk 0:444b87fd373b 51
firewalk 0:444b87fd373b 52 pc.printf("AIN1 %f - AIN2 %f \n\r",code2volt(t1Data), code2volt(t2Data)); //Print Data Formated
firewalk 0:444b87fd373b 53 t.stop();//Stop Timer to Count Time Lapse
firewalk 0:444b87fd373b 54
firewalk 0:444b87fd373b 55 pc.printf("TEMPO %f \n\r", t.read()); //Print Time Lapse
firewalk 0:444b87fd373b 56 t.reset(); //Reset Timer Counter
firewalk 0:444b87fd373b 57
firewalk 0:444b87fd373b 58 }
firewalk 0:444b87fd373b 59 }
firewalk 0:444b87fd373b 60
firewalk 0:444b87fd373b 61 //Function to Convert ADC Data Read
firewalk 0:444b87fd373b 62 float code2volt(float c)
firewalk 0:444b87fd373b 63 {
firewalk 0:444b87fd373b 64 float Vout = 0;
firewalk 0:444b87fd373b 65 Vout = (float)(c*LSB_Size*1000); //In mV
firewalk 0:444b87fd373b 66 return Vout;
firewalk 0:444b87fd373b 67 }