MCP3425 sample

Dependencies:   AQM0802 MCP3425 mbed

See http://developer.mbed.org/users/yasuyuki/notebook/MCP3425/

Committer:
yasuyuki
Date:
Wed Oct 15 14:40:22 2014 +0000
Revision:
0:5999cefe7380
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:5999cefe7380 1 //**********************
yasuyuki 0:5999cefe7380 2 // A/D Converter
yasuyuki 0:5999cefe7380 3 // MCP3425 sample for mbed
yasuyuki 0:5999cefe7380 4 //
yasuyuki 0:5999cefe7380 5 // Voltage=(Vin+)-(Vin-)
yasuyuki 0:5999cefe7380 6 // Voltage Range:-2.048V to 2.048V
yasuyuki 0:5999cefe7380 7 // Resolution:2.048V/0x7FFF=62.5uV, 16bits
yasuyuki 0:5999cefe7380 8 // Sampling Per Second
yasuyuki 0:5999cefe7380 9 // 240 SPS, 12bits
yasuyuki 0:5999cefe7380 10 // 60 SPS, 14bits
yasuyuki 0:5999cefe7380 11 // 15 SPS, 16bits (default)
yasuyuki 0:5999cefe7380 12 //
yasuyuki 0:5999cefe7380 13 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:5999cefe7380 14 // http://einstlab.web.fc2.com
yasuyuki 0:5999cefe7380 15 //**********************
yasuyuki 0:5999cefe7380 16 #include "mbed.h"
yasuyuki 0:5999cefe7380 17 #include "AQM0802.h"
yasuyuki 0:5999cefe7380 18 #include "MCP3425.h"
yasuyuki 0:5999cefe7380 19
yasuyuki 0:5999cefe7380 20 #if defined(TARGET_LPC1768)
yasuyuki 0:5999cefe7380 21 I2C i2c(p28,p27);
yasuyuki 0:5999cefe7380 22 #endif
yasuyuki 0:5999cefe7380 23 // for TG-LPC11U35-501
yasuyuki 0:5999cefe7380 24 #if defined(TARGET_LPC11U35_501)
yasuyuki 0:5999cefe7380 25 I2C i2c(P0_5,P0_4);
yasuyuki 0:5999cefe7380 26 #endif
yasuyuki 0:5999cefe7380 27 // for Nucleo
yasuyuki 0:5999cefe7380 28 #if defined(TARGET_NUCLEO_F401RE)
yasuyuki 0:5999cefe7380 29 I2C i2c(D14,D15);
yasuyuki 0:5999cefe7380 30 #endif
yasuyuki 0:5999cefe7380 31
yasuyuki 0:5999cefe7380 32 AQM0802 lcd(i2c);
yasuyuki 0:5999cefe7380 33 MCP3425 mcp3425(i2c);
yasuyuki 0:5999cefe7380 34
yasuyuki 0:5999cefe7380 35
yasuyuki 0:5999cefe7380 36 int main() {
yasuyuki 0:5999cefe7380 37
yasuyuki 0:5999cefe7380 38 char msg[10];
yasuyuki 0:5999cefe7380 39 short a;
yasuyuki 0:5999cefe7380 40 float v;
yasuyuki 0:5999cefe7380 41
yasuyuki 0:5999cefe7380 42 sprintf(msg,"MCP3425");
yasuyuki 0:5999cefe7380 43 lcd.locate(0,0);
yasuyuki 0:5999cefe7380 44 lcd.print(msg);
yasuyuki 0:5999cefe7380 45 wait(1);
yasuyuki 0:5999cefe7380 46
yasuyuki 0:5999cefe7380 47 while(1) {
yasuyuki 0:5999cefe7380 48
yasuyuki 0:5999cefe7380 49 a = mcp3425.get();
yasuyuki 0:5999cefe7380 50 sprintf(msg,"dat=%X",(unsigned short)a);
yasuyuki 0:5999cefe7380 51 lcd.locate(0,0);
yasuyuki 0:5999cefe7380 52 lcd.print(msg);
yasuyuki 0:5999cefe7380 53 v = (float)a*2.048/0x7FFF;
yasuyuki 0:5999cefe7380 54 sprintf(msg,"%f",v);
yasuyuki 0:5999cefe7380 55 lcd.locate(0,1);
yasuyuki 0:5999cefe7380 56 lcd.print(msg);
yasuyuki 0:5999cefe7380 57 wait(1); // Do not exceed 15SPS with 16bits
yasuyuki 0:5999cefe7380 58 }
yasuyuki 0:5999cefe7380 59
yasuyuki 0:5999cefe7380 60 }
yasuyuki 0:5999cefe7380 61