Hello:
I am trying to make a high power servo with an Arduino UNO, a motor controller and motor, and an encoder to control position. I attach the encoder to the motor shaft and after that I have some gears to slow down speed. All the system is controlled by a second Arduino UNO that sends simple commands using I2C.
My code is attached as file due to its length.
The function that is giving me problems is MoveServo(). At this moment I am not using any PID function as I should use but for the moment this simple technique is ok for me. The problem I experience is that if I try to move the servo with a command 'M100' from some position, it starts the motor and doesn't stop for some seconds, and finally it resets the arduino board. However, if I do not power the motor, and move the encoder with my hand, it shows a normal behaviour. The difference is that the motor runs at approximately 2000 rpm. The encoder is an optical encoder with 600 pulses per turn, which means it is making 4x600=2400 interrupts per turn with the approach I am using to read the encoder.
This is making me crazy. The question is: Maybe the board is resetting due to too many interrupts? Any other approach I could use?
Any help will be very appreciated.
Is the encoder before or after the gear train? On a hobby servo the sensor pot is after the gear train.
2000 rpm * 2400 ppr = 4,800,000 interrupts per minute = 80,000 interrupts per second = 200 instruction cycles per interrupt. If you keep your ISR short that should be OK.
Hello:
Yes, I placed the encoder on the shaft. The reason is to get a good resolution, specially because the first encoder I tried is one of the cheap encoders sold in ebay, at 20 pulses per turn. Since it did not work, I changed for a better quality encoder like this one. I suspect I should change it to another shaft, with less rpm, and taht is what I am going to try now, since when I move all the system at hand speed, it performs ok.
johnwasser, I know there are a lot of ISR but I do not know if my code is short enough. In case it were too long, could it cause the board to reset?
I do not think the power is a cause. Now I'm in developing time and the boards are powered by USB. The motor has an external battery.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
How are you powering your motors, if from the 5V pin of the arduino, STOP, it will not be able to supply the current needed.
We need, the spec, model of the encoder.
We need, the spec, model of the motor.
Even links to these items will help.
You need more than an encoder with 600ppt, how do you know your initial position of the motor at turn on?
Finally I managed to get it to work changing the encoder to a second step shaft. I measured the encoder output with a freq meter and it is around 10 KHz. Now the Arduino board does not reset. Apparently, it can't support the higher freq at the first shat, which was about 200 KHz.
Anyway, my system is only a prototype, only for software and mechanical tuning. The result is not very much usable, and so I am going to build a bigger one with a 300 W motor. When I finish it I will give details.
In order to answer to TomGeorge, the motor is a small hobby motor, I cannot give any detail. The encoder is a 600 ppt, and I use an end-travel switch to reset the counter at power up.