analogRead erratic readings

A program to monitor temperatures, voltage and current on a PSU gives erratic voltage readings as soon as a load is placed on the PSU. The PSU voltage however is stable within 0.00V (measured with Fluke 289, and checked for spikes on oscilloscope).

I tried measures discussed on this board (read analog twice, discard first read, insert delay,…) nothing helps.

Variations under load are +/- 1.5%, if no load varitions are +/-0.01%.

Temperature and current readings are solid stable (current is measured with INA219 low-side).

Voltage is measured with voltage divider.

Leads between analog input and measuring point do not run adjacent power lines and are short (<5cm).

What could be wrong in my code?

EDIT 1: I read each input 8 times then discard minimum and maximum values and then calculate the average.

EDIT 2: here is the code relevant to the analog measurements

EDIT 3: the voltage divider for the voltage measurement uses 1k and 2.6k + 10k trim pot

//start loop x + 2 times

  for (int j1 = 0; j1 < (x+2); j1++)  
  
  // x + 2 measurements of each analog input and accumulation;
  // test conditions for emergency action where and when necessary
                                   
  { 

  //read values from analog inputs and accumulate
    // discardValue = analogRead(0);
    temp1Value = (analogRead(0) / 1023.0) * 500.0; // darlington temp read
    // discardValue = analogRead(1);
    temp2Value = (analogRead(1) / 1023.0) * 500.0; // cooling fins temp read
    // delayMicroseconds(100);
    // voltageValue = (analogRead(2) / 1023.0) * 45.0;
    // discardValue = analogRead(2);
    voltageValue = (analogRead(2) / 1023.0) * 45.0;
    //voltageValue = ina219.getBusVoltage_V();
    currentValue = (ina219.getCurrent_mA()/1000);
    
    if(temp1Value<signalMin0)signalMin0=temp1Value;
    if(temp1Value>signalMax0)signalMax0=temp1Value;
    if(temp2Value<signalMin1)signalMin1=temp2Value;
    if(temp2Value>signalMax1)signalMax1=temp2Value;
    if(voltageValue<signalMin2)signalMin2=voltageValue;
    if(voltageValue>signalMax2)signalMax2=voltageValue;
    
    temp1Total += temp1Value; // temp1 darlington accum
    temp2Total += temp2Value; // temp2 cooling fins accum
    voltageTotal += voltageValue; // spanning
    currentTotal += currentValue; // stroom
  
  //test conditions for overtemp and or overcurrent warnings
      
    if (voltageValue < V1 && currentValue > C1)   // kortsluiting
        {OC = true;
         lcd.setCursor (0, 1);
         lcd.print("kortsluiting    ");
         warning = true;
        } 
        
    else                                 // geen kortsluiting;
        {OC = false;}

}

  //remove minimum and maximum outliers
  
    temp1Total-=signalMin0; // darlington temp
    temp1Total-=signalMax0;
    temp2Total-=signalMin1; // cooling fin temp
    temp2Total-=signalMax1;
    voltageTotal-=signalMin2; // output voltage
    voltageTotal-=signalMax2;


  //calculate average temperatures
    
    temp1Value=temp1Total/x;  // temp darlington
    temp2Value=temp2Total/x;  // temp cooling fins

A 100nF capacitor between the analog pin and ground ?

Same problem. But when I switch of the PSU and switch it back on, under load, the issue dissappears.

Controller is Pro Mini 168P with 78L05 1A supply and a LM4040 5.0V precision regulator on Aref (and AnalogReference(EXTERNAL).

Makes me wonder whether this is a hardware issue..?

The PSU voltage however is stable within 0.00V (measured with Fluke 289, and checked for spikes on oscilloscope).

How about the voltages representing temperature, voltage, and current? Are they stable with the meter or 'scope?

EDIT 1: I read each input 8 times then discard minimum and maximum values and then calculate the average.

You didn't show us all of your code, but I'd recommend that you simplify your code (Just run the Analog Read Serial example) and read one of those inputs at a time until you can figure-out what's going on.

DVDdoug: How about the voltages representing temperature, voltage, and current? Are they stable with the meter or 'scope? You didn't show us all of your code, but I'd recommend that you simplify your code (Just run the Analog Read Serial example) and read one of those inputs at a time until you can figure-out what's going on.

What do you mean "..read Analog Read Serial.."?

Meanwhile I found out there is an issue with value conversion float vs int for the display. I will post the solution here when I find out what exactly is happening in the conversion for the LCD display.