strange issue about Arduino DUE, ADC Joystick, and UART running

hey,
I encounters a strange issue about Arduino DUE, ADC Joystick, and UART running parallel.

by the first following program I get quite reliable joystick readings of both built-in potentiometers :
center: L 0 (+/-4 ), R 0 (+/-4) ,
full swing L+R -255...0...+255.

But:
Once having copied and pasted the code into a proprietary function (then called from loop() which is also calling a UART send/receive function alternatively), suddenly the center values are shifted to
L +100 / R -35,
and the offsets are addionally drifting when the joystick is moved.

Trying a different joystick it's all the same only very small different readings from 2-5 at the center position).

Is this perhaps a known issue about ADC reading, interferring with UART or what ever?

this is the original code which gives +/- reliable readings:

const byte joysticYA = A0; //Analog Jostick Y axis
const byte joysticXA = A1; //Analog Jostick X axis

const byte controllerFA = 10; //PWM FORWARD PIN for OSMC Controller A (left motor)
const byte controllerRA = 9;  //PWM REVERSE PIN for OSMC Controller A (left motor)
const byte controllerFB = 6;  //PWM FORWARD PIN for OSMC Controller B (right motor)
const byte controllerRB = 5;  //PWM REVERSE PIN for OSMC Controller B (right motor)
const byte disablePin = 2; //OSMC disable, pull LOW to enable motor controller

int analogTmp = 0; //temporary variable to store 
int throttle, direction = 0; //throttle (Y axis) and direction (X axis) 

int leftMotor,leftMotorScaled = 0; //left Motor helper variables
float leftMotorScale = 0;

int rightMotor,rightMotorScaled = 0; //right Motor helper variables
float rightMotorScale = 0;

float maxMotorScale = 0; //holds the mixed output scaling factor

int deadZone = 10; //jostick dead zone 

void setup()  { 

  //initialization of pins  
  Serial.begin(19200);
  pinMode(controllerFA, OUTPUT);
  pinMode(controllerRA, OUTPUT);
  pinMode(controllerFB, OUTPUT);
  pinMode(controllerRB, OUTPUT);  

  pinMode(disablePin, OUTPUT);
  digitalWrite(disablePin, LOW);
} 

void loop()  { 
  //aquire the analog input for Y  and rescale the 0..1023 range to -255..255 range
  analogTmp = analogRead(joysticYA);
  throttle = (512-analogTmp)/2;

  delayMicroseconds(100);
  //...and  the same for X axis
  analogTmp = analogRead(joysticXA);
  direction = -(512-analogTmp)/2;

  //mix throttle and direction
  leftMotor = throttle+direction;
  rightMotor = throttle-direction;

  //print the initial mix results
  Serial.print("LIN:"); Serial.print( leftMotor, DEC);
  Serial.print(", RIN:"); Serial.print( rightMotor, DEC);

  //calculate the scale of the results in comparision base 8 bit PWM resolution
  leftMotorScale =  leftMotor/255.0;
  leftMotorScale = abs(leftMotorScale);
  rightMotorScale =  rightMotor/255.0;
  rightMotorScale = abs(rightMotorScale);

  Serial.print("| LSCALE:"); Serial.print( leftMotorScale,2);
  Serial.print(", RSCALE:"); Serial.print( rightMotorScale,2);

  //choose the max scale value if it is above 1
  maxMotorScale = max(leftMotorScale,rightMotorScale);
  maxMotorScale = max(1,maxMotorScale);

  //and apply it to the mixed values
  leftMotorScaled = constrain(leftMotor/maxMotorScale,-255,255);
  rightMotorScaled = constrain(rightMotor/maxMotorScale,-255,255);

  Serial.print("| LOUT:"); Serial.print( leftMotorScaled);
  Serial.print(", ROUT:"); Serial.print( rightMotorScaled);

  Serial.print(" |");

  //apply the results to appropriate uC PWM outputs for the LEFT motor:
  if(abs(leftMotorScaled)>deadZone)
  {

    if (leftMotorScaled > 0)
    {
      Serial.print("F");
      Serial.print(abs(leftMotorScaled),DEC);

      analogWrite(controllerRA,0);
      analogWrite(controllerFA,abs(leftMotorScaled));            
    }
    else 
    {
      Serial.print("R");
      Serial.print(abs(leftMotorScaled),DEC);

      analogWrite(controllerFA,0);
      analogWrite(controllerRA,abs(leftMotorScaled));  
    }
  }  
  else 
  {
  Serial.print("IDLE");
  analogWrite(controllerFA,0);
  analogWrite(controllerRA,0);
  } 

  //apply the results to appropriate uC PWM outputs for the RIGHT motor:  
  if(abs(rightMotorScaled)>deadZone)
  {

    if (rightMotorScaled > 0)
    {
      Serial.print("F");
      Serial.print(abs(rightMotorScaled),DEC);

      analogWrite(controllerRB,0);
      analogWrite(controllerFB,abs(rightMotorScaled));            
    }
    else 
    {
      Serial.print("R");
      Serial.print(abs(rightMotorScaled),DEC);

      analogWrite(controllerFB,0);
      analogWrite(controllerRB,abs(rightMotorScaled));  
    }
  }  
  else 
  {
  Serial.print("IDLE");
  analogWrite(controllerFB,0);
  analogWrite(controllerRB,0);
  } 

  Serial.println("");

  //To do: throttle change limiting, to avoid radical changes of direction for large DC motors

  delay(10);

}

this is the Joystick part which has been copied and pasted from loop() to a proprietary function:

//=====================================================================================
// get remote values
//=====================================================================================
int16_t  analogTmp;
int16_t  throttle, direction = 0; //throttle (Y axis) and direction (X axis) 

int16_t  leftMotor,leftMotorScaled = 0, oldleftMotorScaled = 0; 

float    leftMotorScale = 0;

int16_t  rightMotor,rightMotorScaled = 0, oldrightMotorScaled = 0; //right Motor helper variables
float    rightMotorScale = 0;

float    maxMotorScale = 0; //holds the mixed output scaling factor

int16_t  deadZone = 10; //jostick dead zone

//=====================================================================================

void getremotevalues()
{   
  char sbuf[128];
   
  //aquire the analog input for Y  and rescale the 0..1023 range to -255..255 range
  analogTmp = analogRead(joysticYA);
  //throttle =  (512-analogTmp)/2;  // original
  throttle = -(512-analogTmp)/2;    // rotation 90° 

  delayMicroseconds(100);
  //...and  the same for X axis
  analogTmp = analogRead(joysticXA);
  direction = -(512-analogTmp)/2;

  //mix throttle and direction
  //leftMotor  = throttle + direction;   // original
  leftMotor  = -(throttle + direction);  // rotation 90° 
  rightMotor = throttle - direction;

  //calculate the scale of the results in comparision base 8 bit PWM resolution
  leftMotorScale =  leftMotor/255.0;
  leftMotorScale = abs(leftMotorScale);
  rightMotorScale =  rightMotor/255.0;
  rightMotorScale = abs(rightMotorScale);

  //choose the max scale value if it is above 1
  maxMotorScale = max(leftMotorScale,rightMotorScale);
  maxMotorScale = max(1,maxMotorScale);

  //and apply it to the mixed values
  leftMotorScaled  = constrain(leftMotor/maxMotorScale,-255,255);  
  rightMotorScaled = constrain(rightMotor/maxMotorScale,-255,255);

  memcpy( sendbuf+ANA0*sizeof(char), &leftMotorScaled,  sizeof(int16_t) );
  memcpy( sendbuf+ANA1*sizeof(char), &rightMotorScaled, sizeof(int16_t) );

  sprintf(sbuf, "Lout=%4d | Rout=%4d ", leftMotorScaled, rightMotorScaled);
  Serial.println( sbuf );

  oldleftMotorScaled  = leftMotorScaled;
  oldrightMotorScaled = rightMotorScaled;

}

entire code including joystick and UART:

Neues Textdokument .ino (14.6 KB)

here are the whole codes, easily to scroll through, in a forum which does not have the effing 9000 char restriction for posts:

http://www.roboternetz.de/community/threads/68800-Joystick-Fernsteuerung-für-Differentialantireb-(-Panzer-)?p=624388&viewfull=1#post624388

update:

no idea what happened, I just copied the original code anew into the UART com program, and now it suddenly works perfect... :-/