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
const int MLeft = 10; // Motor Left
const int PWMpin = 8;
const int currentsensorPin = A1;
pinMode (MLeft, OUTPUT);
pinMode (currentsensorPin, INPUT);
currentsensorValue = analogRead(currentsensorPin);
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.
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.