# Arduino Forum

## Forum 2005-2010 (read only) => Software => Interfacing => Topic started by: jazzy_a on Mar 05, 2010, 06:52 pm

Title: Critical Velocity Motor Controller & Arduino
Post by: jazzy_a on Mar 05, 2010, 06:52 pm
Hi guys--

We're having some issues with controlling the speed of our motor using a Critical Velocity Motor Controller.

Parts:
- Arduino duemilanove
- Critical Velocity Motor Controller - 5.5-36V and 15A
- A PMDC 36V, 12.8A motor (350W)

The manual for the controllers say that in order to control the motor speed, we can just pulse the Up and Down lines on the controller:
http://www.robotshop.ca/content/PDF/datasheet-SPD-2115B-EDS.pdf

But by using this code, we can't achieve that. The motor either runs at full speed or at zero speed when the up and down lines are pulsed respectively.

Code:
int RUp = 3;                     //Right Motor Speed Up
int RDown = 5;                   //Right Motor Speed Down
int REnable = 7;                //Right Motor Disable

void setup()
{
pinMode(REnable, OUTPUT);   // sets the digital pin as output
pinMode(RUp, OUTPUT);       // sets the digital pin as output
pinMode(RDown, OUTPUT);     // sets the digital pin as output
digitalWrite(REnable, HIGH);   // Raise Right Motor speed by 0.4%
analogWrite(RUp,10);
}

void loop()
{

}

So at this point, we have no control of the motor speed. It either goes max speed or zero speed with this code.

I think the frequency of the Arduino is too high for the controller. The controller is at about 200Hz. And the Arduino at about ~400Hz. So the arduino is sending pulses so many times that the controller just ends up running the motor at max speed and at min speed.

How can we change the frequency the arduino outputs at? Can someone help please?

Thanks.
Title: Re: Critical Velocity Motor Controller & Arduino
Post by: AWOL on Mar 05, 2010, 08:09 pm
Quote
How can we change the frequency the arduino outputs at?

Isn't the 200Hz the output frequency of the controller?

Have you got the jumpers set correctly?

If you feed PWM to the UP pin, it'll reach max speed very quickly and stay there.

You need to pass individual pulses to  UP  until you reach the desired speed. (bottom of page 2) - it clocks on rising edges.

Code: [Select]
`digitalWrite(REnable, HIGH);   // Raise Right Motor speed by 0.4%` Wrong.
Title: Re: Critical Velocity Motor Controller & Arduino
Post by: jazzy_a on Mar 06, 2010, 03:22 am
Hey you're right. We got it working by pulsing the up signal high, doing a delay, then pulsing it low.

And we put this code in a for-loop to be able to control the number of pulses.

Btw another is that we didn't realize that we had to reset the signals on all of the pins every time we made a change to the code. Because the old settings of the pins still stay on the MCU even when u change the code and recompile.
Title: Re: Critical Velocity Motor Controller & Arduino
Post by: GrooveFlotilla on Mar 08, 2010, 09:28 am
Quote
another is that we didn't realize that we had to reset the signals on all of the pins every time we made a change to the code. Because the old settings of the pins still stay on the MCU even when u change the code and recompile

I think it more likely that the ESC remembers the settings, rather than the Arduino!
Title: Re: Critical Velocity Motor Controller & Arduino
Post by: retrolefty on Mar 08, 2010, 04:59 pm
Looking over that manual you linked to there appears to be two ways to control the speed of the motor with that PWM motor controller.

1. Pulsing the up and down digital inputs on the controller. This allows one to use two manual monentary switches or as you are doing two digital outputs pins from an Arduino.

2. If accepts a analog voltage from an external pot. Or if you used a Arduino PWM output pin followed with a low pass filter (a resistor/cap) you could control speed using the Arduino analogWrite() commands.

Both methods have the same basic limitation, your Arduino has no idea what the actual speed of the motor is at anytime. That is, there is no speed feeback information avalible to the Arduino. One could attach a optical or magnetic speed sensor to the motor shaft and read the pulses directly into the Arduino and then calculate the speed. This could then be used in your Arduino sketch to decide when and how much to increase or decrease the speed commands to the PWM controller.

Lefty