Sinusoidal motion with a precise frequency by using a stepper motor

Hi there!

I am trying to obtain a linear sinusoidal motion with a very precise frequency (error max of 2%) by using a captive linear stepper motor (NEMA 14).

I made up a device able to provide a linear motion up to 3mm. It is possible to select the amplitude of the motion (amplitude of the sine) with a resolution of 0,1mm. Moreover, it is possible to select three different values of motion frequency: 1, 2 and 3Hz.

My hardware consists essentially of: Aurduino DUE (with a TFT display) + Driver A4988 + stepper motor

To obtain the sinusoidal motion, I change the delay time after each step of the motor by using the function dalayMicroseconds(). The delay values are computed by following a sinusoidal law.

There are no problems about the amplitude of the motion.
The probleme is that I always obtain a motion that is slower than the imposed one. The error seems to be random and too much high although I take into account the delay due to the program execution. For istance, instead of 2 Hz I obtain 1,7 Hz (measured by a LVDT sensor).

What could be the problem??

Thank you!

Giovanni

It is very difficult to help with code that we cannot see.

Using millis() for timing instead of delay will give better control of the timing.

beginners guide to millis() (works for micros(), too.)

Read the "how to use this forum-please read" sticky.

giois89:
The delay values are computed by following a sinusoidal law.

The step-frequency values should follow a sinusoidal law, not the delays. If you compute delay as
sinusoid you get negative delays!!

The DSS approach to frequency synthesis is the natural fit here, where you update a phase accumulator
on a regular basis and generate a step everytime enough phase has accumulated.

Hi MarkT,
What is a The DSS approach to frequency synthesis?
Thanks i have a project close to his.

Program execution time with a 3 Hz output whould be unmeasurable and above all, it will be consistent.

We cannot help with code we cannot see. Please post your code using the code tags, the </> icon.

bvking:
Hi MarkT,
What is a The DSS approach to frequency synthesis?
Thanks i have a project close to his.

Sorry, my mistake, I meant DDS, direct digital synthesis.