Hello,
I am using two of these DC geared motors and an Arduino UNO R3 to count the number of encoder ticks. Each motor came equipped with a quadrature Hall encoder attached to the motor shaft. I am using only one encoder channel per motor, and reading the CHANGE in signal level.
This is the 'skeleton' of my Arduino code.
const int right_R1=8;
const int right_R2=12;
const int PWM_R=10;
const int left_L1=7;
const int left_L2=6;
const int PWM_L=9;
const int PinA_left = 3; //motor encoder pins
const int PinA_right = 2;
volatile long count_right = 0;
volatile long count_left = 0;
void setup()
{
Serial.begin(9600);
pinMode(right_R1,OUTPUT);
pinMode(right_R2,OUTPUT);
pinMode(PWM_R,OUTPUT);
pinMode(left_L1,OUTPUT);
pinMode(left_L2,OUTPUT);
pinMode(PWM_L,OUTPUT);
pinMode(PinA_left, INPUT); // set the pulse pins to INPUT or INPUT_PULLUP??
pinMode(PinA_right, INPUT);
attachInterrupt(PinA_left, Code_left, CHANGE);
attachInterrupt(PinA_right, Code_right, CHANGE);
}
void loop()
{
}
//left speed encoder count
void Code_left()
{
count_left ++;
}
//right speed encoder count
void Code_right()
{
count_right ++;
}
I'm trying to understand the importance or need to have INPUT_PULLUP connected to the DC motor encoders, as opposed to just INPUT in the pinMode configuration.
My questions:
From my online research, it seems that some DC motors with encoders have hardware pull-up resistors and they do not require an additional pull-up resistor. How do i know if my motor encoders have these pull-up resistors built-in for the encoder signals? I could not find a datasheet for my DC motors and the available information did not mention anything about pull-up resistors.
What are the consequences, if my motor encoders happen to come equipped with those hardware pull-up resistors, and then i also set the pinMode to INPUT_PULLUP in the Arduino code? From my understanding, this will cause a double pull-up resistor configuration, meaning, two resistors connected in series? How will this affect the readings from the encoders detected by the Arduino UNO R3?
I am trying to get a deeper understanding of the parallel pull-up resistors setup. I did some research and found the following diagram. My DC motor has quadrature encoders so i think it should be the same:
I would get a lesser total pull-up resistor value for each encoder. How to know if that value is high enough?
I did more research and i found this interesting article: Pull-up Resistors - SparkFun Learn and the recommended value for the pull-up resistor is 10kΩ. But in this case, with INPUT_PULLUP enabled, i would get less than 10kΩ. That could cause some problems with the encoder counts?
My DC geared motor model is CHR-GM37-520 and the picture on that website (shown above) is quite close to my own motor:
I tried using a digital multi-meter to measure the resistances but for some reason, it didn't work. I can't get a value by touching my multi-meter probes at the ends of each SMD resistor. I'm not sure what's wrong. I was hoping to verify that the resistors are 3.3 kΩ as shown on that website.
Traditionally encoders have no pull-ups so they can be voltage-agnostic. Many are powered upto 24V and work with 3, 5, 10 or 24V logic equally well - fairly common for industrial sensors.
But as always read the datasheet for your device, that has the details...
No datasheet? Probably wise to choose a better documented product.
Surface mount resistors have their value code marked on them, for instance 472 = 4k7, 103 = 10k
There may be a coating over the circuit board, to protect against moisture/whatever. I would guess, and that's all it is, that R1 and R2 are the pullup resistors, and R3 is for the led. R1 and R2 will be the same value, but R3 may be different. If you can't put a bit more welly into your resistance probing, to penetrate the possible conformal coating, then I would expect you could measure resistance at the connector, 'twixt +v and the two outputs, and get twice those values by measuring between the two outputs.
Well, in this case, i believe that i need to use pinMode with INPUT_PULLUP, as 1 kΩ is probably not enough as a pull-up resistor to deliver meaningful and reliable encoder counts to the Arduino UNO R3 digital pin.
So, in parallel, the final resistance of the pull-up resistor is: (1000 x 10,000) / (11,000) = 909.09 Ω. But this is worse! It's less than 1 kΩ now.
Maybe i should not use pinMode with INPUT_PULLUP or should i use a resistor in series to increase the pull-up resistance value?
Here is a schematic of what i'm considering. Will this work?
Well, in this case, i believe that i need to use pinMode with INPUT_PULLUP, as 1 kΩ is probably not enough as a pull-up resistor to deliver meaningful and reliable encoder counts to the Arduino UNO R3 digital pin.
So, in parallel, the final resistance of the pull-up resistor is: (1000 x 10,000) / (11,000) = 909.09 Ω. But this is worse! It's less than 1 kΩ now.
Maybe i should not use pinMode with INPUT_PULLUP or should i use a resistor in series to increase the pull-up resistance value?
You have this backwards. The lower the pullup resistance the stronger the effect. 1K is often used for noisy environments or long signal wires. 4.7K is often used. The problem with the internal pullups is that they are 20K to 50Kohms and are sometimes too weak.
cattledog:
You have this backwards. The lower the pullup resistance the stronger the effect. 1K is often used for noisy environments or long signal wires. 4.7K is often used. The problem with the internal pullups is that they are 20K to 50Kohms and are sometimes too weak.
Thank you for the clarification. I was thinking about the 10 kOhms pull-up resistor value recommended from the Sparkfun article: Pull-up Resistors - SparkFun Learn. So, based on what you said, then it would not be a good idea to use pinMode with INPUT_PULLUP in the Arduino code? As that will make the pull-up effect stronger...
My dilemma here is explaining my code, more specifically, justifying the use of pinMode with INPUT or INPUT_PULLUP and its effect on the encoder values measured by the Arduino UNO R3 digital pins.
I also want to confirm if this setup is correct for what is happening in the motor encoder circuit? I can see 2 capacitors on there, so this should be a Passive Low Pass Filter? I think R1 and C1, and then, R2 and C2 are together in this configuration? R3 is probably the current-limiting resistor for the LED diode?
Source: https://www.electronics-tutorials.ws/filter/filter_2.html
So, based on what you said, then it would not be a good idea to use pinMode with INPUT_PULLUP in the Arduino code? As that will make the pull-up effect stronger...
Stronger pullups are generally "better". The limit is either the current output capabilities of the open collector transistor inside the encoder, or the ability of the Arduino to recognize a LOW.
If you are uncertain of the pullups on the encoder, then using INPUT_PULLUP is a good idea. If you are certain that you have 1K pullups on the encoder, then they are not necessary.
My dilemma here is explaining my code, more specifically, justifying the use of pinMode with INPUT or INPUT_PULLUP and its effect on the encoder values measured by the Arduino UNO R3 digital pins.
If there are pullups on the board, I doubt it would have any impact. Why do you think it does?
I also want to confirm if this setup is correct for what is happening in the motor encoder circuit?
Where does the sine wave come from? The output should be a square wave based on the pullup and open collector output. An RC filter would just round that off. It may be used for some sort of noise control to dampen spikes, but it would also limit the ability of the Arduino to read fast pulses. I would doubt the existence of a low pass filter on the output of the encoder.
cattledog:
If there are pullups on the board, I doubt it would have any impact. Why do you think it does?
I was considering the pull-up resistor arrangement but since the parallel arrangement would only decrease the pull-up resistor from 1 kOhms to about 900 Ohms, i think it's safer to use INPUT_PULLUP since i cannot confirm that these resistors are actually used as pull-ups. I have not been able to find a schematic of the encoder circuit for that motor.
Where does the sine wave come from? The output should be a square wave based on the pullup and open collector output. An RC filter would just round that off. It may be used for some sort of noise control to dampen spikes, but it would also limit the ability of the Arduino to read fast pulses. I would doubt the existence of a low pass filter on the output of the encoder.
I simply used the schematic from that website but i understand that it should be a square wave input instead of a sine wave. However, i can't figure out why there are capacitors, if they're not used as an RC filter together with these resistors?
Another thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to voltage changes. This is because the system that feeds the input pin is essentially a capacitor coupled with the pull-up resistor, thus forming a RC filter, and RC filters take some time to charge and discharge. If you have a really fast changing signal (like USB), a high value pull-up resistor can limit the speed at which the pin can reliably change state. This is why you will often see 1k to 4.7KΩ resistors on USB signal lines.
raymw:
There may be a coating over the circuit board, to protect against moisture/whatever. I would guess, and that's all it is, that R1 and R2 are the pullup resistors, and R3 is for the led. R1 and R2 will be the same value, but R3 may be different. If you can't put a bit more welly into your resistance probing, to penetrate the possible conformal coating, then I would expect you could measure resistance at the connector, 'twixt +v and the two outputs, and get twice those values by measuring between the two outputs.
I tried poking the SMD resistor ends but no reading on my digital multimeter. I'm afraid to probe harder as the encoder PCB disc might get perforated or damaged.
raymw:
Have you measured the resistance across various pins on the motor/encoder connector? #6 refers.
I plugged the motor connector cable and measured the resistance between the color-coded wires:
Blue: encoder Vcc
Yellow: encoder A output
White: encoder B output
Between Blue and Yellow, i got: 1.005 kOhms
Between Blue and White, i got: 0.992 kOhms
This confirms that the pull-ups are connected. But what about C1 and C2 on the PCB, and their connections and roles in the encoder?
groundFungus:
The caps may be connected to the motor power inputs for electrical noise suppression. Spark suppression caps in reply#4. Not connected to the encoder.
Controlling arc damage from coils and motors is done by suppressing inductive kickback. There are three basic methods which can mitigate inductive kickback: shorting, arc lengthening and switching management. For lower power applications, such as small solenoids and fractional horsepower motors, shorting is the simplest method. Shorting can be accomplished by using a metal oxide varistor (MOV), a neon lamp or a spark gap. An MOV is the most common component used to suppress lesser energies. These devices represent an open circuit below their specified rating and become conductive above that rating. An MOV is connected directly to the terminals of the coil. When the coil is disconnected, its voltage starts to rise, and when it reaches the MOV rating, its output becomes shorted. All arcing is suppressed because the kickback voltage is never large enough to initiate the arc in the first place. Figure 1 shows how an MOV is used in a circuit to suppress inductive kickback.
But in this case, it's about a varistor and not a capacitor...
Note that that is an AC motor so very different than the DC motor you have. An MOV (Metal Oxide Varistor) is not a capacitor. I think, in that case, it is more for absorbing inductive kickback (like a freewheel diode on a DC motor). Caps or a diode won't work on an AC motor.
On a dc motor, the caps are often wired from each power lead to ground. They dump brush noise to ground. And sometimes also across the motor windings.