san m
/
WeightScale
Weight scale using ADS1220
Fork of WeightScale by
main.cpp@1:933f47cce5bf, 2017-02-15 (annotated)
- Committer:
- sandeepmalladi
- Date:
- Wed Feb 15 15:32:38 2017 +0000
- Revision:
- 1:933f47cce5bf
- Parent:
- 0:94208ccccbde
- Child:
- 4:3ca00da0024d
Ads1220 Code to Voltage Conversion Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandeepmalladi | 0:94208ccccbde | 1 | #include "mbed.h" |
sandeepmalladi | 0:94208ccccbde | 2 | #include "ADS1220.h" |
sandeepmalladi | 0:94208ccccbde | 3 | #include "math.h" |
sandeepmalladi | 0:94208ccccbde | 4 | |
sandeepmalladi | 0:94208ccccbde | 5 | |
sandeepmalladi | 1:933f47cce5bf | 6 | #define NWIDTH 20 /* Size of the data buffer; length of the sequence. */ |
sandeepmalladi | 1:933f47cce5bf | 7 | #define STOPPER 0 /* Smaller than any datum */ |
sandeepmalladi | 1:933f47cce5bf | 8 | #define AVERGARE_COUNT 1000 /*Count can be any number from 2,4,8,16 */ |
sandeepmalladi | 0:94208ccccbde | 9 | |
sandeepmalladi | 1:933f47cce5bf | 10 | #define PGA 128 // Programmable Gain = 1 |
sandeepmalladi | 1:933f47cce5bf | 11 | #define VREF 5.0 // Internal reference of 2.048V |
sandeepmalladi | 0:94208ccccbde | 12 | #define VFSR VREF/PGA |
sandeepmalladi | 0:94208ccccbde | 13 | #define FSR (((long int)1<<23)) |
sandeepmalladi | 0:94208ccccbde | 14 | #define LSB_Size (VFSR/FSR) |
sandeepmalladi | 0:94208ccccbde | 15 | |
sandeepmalladi | 1:933f47cce5bf | 16 | ADS1220 ads1220_com(SPI_MOSI, SPI_MISO, SPI_SCK,SPI_CS); |
sandeepmalladi | 0:94208ccccbde | 17 | Serial data_serial(USBTX, USBRX); |
sandeepmalladi | 0:94208ccccbde | 18 | InterruptIn DRDY(PC_5); |
sandeepmalladi | 0:94208ccccbde | 19 | |
sandeepmalladi | 0:94208ccccbde | 20 | |
sandeepmalladi | 0:94208ccccbde | 21 | |
sandeepmalladi | 0:94208ccccbde | 22 | |
sandeepmalladi | 0:94208ccccbde | 23 | |
sandeepmalladi | 1:933f47cce5bf | 24 | bool New_data_avialable; |
sandeepmalladi | 0:94208ccccbde | 25 | void ext_int_DRDY(void); |
sandeepmalladi | 0:94208ccccbde | 26 | float code2volt(float c); |
sandeepmalladi | 0:94208ccccbde | 27 | |
sandeepmalladi | 1:933f47cce5bf | 28 | signed long tData; |
sandeepmalladi | 1:933f47cce5bf | 29 | float volt; |
sandeepmalladi | 0:94208ccccbde | 30 | |
sandeepmalladi | 0:94208ccccbde | 31 | int main() |
sandeepmalladi | 0:94208ccccbde | 32 | { |
sandeepmalladi | 1:933f47cce5bf | 33 | data_serial.baud(115200); |
sandeepmalladi | 0:94208ccccbde | 34 | wait(0.1); |
sandeepmalladi | 0:94208ccccbde | 35 | DRDY.rise(&ext_int_DRDY); |
sandeepmalladi | 0:94208ccccbde | 36 | ads1220_com.Config(); |
sandeepmalladi | 0:94208ccccbde | 37 | ads1220_com.SendStartCommand(); |
sandeepmalladi | 0:94208ccccbde | 38 | while(1) |
sandeepmalladi | 0:94208ccccbde | 39 | { |
sandeepmalladi | 1:933f47cce5bf | 40 | if(New_data_avialable) |
sandeepmalladi | 1:933f47cce5bf | 41 | { |
sandeepmalladi | 1:933f47cce5bf | 42 | New_data_avialable = 0; |
sandeepmalladi | 1:933f47cce5bf | 43 | tData = ads1220_com.ReadData(); |
sandeepmalladi | 1:933f47cce5bf | 44 | volt = code2volt(tData); |
sandeepmalladi | 1:933f47cce5bf | 45 | data_serial.printf("\rVoltage : %f\n",volt); |
sandeepmalladi | 1:933f47cce5bf | 46 | } |
sandeepmalladi | 0:94208ccccbde | 47 | } |
sandeepmalladi | 0:94208ccccbde | 48 | } |
sandeepmalladi | 0:94208ccccbde | 49 | |
sandeepmalladi | 0:94208ccccbde | 50 | float code2volt(float c) |
sandeepmalladi | 0:94208ccccbde | 51 | { |
sandeepmalladi | 0:94208ccccbde | 52 | float Vout = 0; |
sandeepmalladi | 0:94208ccccbde | 53 | Vout = (float)(c*LSB_Size*1000); //In mV |
sandeepmalladi | 0:94208ccccbde | 54 | return Vout; |
sandeepmalladi | 0:94208ccccbde | 55 | } |
sandeepmalladi | 0:94208ccccbde | 56 | |
sandeepmalladi | 0:94208ccccbde | 57 | void ext_int_DRDY(void) |
sandeepmalladi | 0:94208ccccbde | 58 | { |
sandeepmalladi | 0:94208ccccbde | 59 | New_data_avialable = 1; |
sandeepmalladi | 0:94208ccccbde | 60 | } |