Current sensing on VNH5019 controller

Hi,
I’m trying to read the current output to motor from VNH5019 motor controller, but the serial monitor freezes. Sometimes it takes 10sec, sometimes 30sec before it freezes, why would it do that? CS pin of VNH5019 is directly connected to A1

-Mikael

const int MLeft = 10; // Motor Left
const int PWMpin = 8;
const int currentsensorPin = A1;

int currentsensorValue;

void setup()
{
  pinMode (MLeft, OUTPUT);
  pinMode(PWMpin, OUTPUT);
  pinMode (currentsensorPin, INPUT);

  Serial.begin(9600);
}

void loop()
{
  analogWrite(PWMpin, 20);
  digitalWrite(MLeft, HIGH);
  currentsensorValue = analogRead(currentsensorPin);
  Serial.println(currentsensorValue);
}

Sounds like power problems. Please post a complete circuit diagram, and links to the components used.

Circuit and link to motor controller. Arduino Mega is used.
Arduino is powered by USB

Please post links to the motor power supply and the motor data sheet.

It is just some small 6v motor I had that I’m trying with, same with the power supply. The current sensing still works on arduino even if the serial monitor freezes…

Is the Arduino being powered? It needs to be, the Vdd pin on the VNH5019 module is a power input.

Yes, Arduino is powered through USB jack.

Suggests this is interference from the heavy current side of things, perhaps you have a ground loop that’s putting spikes into the USB host? One way a ground loop could exist is if the 12V supply is ground-referenced from a different part of the mains circuit.

Ok, I don’t know what a ground loop is but I will try with a battery as power supply for the motor controller and see if it helps.

It had indeed something to do with the power supply, there was no freeze with a battery as power supply for the motor controller. When I changed back to the power supply serial monitor did freeze again. Probably need a better power supply. Problem solved, Thanks MarkT and jremington. Now I just need to figure out how to get the current sensor value to milli amps.