diff --git a/software/app/application.cpp b/software/app/application.cpp index 8e872c6..d124e03 100644 --- a/software/app/application.cpp +++ b/software/app/application.cpp @@ -2,6 +2,7 @@ #include #include #include "ads101x.h" +#include "dac101c085.h" #include "sensor_hub.h" #include "sensor_settings.h" #include "double_buffer.h" @@ -13,6 +14,8 @@ static const int HUB_PERIOD = 5; static const int ADC_TIMEBASE = 250; static const int ADC_PERIOD = 5; static const uint8_t ADC_ADDRESS = 0x48; +static const uint8_t DAC_ADDRESS = 0xC; + using namespace rijnfel; @@ -23,6 +26,7 @@ void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway); Timer procTimer; ads::cADS101x adc(0, ADC_ADDRESS); uint8_t channel = 0; +dac::cDAC101C085 mydac(1, DAC_ADDRESS); cSensorHub hub(HUB_PERIOD); @@ -78,8 +82,12 @@ void init() { WifiAccessPoint.config("Sensus", "", AUTH_OPEN, false, 3);*/ cWebInterface::GetInstance()->Start(); - procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start(); + //procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start(); //procTimer.initializeMs(5000, SettingsTest).start(); + //mydac.CheckDev(); + //Serial.println(mydac.ReadSettings()); + Serial.println(mydac.ChangeSettings(dac::eOpMode::NORMAL, 1023)); + Serial.println(mydac.ReadSettings()); } diff --git a/software/app/dac101c085.cpp b/software/app/dac101c085.cpp index b93ec57..e39f207 100644 --- a/software/app/dac101c085.cpp +++ b/software/app/dac101c085.cpp @@ -4,7 +4,7 @@ // Author: Maximilian Stiefel // Date: 08.08.2017 // -// Description: +// Description: Small simple driver for the TI DAC101C085. // //---------------------------------------------------------------------------------------------------------------------------- @@ -27,7 +27,7 @@ cDAC101C085::~cDAC101C085() {} //-------------------------------------checkDev------------------------------------------------------------------------------- -void cDAC101C085::checkDev() +void cDAC101C085::CheckDev() { // Vars byte error = 0; @@ -43,7 +43,7 @@ void cDAC101C085::checkDev() } //-------------------------------------changeSettings------------------------------------------------------------------------- -uint8_t cDAC101C085::changeSettings(enum eOpMode mode, uint16_t val) +uint8_t cDAC101C085::ChangeSettings(enum eOpMode mode, uint16_t val) { // Vars uint16_t settings = 0; @@ -54,16 +54,16 @@ uint8_t cDAC101C085::changeSettings(enum eOpMode mode, uint16_t val) switch(mode) { case NORMAL: - settings += 0b00 << PD_BITS_POS; + settings += (0b00 << PD_BITS_POS); break; case PULL_DOWN_2K5: - settings += 0b01 << PD_BITS_POS; + settings += (0b01 << PD_BITS_POS); break; case PULL_DOWN_100K: - settings += 0b10 << PD_BITS_POS; + settings += (0b10 << PD_BITS_POS); break; case HIGH_IMPEDANCE: - settings += 0b11 << PD_BITS_POS; + settings += (0b11 << PD_BITS_POS); break; } @@ -80,7 +80,7 @@ uint8_t cDAC101C085::WriteSettings(uint16_t settings) Wire.write( (uint8_t) (settings >> 8) ); // Most significant byte Wire.write( (uint8_t) (settings & 0xFF) ); // Least significant byte error = Wire.endTransmission(); - Serial.print(settings); + Serial.println(settings); return I2CError(error); // Pass to error parser } diff --git a/software/app/dac101c085.h b/software/app/dac101c085.h index a6e455a..c340788 100644 --- a/software/app/dac101c085.h +++ b/software/app/dac101c085.h @@ -4,7 +4,7 @@ // Author: Maximilian Stiefel // Date: 08.08.2017 // -// Description: +// Description: Small simple driver for the TI DAC101C085. // //---------------------------------------------------------------------------------------------------------------------------- @@ -16,7 +16,7 @@ //-------------------------------------Defines-------------------------------------------------------------------------------- #define DEBUG_LEVEL 1 // 1 a lot debugging output, else rare debugging output -#define PD_BITS_POS 14 // Position of power down bits +#define PD_BITS_POS 13 // Position of power down bits #define D_BITS_POS 2 // Position of data bits //-------------------------------------Namespaces----------------------------------------------------------------------------- @@ -32,14 +32,14 @@ class cDAC101C085 public: cDAC101C085(uint8_t number, uint8_t i_address); // Constructor ~cDAC101C085(); // Destructor - void checkDev(); // Check if device is available and alive + void CheckDev(); // Check if device is available and alive uint16_t ReadSettings(void); - uint8_t WriteSettings(uint16_t settings); - uint8_t changeSettings(enum eOpMode mode, uint16_t val); + uint8_t ChangeSettings(enum eOpMode mode, uint16_t val); private: uint8_t m_number; // Which of the dacs is it? uint8_t m_address; + uint8_t WriteSettings(uint16_t settings); uint8_t I2CError(uint8_t error); }; diff --git a/software/app/excitation_light.cpp b/software/app/excitation_light.cpp new file mode 100644 index 0000000..c46586b --- /dev/null +++ b/software/app/excitation_light.cpp @@ -0,0 +1,54 @@ +//---------------------------------------------------------------------------------------------------------------------------- +// Project: Uppsense +// Name: excitation_light.cpp +// Author: Maximilian Stiefel +// Date: 09.08.2017 +// +// Description: +// +//---------------------------------------------------------------------------------------------------------------------------- + +//-------------------------------------Libraries------------------------------------------------------------------------------ +#include "excitation_light.h" +#include "hardware.h" +#include + +//-------------------------------------Namespaces----------------------------------------------------------------------------- +namespace rijnfel { +namespace light { + +//-------------------------------------Constructor---------------------------------------------------------------------------- +cExcitationLight::cExcitationLight(): + m_rectangleStatus(0), m_DAC_Rect_High(0) +{ + m_DAC = new dac::cDAC101C085(1, DAC1_ADDRESS); +} + +//-------------------------------------Destructor----------------------------------------------------------------------------- +cExcitationLight::~cExcitationLight() +{ + delete m_DAC; +} + +//-------------------------------------setCurrent----------------------------------------------------------------------------- +uint8_t cExcitationLight::setCurrent(uint16_t microamp) +{ + if(microamp < CURR_MAX_UAMP) + { + m_DAC_Rect_High = R_SENSE * microamp; + return 1; + } + else + return 0; +} + +//-------------------------------------rectangleUpdate------------------------------------------------------------------------ +uint8_t cExcitationLight::rectangleUpdate() +{ + m_rectangleStatus ? m_DAC->ChangeSettings(dac::eOpMode::NORMAL, 0) : m_DAC->ChangeSettings(dac::eOpMode::NORMAL, m_DAC_Rect_High); + rectangle_Status ^= 0xFF; +} + + +} +} diff --git a/software/app/excitation_light.h b/software/app/excitation_light.h new file mode 100644 index 0000000..544e8ab --- /dev/null +++ b/software/app/excitation_light.h @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------------------------------------------------------- +// Project: Uppsense +// Name: excitation_light.h +// Author: Maximilian Stiefel +// Date: 09.08.2017 +// +// Description: +// +//---------------------------------------------------------------------------------------------------------------------------- + +#ifndef APP_EXCITATION_LIGHT_H_ +#define APP_EXCITATION_LIGHT_H_ + +//-------------------------------------Libraries------------------------------------------------------------------------------ +#include +#include "dac101c085.h" +#include "hardware.h" + +//-------------------------------------Defines-------------------------------------------------------------------------------- + +//-------------------------------------Namespaces----------------------------------------------------------------------------- +namespace rijnfel { +namespace light { + +//-------------------------------------Enums---------------------------------------------------------------------------------- + +//-------------------------------------cExcitationLight----------------------------------------------------------------------- +class cExcitationLight +{ +public: + cExcitationLight(); // Constructor + ~cExcitationLight(); // Destructor + uint8_t setCurrent(uint16_t microamp); + uint8_t rectangleUpdate(); +private: + dac::cDAC101C085 *m_DAC; + uint8_t m_rectangleStatus; + uint16_t m_DAC_Rect_High; +}; + +} +} +#endif /* APP_EXCITATION_LIGHT_H_ */ diff --git a/software/app/hardware.h b/software/app/hardware.h new file mode 100644 index 0000000..53b225c --- /dev/null +++ b/software/app/hardware.h @@ -0,0 +1,21 @@ +//---------------------------------------------------------------------------------------------------------------------------- +// Project: Uppsense +// Name: hardware.h +// Author: Maximilian Stiefel +// Date: 09.08.2017 +// +// Description: +// +//---------------------------------------------------------------------------------------------------------------------------- + +#ifndef APP_HARDWARE_H_ +#define APP_HARDWARE_H_ + +//-------------------------------------I2C ADRESSES--------------------------------------------------------------------------- +static const uint8_t ADC_ADDRESS = 0x48; +static const uint8_t DAC1_ADDRESS = 0xC; + +#define R_SENSE (uint8_t) 100 // 100 Ohm sensing resistor +#define CURR_MAX_UAMP 10000 // 10 mA max. + +#endif /* APP_HARDWARE_H_ */ diff --git a/software/files/index.js b/software/files/index.js index 036f4ae..779fb88 100644 --- a/software/files/index.js +++ b/software/files/index.js @@ -7,7 +7,7 @@ $( document ).ready(function() { document.getElementById('adc_2').textContent = data.adc_2; document.getElementById('adc_3').textContent = data.adc_3; - setTimeout(worker, 5000); + setTimeout(worker, 1000); }); })(); -}); \ No newline at end of file +});