X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=DS2438_ADC_DS2438_ADC%2FDS2438_DS2438.c;fp=DS2438_ADC_DS2438_ADC%2FDS2438_DS2438.c;h=b9a70409da6c185c76b7ba80d5fd8ebcffb0adc6;hp=0000000000000000000000000000000000000000;hb=81a79648a168a1167c5ad97d4068621c1751a353;hpb=6467d8138460abffd9ddabc7b0a9f00c764af19c diff --git a/DS2438_ADC_DS2438_ADC/DS2438_DS2438.c b/DS2438_ADC_DS2438_ADC/DS2438_DS2438.c new file mode 100644 index 0000000..b9a7040 --- /dev/null +++ b/DS2438_ADC_DS2438_ADC/DS2438_DS2438.c @@ -0,0 +1,241 @@ +// Copyright (c) 2018, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +//!!!!!Max Program size 7551 Byte + +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include +#include "../common/owSlave_tools.h" + + +OWST_EXTERN_VARS +OWST_WDT_ISR + + +//#define W1DAQ +#define JOE_M +volatile uint8_t owid1[8]={0x26, 0x61, 0xDA, 0x84, 0x00, 0x00, 0x03, 0x43};/**/ +volatile uint8_t owid2[8]={0x26, 0x62, 0xDA, 0x84, 0x00, 0x00, 0x03, 0x1A};/**/ +volatile uint8_t config_info1[26]={6,6,6,0x08, 6,8, 0x00,0x00, 0x02,20,20,20,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +volatile uint8_t config_info2[26]={6,6, 6,0x08,6,8, 0,0, 0x02,20,20,20,0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +#ifdef JOE_M +#define PIN_PIOA1 (1<2) { + + wdcounter=0; + ADMUX=OWST_ADCIN_REFINT; + _delay_us(100); + VCC=owst_ADC_runf(); + VCC=(1.079*65472.0)/VCC; + DS2438_2_VDD=VCC*100; + DS2438_1_VDD=VCC*100; + + if (testSW()) { + ADMUX= ADDIFF1; //ADC0 + ADC1 - Gain 1 + _delay_us(100); + VAD_A=owst_ADC_runf(); + if (VAD_A<3100) { + ADMUX= ADDIFF1G; //ADC0 + ADC1 - Gain 20 + _delay_us(100); + VAD_A=owst_ADC_runf(); + VAD_A=VCC/20.0*VAD_A/65472.0; + } else { + VAD_A=owst_ADC_OSS_runf(); + VAD_A=VCC*VAD_A/65472.0; + } + DS2438_1_VAD=VAD_A*100; + DS2438_1_TEMP=VAD_A*256; + + ADMUX= ADDIFF2; //ADC0 + ADC1 - Gain 1 + _delay_us(100); + VAD_B=owst_ADC_runf(); + if (VAD_B<3100) { + ADMUX= ADDIFF2G; //ADC0 + ADC1 - Gain 20 + _delay_us(100); + VAD_B=owst_ADC_runf(); + VAD_B=VCC/20.0*VAD_B/65472.0; + } else { + VAD_B=owst_ADC_OSS_runf(); + VAD_B=VCC*VAD_B/65472.0; + } + DS2438_2_VAD=VAD_B*100; + DS2438_2_TEMP=VAD_B*256; + + + + } else { + ADMUX=ADMA1; + _delay_us(100); + VAD_A=owst_ADC_OSS_runf(); + VAD_A=VCC*VAD_A/65472.0; + DS2438_1_TEMP=VAD_A*256; + + ADMUX=ADMB1; + _delay_us(100); + VAD_B=owst_ADC_OSS_runf(); + VAD_B=VCC*VAD_B/65472.0; + DS2438_1_VAD=VAD_B*100; + + ADMUX=ADMA2; + _delay_us(100); + VAD_C=owst_ADC_OSS_runf(); + VAD_C=VCC*VAD_C/65472.0; + DS2438_2_TEMP=VAD_C*256; + + ADMUX=ADMB2; + _delay_us(100); + VAD_D=owst_ADC_OSS_runf(); + VAD_D=VCC*VAD_D/65472.0; + DS2438_2_VAD=VAD_D*100; + } + + + + + } + + + OWST_MAIN_END + } + + +}