Hi,
Using arduino Uno, arduino motorshield, and a simple dc motor (not important because I change the motor I test on constantly), and a bench power system 10v.
I run simple code which I will attach, and I have the problem where with one call of the AnalogWrite(), the motor moves in two increments no matter what. When I call for the motor to go 'up', it goes up briefly, stops then continues going up for the specified delay time. Same happens when i call it to go down.
I have tried putting a PWM of 0 at the start of the code to initialise it, and it still does the same thing. When i put a multimeter over the motorshield, and a 50 percent duty cycle, whenever I run the code i can see the motor channel A driving pins briefly go up to 5V, drop to 0 then go back to 5v.
Any idea why or how I can prevent it as this 'jitter' is not something I can account for during my project.
const int directionPin = 12;
const int pwmPin = 3;
const int brakePin = 9;
void setup() {
pinMode(directionPin, OUTPUT);
pinMode(pwmPin, OUTPUT);
pinMode(brakePin, OUTPUT);
analogWrite(pwmPin, 0);
// Perform initial actions (for example, go down)
digitalWrite(directionPin, HIGH); // Set direction to go up
analogWrite(pwmPin, 125);
delay(1000);
analogWrite(pwmPin, 0);
}
void loop() {
}
void goUp() {
digitalWrite(directionPin, LOW); // Set direction to go up
analogWrite(pwmPin, 255);
}
void goDown() {
digitalWrite(directionPin, HIGH); // Set direction to go down
analogWrite(pwmPin, 255); // Start the motor
}
void brake() {
analogWrite(pwmPin, 0);
// Stop the motor
}