Stopping Stepper Motor at specific degree and using incremental encoder

Hello,

I have a driver board which is composed of L297 and L298N and many other components, and I have power supply connected to this board and a stepper motor Sanyo Denki 103H7126-5740 bipolar (200steps/revolution, 1.8degrees each step) connected to the board and an arduino uno REV3. The direction of the board is connected to the pin 5 of the arduino and the step to pin 6 and the ground connected to ground and that's all the connections between the board and the arduino. Also I have an incremental encoder 8.KIS40.1362.1024 connected to the arduino, output channel A connected to pin 2 in arduino, output B to Pin 3, reference signal 0 connected to pin 4 and the 0V supply voltage encoder ground connected to gound in the arduino and finally the +V supply voltage is connected to 5V in arduino.
Please I need a code on arduino software that it will make my stepper motor turn exactly 30 degrees and then stop and at the same time the encoder should count each step done by the stepper motor before getting the 30 degrees (or 16.66 steps if 1.8 degrees each step). There's a shaft that connects the encoder shaft and motor shaft by coulpings and bearings and between them there is a mass so I need to be able to change the speed and torque of the motor. Finally, i need also to be able to do full or half step, and wave, modes. And if my board can achieve the microstepping mode I need to do it.

Please if someone has any idea tell me because it is very important to solve this project as soon as possible.
Thank you and have a nice day!

so the obvious question is why not simply step the motor 54 steps from some initial zeroth position? are you worried the stepper motor may slip/skip steps?

I did a mistake the number of steps for 30 degrees is 16.66 sorry about that.
Anyway, I don't mind if the motor do the steps from 0 or not I just need the motor to do 30 degrees and then stops but the goal is how to do it in full step then another way to do it in half step mode then wave mode and then microstepping mode if the board can achieve the microstepping. And at the same time when the motor will turn, the encoder should count each step.

You simply divide the desired angle by the respective degrees/step.

Between full-step and half-step mode, it will be correct, but if I have to use wave mode or micro-step, it won't be accurate.

How will it become more accurate if you don't hit the right position to stop the stepping?

I get the impression that you don't know how to use a stepper motor, the driver modes, and what are the related problems. Perhaps you are better off with a DC motor and encoder, for simpler code?

Let's make it simple, can the stepper motor stop at 16.66 steps (If I am using full step or half step modes)? Because it has 1.8 degrees each step and I need to turn it 30 degrees exactly which means 16.66 steps.

obviously a stepper motor requires micro-stepping to go a fraction of a step.

i'm not that familiar with micro-stepping, but i imagine it's where PWM is used to position the motor in between 2 steps.

i'm also guessing that the encoder is intended to measure the angle more precisely.

what is the tolerance of error for reaching 30 deg? rarely is anything mechanical exact

Use microstepping to get closer. What's the mechanical precision and (direction dependent) uncertainty of your device?

Okay no problem but do you have any idea if the encoder can count the fraction of a step? I mean for example if I used microstepping and the motor turns 16.66 steps can the encoder mention ''.66''? or it will mention only 16 or 17?

This is my problem, how to use microstepping with the board that is composed of L297 and L298N and some components like resistors and switches?

looks like the encoder has a resolution of 1024 increments / revolution or 0.351 deg

Yes, do you have a code that I can use it so the encoder can mention the fraction of the steps and the speed of the motor?

no.
the encoder doesn't measure stepper motor steps. it has it's own resolution, as mentioned.

looks like the L297 is a stepper motor controller that support half/full steps

the L298 looks like a simple H-bridge where the enable pin can be used to modulate the power to a particular motor coil.

it's common that when two stepper motor coils are driven, the motor is positioned halfway between the coils. i believe PWM can be used to unevenly power two coils to position the motor fractionally between the 2 coils

sounds like you're expecting to find code to do this for you.

Adjust your preferences closer to your goal.

I knew that the L297 cannot achieve the microstepping but I was checking if I am right.
Anyway I will check how to do it.
Thank you for your time.

Yes, thanks.

Can you give me a brief idea of how PWM can be used?

Look over the above

You need a 5 : 9 gear or cog belt ratio, 5 or10 tooth gear on motor, 9 or 18 tooth gear on driven shaft. One step on motor (1.8°) = 1.8 * 5 / 9 = 1° on driven shaft. You can't make the motor turn to and hold 2/3 of a step no matter how many divisions by 2. 1/2, 1/4,... 1/256, etc..