There have been a few threads on this in the past; I referenced to write my code.
I have a Victor 888 hooked up to a 12 V power supply and a CIM motor. Also have wires in the PWM slots, running to slot 10 on Arduino and the 5V and ground.
When I run the program, the CIM only moves in quick, short bursts. It won’t move fluidly. The Victor/CIM will then stop moving for a bit and make a high-pitched sound. I’m getting a yellow flashing signal on the Victor, which means no PWM; however the wires are soundly connected (and shouldn’t the motor not move at all if there’s no PWM?)
Here’s my code, which I think is the issue (but am not really sure either way):
#include <Servo.h>;
Servo rightVictor;// create servo object to control a servo
int rightVictorPin = 10; // twelve servo objects can be created on most boards
void setup() {
rightVictor.attach(rightVictorPin); // attaches the servo on pin 10 to the servo object
}
void loop() {
rightVictor.write(180); //turn forward full speed
delay(5000);
rightVictor.write(0); //turn off
delay(5000);
}
Never use delay(5000)! Implement a state machine to create this behavior, so that the arduino O/S can do its thing every few milliseconds.
I’m not sure if this is your issue; IIRC, the arduino will continue to pump out PWM signal from a Servo object on pin 10, but I’m not 100% sure. It may depend on which ardunio model you’re using.
This is extremely important, and a whole bunch of arduino libraries (AdaFruit Motor Shield, I’m looking at you…) botch this. Delay() should never, ever, ever be used when you actually care about the accuracy of your timing.
While I can’t say why the motor is doing the weird jumping behavior, the neutral spot for the motor is not 0. It should be somewhere around 90 (you will need to experiment with this some to get it to work, I think in the two talons I’m currently running off an arduino it’s something like 93).
Here is my code I used. The only difference is I use #include “Servo.h” where you use #include <Servo.h>
It’s a circuitspecialists.com Switching Power Supply (whatever we had laying around in the robotics classroom). Could that be the cause of my issues?
Basically trying to build a simply base bot with two CIMs, four wheels. It’s for team practice/learning.
So I removed delay and changed code to: #include <Servo.h>;
Servo rightVictor;// create servo object to control a servo
int rightVictorPin = 10; // twelve servo objects can be created on most boards
void setup() {
rightVictor.attach(rightVictorPin); // attaches the servo on pin 10 to the servo object
}
void loop() {
rightVictor.write(100); // move motor at some speed
}
And the motor will spin constantly. However, if I use any value but 100 (0, 90, 120, etc) then the motor jumps back and forth instead of spinning constantly, and I get a no PWM signal from the Victor again. Does anyone know what I’m doing wrong??
Most power supplies have a current limiter (some can be user set within a range).
When the power supply hits or exceeds it’s current limit it folds back and reduces the voltage until it is at it’s current limit. Then every 100ms or so (depending on the brand/settings) it will put full voltage back on the line to see if the short / low resistance (measured as high current) has been fixed. This, in the power supply industry, is called hiccup mode.
CIM, and all electric motors, start in stall which is where they draw the most current. CIMs draw ~113 amps in stall. Your power supply is probably just protecting itself.
try your setup with a battery and breaker. That’ll prove if it’s the power supply or not.
Hi everyone! Thank you so much for replying. I tried to reply on Thursday, but it seems my post didn’t go through.
I removed the delay statements and now have:
#include <Servo.h>;
Servo rightVictor;// create servo object to control a servo
int rightVictorPin = 10; // twelve servo objects can be created on most boards
void setup() {
rightVictor.attach(rightVictorPin); // attaches the servo on pin 10 to the servo object
}
void loop() {
rightVictor.write(100);
}
If the write value is 100, the motor moves continuously. Literally any other value causes the jumping behavior to return. I’m going to try hooking it up to an FRC battery instead of the power supply since some of you think that could be my issue! I’ll keep you updated
Hey everyone, problem solved! It was the power supply. Hooked it up to 12 V battery with a breaker and it works fine, 90 is 0, 0 is full reverse, and 180 is full forward. Thank you!!