PWM and Speed Controller

Hey guys,

I have this remote control car, and I've ripped it apart and stuck my Arduino Uno into the speed controller. I can control it by bitbanging, but I want to be able to use PWM. So:

I'm trying to use the Arduino Uno to output a PWM signal with a period of approximately 17.20ms. The duty cycle for this wave changes from ~1ms for left/backward, ~1.5ms for neutral, and ~2ms for right/forward.

I think that I have to change the PWM frequency to a much smaller value, but I'm not sure how to go about doing that. I assume I can change the duty cycle to the three values once the frequency is low enough.

If anyone can help me out with code that implements the three cases, that'd be awesome. Thanks!

If anyone can help me out with code that implements the three cases, that'd be awesome. Thanks!

The signal you are trying to generate is a standard servo PPM type and should best be done using one of the servo libraries available for controlling servos, not with pwm outputs. Most all R/C esc are designed to look just like a servo for controlling purposes.

Lefty

The R/C car uses a speed controller linked to a DC motor. I hooked up the receiver to an oscilloscope, and found that the output was a PWM signal with the given statistics. I assumed that I should use the Arduino to replicate the same sort of signal, and send it to the speed controller.

Is that correct, or should I use the servo examples?

Servo examples.

Use servo commands. Specifically use the writeMicroseconds() command from the servo library to generate your desired signal, here is a reference:

Lefty

Simple servo test code below that you can use with the serial monitor to test your setup.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  } 
}