Maker Pro
Maker Pro

Control stepper motor with PIC, maximum output frequency of PIC

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Dear all,
I would like to control a stepper motor using PIC18F.
I have a driver circuit for this motor.
The driver circuit allows me to give an input pulse to control the motor.
To control the speed of the motor, I should be able to produce pulses with different frequencies.

I have the following questions :

1. Is a microcontroller a good solution for controlling a motor with a driver circuit? I mean mainly for generation of pulses...? or better to use NI cards and DAQs (in output modes) to generate pulses?
2. Is, for example a PIC18F microcontroller fast enough to generate pulse with high frequencies? I mean what is the max frequency we can acheive with a microcontroller?
3. I want to produce pulses by opening/closing a port. Is it the right way?


Many thanks,
Bests regards
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Dear all,
I would like to control a stepper motor using PIC18F.
I have a driver circuit for this motor.
The driver circuit allows me to give an input pulse to control the motor.
To control the speed of the motor, I should be able to produce pulses with different frequencies.

I have the following questions :

1. Is a microcontroller a good solution for controlling a motor with a driver circuit? I mean mainly for generation of pulses...? or better to use NI cards and DAQs (in output modes) to generate pulses?
2. Is, for example a PIC18F microcontroller fast enough to generate pulse with high frequencies? I mean what is the max frequency we can acheive with a microcontroller?
3. I want to produce pulses by opening/closing a port. Is it the right way?


Many thanks,
Bests regards
You should start looking into specs for specific PIC microcontrollers.
You need to generate a 'Step' pulse, as well as control a 'Direction' bit.
So each stepper will need two bit from the microcontroller.

If all you want to do is generate the step pulses, a PIC can do that fine... if you plan to build a program that will be doing calculations as well as providing step/direction pulses for multiple steppers you will start running into problems.

We need more information. How fast do you want it to go?
Are you doing full steps or micro steps?
 

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Thank you very much.
Yes my driver has an input for "pulse" and an input for "direction". So I guess all I should do is to connect the "pulse" input of the driver to one port of my microcontroller? Then by changing the state of this PORT, I can create my "Step" pulses?

I dont want to do calculation. However I want to have LabVIEW program, communicating with my PIC (using UART) to read data from the serial port. I have also a force sensor which I may read the value sometimes in the program.

I did not choose the speed yet, but I want to be quite fast.
The motor I have is the following:

http://www.sonceboz.com/medias/Products/PDFs/datasheets V2/7220.pdf

I think I will use full step (but the driver allows me to choose between full step or micro step I guess).

Many thanks again and bests regards
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Thank you very much.
Yes my driver has an input for "pulse" and an input for "direction". So I guess all I should do is to connect the "pulse" input of the driver to one port of my microcontroller? Then by changing the state of this PORT, I can create my "Step" pulses?

I dont want to do calculation. However I want to have LabVIEW program, communicating with my PIC (using UART) to read data from the serial port. I have also a force sensor which I may read the value sometimes in the program.

I did not choose the speed yet, but I want to be quite fast.
The motor I have is the following:

http://www.sonceboz.com/medias/Products/PDFs/datasheets V2/7220.pdf

I think I will use full step (but the driver allows me to choose between full step or micro step I guess).

Many thanks again and bests regards
If you are unfamiliar. The stepper motor driver requires both a step and direction.. if you omit the direction bit, the stepper motor will only ever turn in one direction.
Of course, when you change the setting from full step to any of the micro stepping options, you will need to send a multiple of pulses to turn the stepper as far as a single pulse from a full step.
There will be a trade-off... step resolution or speed, you can't have both...
Additionally, the stepper driver you have should come with specifications on the hold time required for a change on the 'direction' line, as well as a maximum frequency it can accept as a 'step'.

If you want to play, you can simply set one of the pins on the PIC as an output, and toggle it high and low.
Be careful adding additional functions to the pic... if it has to pause outputting steps to read a sensor, this will slow down the rate of which it sends the pulses, or worse yet can introduce an oscillation that will inhibit the motion of the stepper motor.
Careful coding can avoid this... as well as keeping the step frequency lower than the max speed of the pic. (This gives you time to process stuff with a few cycles before outputting a pulse)
 

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Thank you very much.
Could you please explain me what is this "step" pulse? I dont get it.
How can this "step" pulse gives information about Number of steps and the speed?
Is it a periodical signal ? or not?

Sorry I am too beginer ! ;)

By the way thanks a lot
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Thank you very much.
Could you please explain me what is this "step" pulse? I dont get it.
How can this "step" pulse gives information about Number of steps and the speed?
Is it a periodical signal ? or not?

Sorry I am too beginer ! ;)

By the way thanks a lot
Your stepper driver has two inputs. Step and Direction.
To move the motor forward, you leave the Direction input low, and feed pulses into the Step input. To move the motor in reverse, you set the Direction input high, and then feed pulses into it.
The stepper motor expects to be drive with changing combinations of powered pairs of wires... the driver you have takes care of that part for you, but you still need to tell the driver how many steps and which direction you want it to move the stepper.

So.. your stepper claims that each step will travel 0.001".
So if you want to move 1", you need to send 1000 step pulses. If you set micro stepping to 4x for example... each 'step' will only move a quarter of the way, meaning you would need to send 4000 step pulses to move an inch.
The pulses are merely a square wave. So if your PIC's step output is 0V, changes to 5V, and back to 0V. That is a single step.
Remember that even if you get a PIC to send step pulses at 1GHz, the stepper driver may not handle it.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
The motor datasheet does not include a max RPM, but the graph shows step rates only up to 1000 per second. The PIC can do that rate without even breaking a sweat. In fact, I can do that while having nearly it's full compute power for doing other things.

Bob
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
The motor datasheet does not include a max RPM, but the graph shows step rates only up to 1000 per second. The PIC can do that rate without even breaking a sweat. In fact, I can do that while having nearly it's full compute power for doing other things.

Bob
Motor spec sheet will not, but the stepper driver most likely will. 1000 Steps per second will be easy as you mentioned, but if the op is after a maximum output frequency we need to determine the weakest link.
This could potentially be quite complicated though... as even with an unlimited frequency was supported by the PIC and the stepper controller, the voltage used to drive the stepper (and the steppers characteristics) will limit how fast it will rotate.
BobK, can you spitball estimated maximum rates for a couple of common PIC's? I'm more curious on estimates than facts.
@Emam, I would love to see a data sheet or part number for the stepper driver you are using.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Actually, if you use the PWM module, you can probably put out a square wave at the 1/2 of the clock frequency. But it would probably be impossible to control the number of steps accurately since you could not use interrupts at that rate.

I would say that a PIC could reliably put controlled, counted pulses at 1/8 of the instruction rate (1/32 of clock frequency for 8-bit PICs). So, for a PIC operating at 16MHz, probably 500KHz, way above the ability of any stepping motor you are likely to find.

I actually made an AM transmitter using the PWM module on a mid-range PIC to output a square wave at 1MHz (middle of the AM band), using 4 different duty cycles to put out an audio tone on an AM receiver. Just as an experiment, no real purpose in in.

Bob
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
[
QUOTE="Nyein Chan, post: 1647483, member: 39518"]I would like to control stepper motor ( >50kHz) , 12V, 1.3A with PIC 18F4553 .
I have stepper & driver already .
We tested this stepper with Panasonic PLC unit , this stepper driver can support to this stepper in this frequency range .
But I want to use Microcontroller .

This PIC i8F4553 can support this frequency from its output ?
Please help me to give the sample program for driving stepper with pusle signals using C .

Thanks in advance .
@Nyein Chan what you have just done is called "hijacking a thread" and that is not good manners. Although your question is on-topic, it does not appear to have originated from the same application that @Emam is posting about... unless the two of you are co-workers on the same project. If you are NOT co-workers on the same project, you should post your question as a new topic.[/QUOTE]

[Mod note by Dave = I have taken care of this :) his post now has its own thread]

The PIC 18F4553 can probably produce 50 kHz pulses, but it won't have much time left to do much more than that. Read the datasheet and decide how you would program the PIC to produce pulses. @BobK has experience in this area, and his previous post #10 indicated pulses up to about 500 kHz can be easily produced. Whether or not the PIC has time to do anything else will depend on what else you want to do. PICs are dirt cheap, so don't overlook the possibility that you might need two or more, working in cooperation, to accomplish your overall task.
 
Last edited by a moderator:

Nyein Chan

Apr 4, 2015
2
Joined
Apr 4, 2015
Messages
2
Sorry

I did not know your forum's rule . I suddenly saw this topic and eagerly wanted to know .
That's why .
 

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Thank you all for your help.
Especially I would like to thank "hevans" for his helpful commments.
I have partially resolved the problem, however I should still correct some data conversion etc.
The origin of the problem was various but the main problem was that I did not have any documents!!

Here is the summary of what blocked me for a long time:

1. The fabricant gave me a data sheet but it was not a right one exactly. My sensor was an updated version compared to the one for which I had data sheet.
2. The fabricant could not help me, becasue the sensor was too old. The person who did this sensor was no more available.
3. As Hevans said, a "nul modem" cable was necessary for the transfer. I had no idea about that.
4. As "Heavans" said, there was a need to enter <CR> charactere at the end of my ASCI command, to communicate with my device.
5. The righ ASCI command for transfere starts with character ' , ' which I did not know.

Most important thing: I put an entire day, to search everywhere, in the computers of our company, the hard disks of my old colleagues, and our server data storage.
Finally I found the data sheet !!!!

By the way, I know that the problem was not technical problem, but rather organizational problem.
But Its important to work with devices with correct documents.


Again many thanks
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
... But Its important to work with devices with correct documents ...

You are absolutely correct! I would estimate that 90% of the problems people pose here could be easily solved by the original poster if they had correct documents and took the time to read and understand the contents of those documents. It is fortunate that there is so much information available on the World Wide Web, but as you discovered most of the older technology has not been scanned and archived.

Congratulations on your diligence in finding the document you needed!

BTW, it appears you are responding to this older thread instead of the current thread. Posts here are organized by the title provided by the original poster (OP) rather than by the user name provided.
 

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Ah yes, sorry I copied it to the right place.
Yes,i thinks documens should be kept and saved somewhere in companies for the use of other people. The person who used 10 years ago this sensor in our company is no more present, but he understood the importance of keeping docs. Thats helped me to find the solution 10 years after his departure !
Thank you again for your interesting remarks.
Emam
 
Top