From 019413d75c5cfcb016736b5be37d8c1bba65fe62 Mon Sep 17 00:00:00 2001 From: Maximilian Stiefel Date: Mon, 14 Aug 2017 10:54:31 +0200 Subject: [PATCH] Made rectangle signal from DAC work. --- software/app/application.cpp | 18 +++++++++++++----- software/app/dac101c085.h | 2 +- software/app/excitation_light.cpp | 19 ++++++++++++++----- software/app/excitation_light.h | 1 + software/app/hardware.h | 10 ++++++---- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/software/app/application.cpp b/software/app/application.cpp index e8c22da..eeed28f 100644 --- a/software/app/application.cpp +++ b/software/app/application.cpp @@ -2,7 +2,7 @@ #include #include #include "ads101x.h" -#include "hardware.h" +#include "defines.h" #include "excitation_light.h" #include "sensor_hub.h" #include "sensor_settings.h" @@ -40,6 +40,11 @@ void SettingsTest() { Serial.printf("Settings: %d\n\r", adc.GetSettings()); } +void GenerateRectangle() +{ + mylight.RectangleUpdate(); +} + void AdcTest() { channel++; if (channel > 3) { @@ -78,6 +83,7 @@ void init() { //WDT.enable(false); pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, 1); adc.SetMux(ads::eInputMux::AIN_0); adc.SetSampleSpeed(ads::eSampleSpeed::SPS_3300); adc.SetGain(ads::eGainAmplifier::FSR_4_096); @@ -95,11 +101,13 @@ 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(1000, AdcTest).start(); - procTimer.initializeMs(5000, SettingsTest).start(); - mylight.SetCurrent(5000); - mylight.RectangleUpdate(); + //procTimer.initializeMs(5000, SettingsTest).start(); + mylight.SetCurrent(1000); + //mylight.DeactivateLED(); + //procTimer.initializeUs(2500, GenerateRectangle).start(); + } void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6], diff --git a/software/app/dac101c085.h b/software/app/dac101c085.h index c340788..d4edf34 100644 --- a/software/app/dac101c085.h +++ b/software/app/dac101c085.h @@ -13,9 +13,9 @@ //-------------------------------------Libraries------------------------------------------------------------------------------ #include +#include "defines.h" //-------------------------------------Defines-------------------------------------------------------------------------------- -#define DEBUG_LEVEL 1 // 1 a lot debugging output, else rare debugging output #define PD_BITS_POS 13 // Position of power down bits #define D_BITS_POS 2 // Position of data bits diff --git a/software/app/excitation_light.cpp b/software/app/excitation_light.cpp index d079673..dc38160 100644 --- a/software/app/excitation_light.cpp +++ b/software/app/excitation_light.cpp @@ -10,7 +10,7 @@ //-------------------------------------Libraries------------------------------------------------------------------------------ #include "excitation_light.h" -#include "hardware.h" +#include "defines.h" #include //-------------------------------------Namespaces----------------------------------------------------------------------------- @@ -21,7 +21,7 @@ namespace light { cExcitationLight::cExcitationLight(): m_rectangleStatus(0), m_DACRectHigh(0) { - m_DAC = new dac::cDAC101C085(1, DAC1_ADDRESS); + m_DAC = new dac::cDAC101C085(1, 0xE); } //-------------------------------------Destructor----------------------------------------------------------------------------- @@ -33,11 +33,15 @@ cExcitationLight::~cExcitationLight() //-------------------------------------setCurrent----------------------------------------------------------------------------- uint8_t cExcitationLight::SetCurrent(uint16_t microamp) { - uint16_t new_DACRectHigh = 0; + uint32_t new_DACRectHigh = 0; if(microamp < CURR_MAX_UAMP) { - new_DACRectHigh = microamp/R_SENSE_DIV_FACT; - Serial.println(m_DACRectHigh); + new_DACRectHigh = ( (microamp*R_SENSE*RESOLUTION_DAC)/VREF_DAC ) / 1000; + #if DEBUG_LEVEL == 1 + Serial.print("DAC value: "); + Serial.println(new_DACRectHigh); + #endif + m_DACRectHigh = new_DACRectHigh; return 1; } else @@ -51,6 +55,11 @@ uint8_t cExcitationLight::RectangleUpdate() m_rectangleStatus ^= 0xFF; } +//-------------------------------------DeactivateLED-------------------------------------------------------------------------- +uint8_t cExcitationLight::DeactivateLED() +{ + return m_DAC->ChangeSettings(dac::eOpMode::PULL_DOWN_2K5, 0); +} } } diff --git a/software/app/excitation_light.h b/software/app/excitation_light.h index 43593ff..fffec17 100644 --- a/software/app/excitation_light.h +++ b/software/app/excitation_light.h @@ -32,6 +32,7 @@ public: ~cExcitationLight(); // Destructor uint8_t SetCurrent(uint16_t microamp); uint8_t RectangleUpdate(); + uint8_t DeactivateLED(); private: dac::cDAC101C085 *m_DAC; uint8_t m_rectangleStatus; diff --git a/software/app/hardware.h b/software/app/hardware.h index 8e1f60b..7ba0661 100644 --- a/software/app/hardware.h +++ b/software/app/hardware.h @@ -12,10 +12,12 @@ #define APP_HARDWARE_H_ //-------------------------------------I2C ADRESSES--------------------------------------------------------------------------- -static const uint8_t ADC_ADDRESS = 0x48; -static const uint8_t DAC1_ADDRESS = 0xC; +static const uint8_t ADC_ADDRESS = 0x49; +static const uint8_t DAC1_ADDRESS = 0xE; -#define R_SENSE_DIV_FACT 100 // 100 Ohm sensing resistor -#define CURR_MAX_UAMP 10000 // 10 mA max. +static const uint16_t R_SENSE = 100; // 100 Ohm sensing resistor +static const uint16_t CURR_MAX_UAMP = 10000; // 10 mA max. +static const uint16_t VREF_DAC = 3300; // in mV +static const uint16_t RESOLUTION_DAC = 1024; #endif /* APP_HARDWARE_H_ */