diff options
author | Vishnu Easwaran E | 2020-08-10 12:44:59 +0530 |
---|---|---|
committer | GitHub | 2020-08-10 12:44:59 +0530 |
commit | c76c13209edef0efe7562685ba1b3b7017221679 (patch) | |
tree | 7e531c6afdad83ad9e6781c5e0ea42e23f5c3784 /Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp | |
parent | 381c57f811249833341c0e394fb48460d4b175b1 (diff) | |
parent | c3659645dd417f5c35424f7c174597d0ffd7e926 (diff) | |
download | OpenPLC-c76c13209edef0efe7562685ba1b3b7017221679.tar.gz OpenPLC-c76c13209edef0efe7562685ba1b3b7017221679.tar.bz2 OpenPLC-c76c13209edef0efe7562685ba1b3b7017221679.zip |
Merge pull request #12 from VishnuEaswaran/vishnuDev
Updating repo structure and documentation
Diffstat (limited to 'Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp')
-rw-r--r-- | Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp b/Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp deleted file mode 100644 index 098debe..0000000 --- a/Resources/OpenPLCv2/firmware/ADC.test.arduino/vishnuADC.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "vishnuADC.h" -#include "Arduino.h" - -/** - * Constructor of the class - * @param io_pin_cs a byte indicating the pin to be use as the chip select pin (CS) - */ -ADS1118::ADS1118(uint8_t io_pin_cs) { - cs = io_pin_cs; -} - -/** - * This method initialize the SPI port and the config register - */ -void ADS1118::begin() { - pinMode(cs, OUTPUT); - digitalWrite(cs, HIGH); - SPI.begin(); - SPI.beginTransaction(SPISettings(SCLK, MSBFIRST, SPI_MODE1)); - configRegister.bits={RESERVED, VALID_CFG, PULLUP, ADC_MODE, RATE_8SPS, SINGLE_SHOT, FSR_0256, DIFF_0_1, START_NOW}; //Default values -} - -/** - * Getting the temperature in degrees celsius from the internal sensor of the ADS1118 - * @return A double (32bits) containing the temperature in degrees celsius of the internal sensor - */ -double ADS1118::getTemperature() { - uint16_t convRegister; - uint8_t dataMSB, dataLSB, configMSB, configLSB, count=0; - if(lastSensorMode==TEMP_MODE) - count=1; //Lucky you! We don't have to read twice the sensor - else - configRegister.bits.sensorMode=TEMP_MODE; //Sorry but we will have to read twice the sensor - do{ - digitalWrite(cs, LOW); - dataMSB = SPI.transfer(configRegister.byte.msb); - dataLSB = SPI.transfer(configRegister.byte.lsb); - configMSB = SPI.transfer(configRegister.byte.msb); - configLSB = SPI.transfer(configRegister.byte.lsb); - digitalWrite(cs, HIGH); - for(int i=0;i<CONV_TIME[configRegister.bits.rate];i++) //Lets wait the conversion time - delayMicroseconds(1000); - count++; - }while (count<=1); //We make two readings because the second reading is the temperature. - convRegister = ((dataMSB << 8) | (dataLSB))>>4; - if((convRegister<<2) >= 0x8000){ - convRegister=((~convRegister)>>2)+1; //Converting to right-justified and applying binary twos complement format - return (double)(convRegister*0.03125*-1); - } - return (double)convRegister*0.03125; -} - -void ADS1118::setSamplingRate(uint8_t samplingRate){ - configRegister.bits.rate=samplingRate; -} |