Hi. I am currently working on a project that involves the actuation of a stepper motor coupled to a Linear Motion Guide, and have a reached a problem to which I cannot figure out a solution. I will try and explain the problem as elaborately as possible so that you can get a clear picture of what I am stuck at.
I was planning on working the stepper motor using acceleration/deceleration profiles as I learned that it wouldn't be good to subject the motor to a sudden jump to high speeds, and because it looks more appealing in operation to see uniform transition in speeds. A formula was derived which would vary the delay between each step while actuating the stepper motor and thus obtain the required speed profile. The code to actuate the Stepper motor was such that it would first calculate the delay between the present and next step using the formula, actuate the present phase of the stepper motor, provide the calculated delay using the delayMicroseconds() function (to be more specific, the delay would range from 2500 microseconds at slow speed to 700 microseconds at the desired top speed), de-actuate the phase and then move on to actuating the next phase in the same manner (as would be the operation of any regular stepper motor code, to my knowledge).
The project started out with testing on an Arduino Mega ATmega2650 (running with a 16MHz crystal oscillator) and the results obtained after quite a bit of trial and error were in line with what I had expected. But due the requirements of the project, I had to move on to making my own custom Mega using a standalone ATmega2560 IC. I purchased one that was soldered onto an SMD to DIP breakout board, but this one had a 14.7456 MHz crystal soldered onto it. I figured that this wouldn't be much of an issue as the Arduino libraries are built with functions which handle the required calculations for delays. From my testing with the new standalone IC, it turns out I was probably not entirely right. The same program that worked with the Arduino Mega, didn't seem to work on the standalone.
I tried to work around this and figure out what the problem could be by tweaking the delay provided between steps from which I made two observations:
-
The Arduino Mega would give me the required functionality using either the delay() or the delayMicroseconds() function for delays between 3000 microseconds to 600 microseconds. The standalone would give me the required functionality using the delay() function for delays between 3 milliseconds and 1 millisecond.
-
On the standalone the stepper motor would work the right way with a delay(x) function call, but would not work with a delayMicroseconds(x*1000) function call. For eg.: delay(1) would work fine, but delayMicroseconds(1000) would not work fine. Technically both of them should mean the same, but I do not know why this difference prevailed.
Now that my problem has been described, my questions are:
-
What could be causing the difference in operation between the Mega and the standalone?? Does the different clock actually cause it??
-
Could there be a workaround to this problem in terms of the logic used?? Can I find a solution that does not involve changing the hardware, i.e., the oscillator??