# Writing a program to measure frequency sent to a stepper motor at every impulse

Hello!

I am currently working on a project with a stepper motor where I have run into a little confusion on what to do. Here is the general gist of the project:

I am powering a NEMA 17 stepper motor with an Arduino Uno and Arduino Motor Shield. I have designed a full-wave rectifier via an op-amp/hardware to allow the stepper motor to do complete rotations as opposed to oscillatory movements, as the rotating motor will be hooked up to a mechanical device that will essentially translate the rotational movement to a vertical linear movement (the motor function is irrelevant for this question, however). What I am intending on doing is using PWM to alter the frequency/rpm of the motor (I will be exploring frequencies between 0 Hz and 100 Hz, in increments of 5 Hz). In addition to that, I would like to assign a “digital Word” to every frequency that I will be testing so that when I change the frequency of the motor to 5 Hz, for example, the digital word 0001 is sent to a certain channel that I can pull data from for data analysis. This allows me to know when I was at 5 Hz, 10 Hz, 15 Hz, 20 Hz, etc… This will continue (when the motor is changed to 10 Hz, the Arduino assigns 0010 to a new channel for data analysis, etc.).

I am powering a NEMA 17 stepper motor

But what color is it? The mounting hole size and spacing are completely immaterial.

with an Arduino Uno and Arduino Motor Shield.

But, then you say

I have designed a full-wave rectifier via an op-amp/hardware

So, which is it?

What I am intending on doing is using PWM to alter the frequency/rpm of the motor

How? Every stepper motor driver I've seen moves the stepper motor by setting 4 pins HIGH or LOW in various combinations, to set one set of coils on, making the motor step.

I would like to assign a "digital Word" to every frequency that I will be testing so that when I change the frequency of the motor to 5 Hz, for example, the digital word 0001

What is a "digital Word"? The value looks like the frequency divided by 5.

digital word 0001 is sent to a certain channel

You need to explain what this means. The Arduino does not have "channels".

I apologize, my terminology may be off. The motor that I am using is below:

I am using both hardware and Arduino. The signal will be sent through the Arduino for PWM, then sent through the full-wave rectifier to make the motor operate in complete rotations as opposed to just oscillating.

I was under the impression that it is possible to use PWM for the stepper motor. Is this incorrect? If so, is there another option that yields a similar result?

When I refer to a digital word, I am essentially just referencing a digital signal that is sent through one of the Arduino pins (not channels) everytime a certain frequency is hit. Think about it like a notification system; for example, if every time a wave pulse of 5 Hz frequency was sent, a red light went on, for 10 Hz a blue light went on, etc. In the same idea, I want to send a certain digital code that I assigned to each frequency (the digital codes are arbitrary, they are just assigned, so it could be 5 Hz = 0001, 10 Hz = 0010, 15 Hz = 0110, etc.). This way, every time a 5 Hz wave pulse is sent, a 0001 digital signal is sent to pin 5, for example. Does this make a little more sense? If not, I can elaborate more.

I apologize, my terminology may be off.

It's not just you. LadyAda is making the same mistake, thinking that NEMA 17 means something, when all it defines is the mounting hole locations, count, and size.

I was under the impression that it is possible to use PWM for the stepper motor.

What does a 14% duty cycle mean to a stepper motor? What does it do to YOUR stepper motor?

Think about it like a notification system; for example, if every time a wave pulse of 5 Hz frequency was sent,

Think about it from the Arduino's perspective. What does sending a wave pulse mean? The Arduino can turn pins on and off. THAT IS ALL. It can do so very rapidly, in the form of PWM, but how does that relate to "sending a wave pulse"?

This way, every time a 5 Hz wave pulse is sent, a 0001 digital signal is sent to pin 5, for example.

Aside from the fact that sending a wave pulse doesn't make sense, what would you send to pin 5 when the frequency was 10 Hz? Keeping in mind that the pin can only be on or off.

I have worked with PWM with DC motors, but what you are saying with only being able to output HIGH and LOW makes sense. If this is the case, is there any way to produce a PWM-type result with the Arduino, or is this a moot effort?

By saying wave pulse, what I mean is say at the beginning of every wave that is Processed through the Arduino, there is a notification for it. So the digital word (0001, 0010, etc.) would be sent out each wave beginning.

gmaestas: I am powering a NEMA 17 stepper motor with an Arduino Uno and Arduino Motor Shield. I have designed a full-wave rectifier via an op-amp/hardware to allow the stepper

...SNIP...