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);
}
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..
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.