//############################################################################################################################################################## //BF sort, correct and recalculate ADC-values //BF changed by Stefan to avoid correction error in inverting and averaging mode void Hardware::READADC_ALL(unsigned char which, unsigned char *DataArray1, unsigned char inverse, unsigned int zero, unsigned char averageval, unsigned char highspeed) { static unsigned long mask = 0xFEFEFEFE; //set MASK (but never use it???) static unsigned int lw_count = 4096; //number of longwords to work on, should be a parameter static unsigned char *chan_addr; //input-buffer static unsigned int loop, i; //control static unsigned char byte_data; //byte to work on static unsigned char temp_byte; static int temp_int; static unsigned char correct[4]; //channeldependend correctionvalues static unsigned char *DataArray2; static unsigned int zero2; DataArray2 = DataArray1; zero2 = zero << 1; chan_addr = ((unsigned char*)(0x00917440)); //channel_address = readout_sigbuf, READADC_ALL2 filled this buffer if (highspeed == 1) //timebase < 7 /* //Guido: testing: { for (loop = 0; loop < 4096; loop++) { byte_data = *(chan_addr); byte_data = ~byte_data; *(DataArray2) = byte_data;; *(DataArray2 + 1) = byte_data;; //byte_data = *(chan_addr + 2); //byte_data = ~byte_data; *(DataArray2 + 2) = byte_data;; *(DataArray2 + 3) = byte_data;; DataArray2 += 4; chan_addr += 4; } } */ { // this was done bei PREPARE_READADC (now obsolete): load the channel's correctionvalues for (i = 0; i < 4; i++) correct[i] = ADC_Offset[(which - 1)][i]; for (loop = 0; loop < lw_count; loop++) { byte_data = *(chan_addr); //load first byte byte_data = ~byte_data; //invert it bitwise if (byte_data > correct[0]) byte_data -= correct[0]; //offsetadjustment (stefan put it here) else byte_data = 0; if (inverse == 1) { temp_int = zero2 - byte_data; if (temp_int < 0) temp_int = 0; //limit to byte else if (temp_int > 255) temp_int = 255; byte_data = temp_int; } if (averageval != 0) //then start averaging { temp_byte = *(DataArray2); //load old value as byte byte_data = (unsigned char)(((unsigned short)byte_data + (unsigned short)temp_byte) >> 1); } *(DataArray2) = byte_data; //store result byte_data = *(chan_addr); //load second byte byte_data = ~byte_data; //invert it bitwise if (byte_data > correct[1]) byte_data -= correct[1]; //offsetadjustment (stefan put it here) else byte_data = 0; if (inverse == 1) { temp_int = zero2 - byte_data; if (temp_int < 0) temp_int = 0; //limit to byte else if (temp_int > 255) temp_int = 255; byte_data = temp_int; } if (averageval != 0) //then start averaging { temp_byte = *(DataArray2 + 1); //load old value as byte byte_data = (unsigned char)(((unsigned short)byte_data + (unsigned short)temp_byte) >> 1); } *(DataArray2 + 1) = byte_data; //store result byte_data = *(chan_addr); //load third byte byte_data = ~byte_data; //invert it bitwise if (byte_data > correct[2]) byte_data -= correct[2]; //offsetadjustment (stefan put it here) else byte_data = 0; if (inverse == 1) { temp_int = zero2 - byte_data; if (temp_int < 0) temp_int = 0; //limit to byte else if (temp_int > 255) temp_int = 255; byte_data = temp_int; } if (averageval != 0) //then start averaging { temp_byte = *(DataArray2 + 2); //load old value as byte byte_data = (unsigned char)(((unsigned short)byte_data + (unsigned short)temp_byte) >> 1); } *(DataArray2 + 2) = byte_data; //store result byte_data = *(chan_addr); //load last byte byte_data = ~byte_data; //invert it bitwise if (byte_data > correct[3]) byte_data -= correct[3]; //offsetadjustment (stefan put it here) else byte_data = 0; if (inverse == 1) { temp_int = zero2 - byte_data; if (temp_int < 0) temp_int = 0; //limit to byte else if (temp_int > 255) temp_int = 255; byte_data = temp_int; } if (averageval != 0) //then start averaging { temp_byte = *(DataArray2 + 3); //load old value as byte byte_data = (unsigned char)(((unsigned short)byte_data + (unsigned short)temp_byte) >> 1); } *(DataArray2 + 3) = byte_data; //store result DataArray2 += 4; chan_addr += 4; } } else //timebase > 6: only use ADC0 { for (loop = 0; loop < lw_count; loop++) { byte_data = *(chan_addr); //load one byte byte_data = ~byte_data; //invert it bitwise // nothing to correct as only one ADC is used //if (byte_data > correct[0]) byte_data -= correct[0]; //offsetadjustment (stefan put it here) //else byte_data = 0; if (inverse == 1) { temp_int = zero2 - byte_data; if (temp_int < 0) temp_int = 0; //limit to byte else if (temp_int > 255) temp_int = 255; byte_data = temp_int; } if (averageval != 0) //then start averaging { temp_byte = *(DataArray2); //load old value as byte byte_data = (unsigned char)(((unsigned short)byte_data + (unsigned short)temp_byte) >> 1); } *(DataArray2) = byte_data; //store result DataArray2 += 1; chan_addr += 4; } } }