vnh5019 131:1 37D with encoder

I am sorry I am such a newbie, but here goes nothing

Recently bought vnh5019 dual motor controller shield and the 37D 131:1 metal gear motor item# 1447. Using with an Arduino Duemilanove. Shield and Arduino have separate power supplies. Arduino powered by 6vdc 200ma walwart. Only running 1 motor. Motor supplied with 12V, 4.5A walwart. I know this could be a little short vs stall amps on motor, but I am hoping to never stall the motor.

I haven’t seen such a basic question in the forums and I’ve read through the shield documentation but can’t seem to quit figure out what I want to do if it is possible. I hope my question might help others.

I haven’t yet, but don’t expect any problems hooking everything up except for the encoder leads. Can I hook up the leads to the Arduino and monitor the encoder output? If so what should they be hooked up to. I know the encoder needs 3.5-20V so I think I can just grab 5v VDD from the Arduino pin through header on the bottom of the shield along with Gnd. But where do I connect the encoder A and B wires to allow monitoring of the shaft position in the Arduino, or do in need to be looking at an Orangutan?

Thank you for your help.

So, I’ve done some more research reading. I still need to know if I can get my power and gnd for the encoder where I posted above.

I know I can use pins #2 and #3 with external interrupts for the encoder, but pin #2 is used by the shield for Motor 1 direction input. As I am only going to be using one motor (for now) I suppose I could connect my motor to Motor 2 and reset pin #2 for the encoder and loose the the Motor 1 direction input (I’m not quit sure how to do that yet) or I could just use pin #3 and loose half the resolution of the encoder by not using both leads (I don’t need great resolution, but I would rather have it all if I can).

If someone could point me in the right direction I would appreciate it.

You can use pin-change interrupts and use any pins on the Arduino.

Also, if you’re OK with a quarter of the resolution (hint: with 131:1 gearing, you are :slight_smile: then you can tie the A pin to a single interrupt for rising edge only, and use the B pin on any digital input as a “direction sense.” In the interrupt handler, read the B pin; if it’s high, you’re going one way; if it’s low, you’re going the other. This assumes that you can deal with 160,000 interrupts per minute, which is possible but not easy. You will likely miss interrupts with some frequency due to timer interrupts, serial communications, etc, and a delayed interrupt will mean that you count the “wrong way” for the direction sense.

You can also use Timer 2 in Externally Clocked mode by putting one of the signals into the T1 pin and setting the EXCLK bit in the ASSR register (check page 156 of the Atmega328p data sheet.) Unfortunately, I can’t find a good way to set the direction of the counter when doing this – there’s no “direction” input pin.

I’m thinking of using ATTiny85s to do this counting for me. I can run them at 8 MHz on the internal clock, and I can poll their values using SPI, and then can sit in a tight loop, doing nothing but counting step/direction signals.

Thank you for the help and thoughts. With what your thinking of doing do you think you still can read everything fast enough to know what is going on. You don’t think you will also lose some important data?

I know I can hook up to any pin and read pin changes, but my understanding is I only have two pins I can use with external pin reads which are faster. They are pins 2 & 3 but 2 is used by the shield.

For me, I don’t really need to know exact position. I am going to be using this to twisting wire together (so many twists per in / cm) so I only need to be within about 1/4 of a revolution and only need a speed of around 40-80 rpm. I am only going to be twisting in one direction, so actually verifying the direction the shaft is turning at any given moment really is not necessary (motor could turn backwards after wires are twisted and motor stopped without brake due to wire memory, but that should be pretty constant and can be taken care of within initial setup). Of course I am then assuming the motor will always turn in the direction I initially start it in, and won’t be verifying, but I think that is a pretty safe assumption, and there will be a human monitoring the process that can always shut things down if it goes terribly wrong. I want to be able to set acceleration and deceleration over the number of revolutions I need and then motor brake at the end to hold the twists for a given length of wire. The motor I picked gives me the speed and torque that will let me do a variety of wire sizes and lengths but the encoder resolution is way overkill but if I can pair down the information or just sample at slower speed using a delay I think it should work?

So I am now thinking of just reading one encoder lead with external pin change on pin #3 and set a delay of how often I read the pin. However, because I can not then set an exact number of the encoder readings to determine exactly how many revolutions I’ve gone and where the shaft is within a revolution (remember I am going to be accelerating and decelerating during the run time so reading the encoder with a delay will not be reading at a constant frequency vs turns) I am not sure I can easily achieve, though again I do not need to be very accurate, the precision I am after. Reading the one pin all the time might be too overwhelming for the Arduino. I will have to look into your suggestion of using the clock mode, but it too might suffer from inaccuracies due to my want of acceleration / deceleration. If anyone else has some other ideas I am all ears.

If the motor will be turning in one direction only, then jwatte’s suggestion to Timer 2 in Externally Clocked mode is the way to go. You won’t miss any counts that way.