X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=DS2450_ADC_JOE2%2FDS2450.c;fp=DS2450_ADC_JOE2%2FDS2450.c;h=edf30765cd83c5b81374287551756f39fb6f155f;hp=0000000000000000000000000000000000000000;hb=81a79648a168a1167c5ad97d4068621c1751a353;hpb=6467d8138460abffd9ddabc7b0a9f00c764af19c diff --git a/DS2450_ADC_JOE2/DS2450.c b/DS2450_ADC_JOE2/DS2450.c new file mode 100644 index 0000000..edf3076 --- /dev/null +++ b/DS2450_ADC_JOE2/DS2450.c @@ -0,0 +1,305 @@ + +// Copyright (c) 2017, 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. + +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include +#include "../common/owSlave_tools.h" + + +OWST_EXTERN_VARS + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[26]={0x06,0x09,0x06,9,0x06,9,0x06,9,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +OWST_WDT_ISR + + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} pack_t; +volatile pack_t pack; + +OWST_ADC_CONF16_FUNC +OWST_ADC_CONF16_OSS_FUNC +OWST_TESTSW + +#define LPIN_CH2 (1<3) { + LED2_ON + wdcounter=0; + ADMUX=OWST_ADCIN_REFINT; + _delay_us(100); + VCC=owst_ADC_runf(); + VCC=(1.079*65472.0)/VCC; + //if (VCC>5.1) VCC=5.1; + //VAD=VCC*65535.0/5.1; + //if (VAD>65535) VAD=65535; + if (testSW()) { //Zwei differential Eingaenge + VAD_C=0; + ADMUX=0b0011010; //ADC4 + ADC5 - Gain 1 + _delay_us(100); + VAD_A=owst_ADC_runf(); + if (VAD_A<3100) { + ADMUX=0b0011011; //ADC0 + ADC1 - Gain 20 + _delay_us(100); + VAD_A=owst_ADC_runf(); + VAD_A=VCC/20.0*VAD_A/65472.0; + //VAD_A=VCC/20.0; + VAD_C+=12850; + } else { + VAD_A=owst_ADC_OSS_runf(); + VAD_A=VCC*VAD_A/65472.0; + VAD_C+=0; + } + if (pack.CSA2&0x01) VAD_A=VAD_A*65535.0/5.1; else VAD_A=VAD_A*65535.0/2.55; + if (VAD_A>65535) VAD_A=65535; + ///_------------------------ B--------------------- + ADMUX=0b011110; //ADC6 + ADC7 - Gain 1 + _delay_us(100); + VAD_B=owst_ADC_runf(); + if (VAD_B<3100) { + ADMUX=0b011111; //ADC6 + ADC7 - Gain 20 + _delay_us(100); + VAD_B=owst_ADC_runf(); + VAD_B=VCC/20.0*VAD_B/65472.0; + //VAD_B=VAD_B20.0; + VAD_C+=12850*2; + } else { + VAD_B=owst_ADC_OSS_runf(); + VAD_B=VCC*VAD_B/65472.0; + VAD_C+=0; + } + if (pack.CSB2&0x01) VAD_B=VAD_B*65535.0/5.1; else VAD_B=VAD_B*65535.0/2.55; + //VAD_B=VAD_B*65535.0/5.1; + if (VAD_B>65535) VAD_B=65535; + VAD_D=VCC*65535.0/5.1; + if (VAD_D>65535) VAD_D=65535; + + } else { // 4 Eingaenge gegen Masse + ADMUX=OWST_ADCIN_PA4; + _delay_us(100); + VAD_A=owst_ADC_OSS_runf(); + VAD_A=VCC*VAD_A/65472.0; + if (pack.CSA2&0x01) VAD_A=VAD_A*65535.0/5.1; else VAD_A=VAD_A*65535.0/2.55; + if (VAD_A>65535) VAD_A=65535; + + ADMUX=OWST_ADCIN_PA5; + _delay_us(100); + VAD_B=owst_ADC_OSS_runf(); + VAD_B=VCC*VAD_B/65472.0; + if (pack.CSB2&0x01) VAD_B=VAD_B*65535.0/5.1; else VAD_B=VAD_B*65535.0/2.55; + if (VAD_B>65535) VAD_B=65535; + + ADMUX=OWST_ADCIN_PA6; + _delay_us(100); + VAD_C=owst_ADC_OSS_runf(); + VAD_C=VCC*VAD_C/65472.0; + if (pack.CSC2&0x01) VAD_C=VAD_C*65535.0/5.1; else VAD_C=VAD_C*65535.0/2.55; + if (VAD_C>65535) VAD_C=65535; + + ADMUX=OWST_ADCIN_PA7; + _delay_us(100); + VAD_D=owst_ADC_OSS_runf(); + VAD_D=VCC*VAD_D/65472.0; + if (pack.CSD2&0x01) VAD_D=VAD_D*65535.0/5.1; else VAD_D=VAD_D*65535.0/2.55; + if (VAD_D>65535) VAD_D=65535; + } + LED2_OFF + + + } + + if (gcontrol) { + //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1]