Easiest way to drive stepper motors

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hello, 

   

So, the delicate issue of driving steppers - whilst doing something else with your SoC ... like, I2C, ADC+ DAC, filtering etc. 

   

I am looking to drive some stepper motors using this driver: http://www.schmalzhaus.com/EasyDriver/  and a PSoC 5 or course 🙂 

   

The problem I find on the web is that you need to send the pulses for your steps and time them. Of course the easyest way is using the Delay fct ... but that will kill everythig else or result in a jerky motion. 

   

Do you have any idea on how this might be done with minmum resources? I am looking to run the motor and also measure loads of sensors ( 8 in total) and 8 digital signals in the same time: wheel pulse feedback as well as 6 other digital sensors. I don't have a project for this. At the moment I am using normal DC motors with a PWM function but would like to switch to steppers. 

   

Accel / decel control would also be amazing to have - something similar to this approach: http://www.airspayce.com/mikem/arduino/AccelStepper/  - I think this is the nicest and most refined of the open libraries around. 

   

My thoughts were of using a Timer or ARMs SysTick? not sure how well that would work but it must be a way to do it whilst keeping the rest of the code runnng. 

   

Thanks for the help! 

0 Likes
32 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given
0 Likes
Anonymous
Not applicable

Hi, I started working with the psoc 5lp and I trying to drive a step motor. I just learned that in order to get more precise steps I need to use micro-steps. I still dont fully understand what I need to do. can someone help me, and explain how I need to proceed. I cant find any relevant code example that uses micro-steps

0 Likes

Hi,

I am at the moment developing some PSoC 5 hardware for unipolar and bipolar stepper motors using full and half stepping and variable speed. If you have not already completed your design I am happy to share my findings.

0 Likes
Anonymous
Not applicable

Hi, I would appreciate if you would share your findings as mentioned in your post. I am using the PSoC4 Pioneer kit and the

CY8CKIT-037 -PSoC 4 Motor Control Evaluation Kit to just rotate a stepper motor in CW and CCW directions. The example code available is for microstepping. I would appreciate any help to modify this to do only FULL STEP. The Cypress AN56551 seems to indicate that this is possible. Thanks.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi

This Menus Zip is part of a larger work, the stepper schematic and hardware should be stand alone if stripped out as that is how it was first developed.

Hope this is of some help.

Sent from Mail for Windows 10

0 Likes
Anonymous
Not applicable

Hi,

I also have the same problem and i used your code you had sent in the menus.zip. I changed the device to PSoC4 CY8C4245AXI-483. When i build I'm getting the following errors,

pastedImage_0.png

I will not be having any display interface so i deleted that sheet and I'm using only the stepper hardware. I deleted the softstart also. Here's my current schematic , 

pastedImage_1.png

I appreciate any help to solve this problem. Thanks.

0 Likes

Hi,

I suspect the problem is associated with the amount of programmable logic available in a PSoC 4 device.

I found early on that PSoC 5 was much better suited to larger firmware designs.

You might look at the “rpt” that is generated in Creator and see what of the avaiable PSoC 4 hardware you have run out of.

In the first instance you might try to alter the design by removing the counter “Steps to Do” or using just using a fixed frequency and removing the PWM . PWM is probably using a lot of UDB.

You might even try using the PSoC 5 $10 board from Cypress that this was design in.

Hope some ofthe above helps.

Conrad Mannering

mrcrustyathome@gmail.com

“The Gnurrs Come from the Voodvork Out”

Bretnor, Reginald –(1950)

0 Likes

Hi,

I changed to a PSoC 4 kit chip with a UDB of 4 and if I remove the PWM component and just connect the clock source at a reduced rate say 1 kH then the project will compile.

The counter and the PWM both use UDB resources so that does not leave much for anything else in PSoc 4 chip.

You might be able to lose the counter and just count pulses by the interrupt to start and stop the PWM as to generate a varible colock rate is best in PWM module.

Hope some of this has helped.

Conrad Mannering

mrcrustyathome@gmail.com

“The Gnurrs Come from the Voodvork Out”

Bretnor, Reginald –(1950)

0 Likes
Anonymous
Not applicable

Thank you very much. I will try what you have suggested. Many thanks for

your time.

On Mon, Jul 23, 2018 at 11:30 PM, user_398677465 <

0 Likes

Your welcome.

Conrad Mannering

mrcrustyathome@gmail.com

“The Gnurrs Come from the Voodvork Out”

Bretnor, Reginald –(1950)

0 Likes
Anonymous
Not applicable

There is a Microstepping example code available on PSoC Creator 4.2. Works for me with the PSoC4 pioneer kit and the CT8CkIT-037 PSoC4 Motor Control Evaluation Kit

0 Likes
Anonymous
Not applicable

 Thanks Dana, 

   

I looked at them before I posted - great information but they all seem to use significant resources. The best way I found to date is this little I2C controller from NXP: http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629...

   

But always worth asking if there is a crazy cool way of doing it on a PSoC that I missed. . . 

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

If the concern is stepping the motor without software lag making jerky motion, you might want to considder using the UDBs to build the interface so that it will operate along side of the processor code.  According to the A3967 datasheet, you are required to have a step frame of at least 2 uS, with 1 uS on and 1 uS off on the step pin, so this looks like a job for a timer/PWM/ or just a Datapath state machine. So, esssentially, the PSoC isn't generating the phasing of the motor, the controller is, and the only thing the PSoC need do is generate a pulse at a consistant rate, which is not that far off from the brushed DC motor with which you have been working.

   

smooth acceleration of the motor can be achieved by using smart use of the micro-stepping pins, MS1/MS2 to select between full,half, etc. and that can be based on the distance you need the motor to travel, or ramped up when starting/stopping the motor. on the A3967, there are 4 step sizes that can be achieved, which can be used to move to a precicse position, or used to control the speed of rotation with a constant step pulse stream being generated from the PSoC.

   

Hope that helps!

   

Chuck

0 Likes
Anonymous
Not applicable

 Yes, it seems that combining the step sizes can give some cool features. 

   

Generating the pulses will all have to be done in hardware. Or using a serial sender ( UART TX ) and a buffer - just preload the set word in the buffer based on how many steps I need to take ? than set the Bits per sec as speed - this limits the speeds to discrete BPS vals but it should work without CPU - I think ? 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Use this chip and control it with your PSoC. You may of course copy the insides of that device and re-program what you need into the PSoC5.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

   

 

   

At this price maybe buy another PSOC 5LP and add a bare fet driver.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

My emphasis was on the second sentence, that with the "copy"

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You cannot copy the inside of that device because there is a significant

   

amount of slew, thermal, regulation, and other analog stuff. You could,

   

with some effort, implement partial synthesis of the functionality of the

   

analog with PSOC + external sensors, components. But messy.

   

 

   

You can of course copy some of the digital into PSOC.

   

 

   

Most cost effective approach is external power driver with or without MOSFETs,

   

at minimum gate drive capability, with thermal, and PSOC for control.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Thanks for all the info! I thought it's a nice option to also get a PSoC and emulate the I2C driver - that has loads of distributed computational potential. 

   

For the moment I ordered a pair of these ICs: PCA9629A - hopefully they will work well but I'll let you know as I test. 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Becuse of motor driving currents and transients layout and bypassing is

   

everything in the design. Hopefully these will help -

   

 

   

    

   

         

   

http://www.cypress.com/?rID=39677     AN57821 - PSoC® 3, PSoC 4, and PSoC 5LP Mixed Signal Circuit Board Layout Considerations

   

http://www.cypress.com/?rID=40247     AN58827 - PSoC® 3 and PSoC 5LP Internal Analog Routing Considerations

   

http://www.cypress.com/?rID=39974     AN58304 - PSoC® 3 and PSoC 5LP – Pin Selection for Analog Designs

   

 

   

www.dropbox.com/s/ruaf9booe17jk8n/PCB%20Layout.zip

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

So... just to post some updates. The I2C driver seems to be ok, however it needs an extra high current IC, increasing complexity and cost. 

   

I have found this little guy: https://www.sparkfun.com/products/retired/13226  ( based on the Allegro 3967 IC ) which only needs a pulse train and a direction pin. 

   

My big question now is .... How do you think would be best to generate a specific length pulse train from the PSoC ? I need to generate   X pulses and know how many I have output and also do other things in the mean time - I don't want to block the CPU. 

   

I am thinking of a timer that will give me the pulses at a specific frequency. However I need a counter with that to know how many pulses I have generated. 

   

Or maybe a down counter that would count the pulses than stop on zero. 

   

Any ideas are welcome 🙂 - Thank you! 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The interrupt system of the PSoC5 is fast enough to handle a timer counted down to zero. More challenging will be to vary the pulse frequency to allow for start ramps having the stepper running at faster speeds.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Given that you want a pulse train counted w/o CPU intervention, a Timer or PWM

   

to develop the pulses and a counter that counts the pulses and gates N pulses for

   

you. Fairly simple, down counter could gate the timer enable off with a D and you

   

use a control reg to reset the D to initiate another burst of pulses. Or basic variants

   

of this scheme.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

So... I tried to do the checks and stops in software with no luck. The biggest problem I have is to capture accurately when the pulses are done, i.e. count complete and be able to restart after. I didn't find any good way to store the TC/ Comp pulse and use that. 

   

The hardware solution you mentioned Dana seems better. But trying a SR Flip Flop led me nowhere - I can't set it up so it stops after steps are done and waits for a reset from register. 

   

I am thinking I could disable PWMs once steps are done or set the pulse to zero. Than, for a new command reset counter and brings pulses back to desired speed. The scenario is: 

   

I set it to do X steps. Once it finished it will stop. Than I either run again, keep speed zero or set a new step number. 

   

 

   

Regarding speed setup, it's very easy, just change the PWM frequency and it sends more pulses - hence higher speed. 

   

 

   

 

   

This should in theory be a simple problem- capture pulse from TC/Compare in a SR and that sets my PWM to zero. Also updated a value in a sticky status register. Than I read the reg and if pulses are done update new command. 

   

No idea why it will not work. 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Use a different much higher clock for your sticky status register (if you still need them)

   

I strongly suggest to use an interrupt-driven approach. connect an interrupt component to your counter, use _StartEx to define the handler within your code. Do not forget to remove the interrupt cause by reading the counter status. Use a very high clock for the counter, see datasheet: The clock is not counted, it is used to detect a pulse on the count input!!!

   

Connect PWM to Count. Setup PWM frequency and pulse width. Set counter to count down, load number of pulses and start counter.

   

Start PWM.

   

In counter's interrupt handler stop PWM, read counter status and stop counter. Set a volatile global flag to indicate that stepping is done.

   

 

   

Happy coding

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a basic pulse burst generator. The Npulses = Timerperiod +2

   

 

   

Its triggered by a write to TrigPulseTrain control register.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Note you can replace timer with PWM so that you add duty cycle control.

   

 

   

Or use a counter, basic logic should work for the design.

   

 

   

Regards, Danma.

0 Likes
Anonymous
Not applicable

Thanks Bob and Dana. 

   

I got the ISR project as suggested by Bob up and running in the end. 

   

However, the HW approach you suggest is quite neat and I like the fact I have no processor intervention. I would need to vary the pulse frequency. I think it can be done by changing the clock to a derived one (using another timer) 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Use the clock APIs to change their frequency, the one I used as 1 Mhz. In component datasheet.

   

 

   

Leave the BUS_CLK clock alone

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The pulse frequency is best modified by changing the PWM period yalue and adjusting the compare value.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

No PWM is used in design posted, although that is an alternative, which as

   

pointed out earlier, permits DC modification. So using clock divider api's make

   

most sense for the posted design.

   

 

   

I have one more design to post, using fixed 7 bit counter in UDB, which

   

uses less resources than the timer that was core of earlier posted design.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is count version, ranges from 3 pulses to 131 pulses, uses less resources.

   

 

   

Regards, Dana.

0 Likes