Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Digital pin goes high for short period after initialization on: September 09, 2013, 02:52:55 pm
I used a 1k pulldown resistor, which makes the output voltage jump to 0.5V for a second with the motor driver connected. Fortunately, 0.5V is not enough to move the motor and I still get ~4.9V when I control the output on full duty cycle which is not too bad. Anyway, I consider this problem solved for now. Thank you all for the help!
2  Using Arduino / Project Guidance / Re: Digital pin goes high for short period after initialization on: September 09, 2013, 10:49:23 am
Sorry for not being totally clear. To simplify my explanation and eliminate the need to post a schematic on my wiring, I am ONLY reading the voltage coming out of digital pin 9 relative to ground. The motor itself has nothing to do with Arduino's behavior, so I removed it for debugging purposes because think this will help me get to the root of the problem more quickly. Here is my code:

Code:
// Test digital pin 9
#define speedPin 9

void setup() {
  pinMode(speedPin, OUTPUT);
}

void loop() {
}

After uploading this code to the Arduino, my multimeter reads 2.2V coming from pin 9 for a second before dropping down to 0V. I tested all of the PWM pins and they all exhibit this same behavior after initializing them using pinMode.

MarshaJ847: I added a 10K pulldown resistor to the output pin which dropped the initial voltage to around 1V. This was better, but still not low enough to prevent the motor from moving. I tried using a lower value pulldown resistor (100 Ohms), which took the voltage down to around 0.05V. However, now I can only get a maximum output of 3.5V out of 5V on full duty cycle going to the motor driver (i.e. using analogWrite(speedPin,255)) because the pulldown resistor draws too much current. I wonder if there is anyway to use a pulldown resistor without taking current away from the motor driver when I actually intend to deliver current.
3  Using Arduino / Project Guidance / Digital pin goes high for short period after initialization on: September 07, 2013, 12:30:52 am
When running a DC motor using the digital pwm output pin 9 on my Arduino Uno, I noticed that the motor would always rotate for about one second immediately after I uploaded my code into the microprocessor. I checked the voltage on digital pin 9 and it would always go up to about 1.2 V for about a second after uploading the code, then drop back down to 0 V. In my code, the only thing I did was initialize pin 9 with pinMode(9, OUTPUT) in the void setup() function so I'm wondering if this is normal behavior. If yes, is there any elegant way to deal with this situation? This behavior is undesirable because I have an encoder attached to the external interrupt that starts counting when the motor is rotating unintentionally.
4  Using Arduino / Sensors / Pololu Motor/Encoder Problems on Arduino Uno on: February 16, 2013, 12:37:13 am
I am having problems trying to read the quadrature encoder signals from this Polulu motor/encoder: http://www.pololu.com/catalog/product/2275 using my Arduino Uno. The motor is connected to a simple circuit consisting of an L293D H-bridge and a potentiometer I use to vary the motor speed. When the motor is used by itself without the encoder, everything works as expected. However, when the encoder is connected, the motor stops working properly. More specifically, the motor just runs at a slow constant speed and stops responding to commands from the potentiometer. The encoder digital outputs are connected to interrupt pins 2 and 3  on the Arduino. What do you think the problem could be? The sketch is provided below:

Code:
//Motor variables
#define switchPin 4 // switch input
#define motorPin1 5 // L293D Input 1
#define motorPin2 6 // L293D Input 2
#define speedPin 9 // L293D enable Pin 1
#define potPin 0 // Potentiometer on Analog Pin 0
int Mspeed = 0; // a variable to hold the current speed value

//Encoder variables
#define encoder0PinA 2
#define encoder0PinB 3
volatile unsigned int encoder0Pos = 0;

void setup() {
 
  // Encoder setup
  pinMode(encoder0PinA, INPUT); // encoder pin on interrupt 0 (pin 2)
  pinMode(encoder0PinB, INPUT); // encoder pin on interrupt 1 (pin 3)
  attachInterrupt(0, doEncoderA, CHANGE);
  attachInterrupt(1, doEncoderB, CHANGE);
 
  // Motor setup
  pinMode(switchPin, INPUT); // set switch pin as INPUT
 
  pinMode(motorPin1, OUTPUT); // set remaining pins as outputs
  pinMode(motorPin2, OUTPUT);
  pinMode(speedPin, OUTPUT);

  // Encoder setup
  pinMode(encoder0PinA, INPUT); // encoder pin on interrupt 0 (pin 2)
  pinMode(encoder0PinB, INPUT); // encoder pin on interrupt 1 (pin 3)
  attachInterrupt(0, doEncoderA, CHANGE);
  attachInterrupt(1, doEncoderB, CHANGE);
 
  Serial.begin (9600);
}

void loop() {
  Mspeed = analogRead(potPin)/4; // read the speed value from the potentiometer
  analogWrite(speedPin, Mspeed); // write speed to Enable 1 pin
  if (digitalRead(switchPin)) { // If the switch is HIGH, rotate motor clockwise
    digitalWrite(motorPin1, LOW); // set Input 1 of the L293D low
    digitalWrite(motorPin2, HIGH); // set Input 2 of the L293D high
  }
  else { // if the switch is LOW, rotate motor anti-clockwise
    digitalWrite(motorPin1, HIGH); // set Input 1 of the L293D low
    digitalWrite(motorPin2, LOW); // set Input 2 of the L293D high
  }
}

void doEncoderA(){
  // look for a low-to-high on channel A
  if (digitalRead(encoder0PinA) == HIGH) {
    // check channel B to see which way encoder is turning
    if (digitalRead(encoder0PinB) == LOW) { 
      encoder0Pos = encoder0Pos + 1;         // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }
  else   // must be a high-to-low edge on channel A                                       
  {
    // check channel B to see which way encoder is turning 
    if (digitalRead(encoder0PinB) == HIGH) {   
      encoder0Pos = encoder0Pos + 1;          // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }
  }
  //Serial.println (encoder0Pos, DEC);         
  // use for debugging - remember to comment out
}

void doEncoderB(){
  // look for a low-to-high on channel B
  if (digitalRead(encoder0PinB) == HIGH) {   
   // check channel A to see which way encoder is turning
    if (digitalRead(encoder0PinA) == HIGH) { 
      encoder0Pos = encoder0Pos + 1;         // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }
  // Look for a high-to-low on channel B
  else {
    // check channel B to see which way encoder is turning 
    if (digitalRead(encoder0PinA) == LOW) {   
      encoder0Pos = encoder0Pos + 1;          // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }
  }
}
Pages: [1]