PDA

View Full Version : PWM/HPWM Stepper Motor Controller



DavyJones
- 28th September 2020, 14:01
Hi, I'm just getting into a project that I want to control the speed/direction of a stepper motor using a stepper motor driver/controller (https://www.amazon.com/gp/product/B07PQ5KNKR/ref=ppx_yo_dt_b_asin_title_o07_s02?ie=UTF8&psc=1) which seems pretty straight forward. At least for controlling the direction and enable disabling the motor. I have the controller in the link above. It doesn't come with any instructions other than printing on it you can set the dip switch to the number of pulses it needs to receive for one revolution. It has me puzzled how to actually control the speed there I'm not getting it I look at 200 pulses and think that would be HZ. I'm kind of stuck has anyone used a PIC to feed one of these controllers?
Thanks
David

Dave
- 28th September 2020, 14:23
These type of controllers require a digital direction input, an digital enable input, and last but not least, a digital step input. The controller will advance the motor 1 step for every digital input pulse. Depending on the steps per rev. setting made thru the dip switches.

DavyJones
- 28th September 2020, 15:09
These type of controllers require a digital direction input, an digital enable input, and last but not least, a digital step input. The controller will advance the motor 1 step for every digital input pulse. Depending on the steps per rev. setting made thru the dip switches.

Agreed..... I think I understood that what I am missing is if I am am going to send PWM/HPWM out on one of the pins (lets say as an example I set it up for 200 pules per revolution) is that 200 pulses per second or? How if I set it up for 200 pulses per revolution would you regulate the speed?
Thanks

David

mark_s
- 28th September 2020, 17:59
This is a simple way to generate step pulses



Count = 1

While count < 2000 ' Send 2000 pulses rotate motor 10 times

Latx = 1 'Output 10us pulse to stepper drive
pauseus 10
Latx =0

Count = Count + 1
pause 10 ' use this delay to slow down or speed up the motor
Wend

DavyJones
- 28th September 2020, 18:06
Thanks Mark_S that makes sense to me know
David

mark_s
- 29th September 2020, 00:02
David, at 200 steps per revelolution the motor will run rough. Once you get it running change the dip switches on the driver to 1/8th step or 1600 pulses/rev. It will run much smoother.

Mark

DavyJones
- 29th September 2020, 11:13
Mark thanks for the info. I'm new to working with stepper motors and their controllers. Seems a little easier to use a controller than to do all the programming to pulse all 4 inputs on the motor manually.
It looks like the NEMA rating just has to do with the size of the front or something here is the NEMA 23 (https://www.amazon.com/gp/product/B00PNEPF5I/ref=ppx_yo_dt_b_asin_title_o08_s01?ie=UTF8&psc=1) one I got. It looks like this is rated 2.8 amps so would you mind I should set my controller dip switches to reflect 2.8 amps right?
Thanks
David

mark_s
- 29th September 2020, 17:48
Mark thanks for the info. I'm new to working with stepper motors and their controllers. Seems a little easier to use a controller than to do all the programming to pulse all 4 inputs on the motor manually.
It looks like the NEMA rating just has to do with the size of the front or something here is the NEMA 23 (https://www.amazon.com/gp/product/B00PNEPF5I/ref=ppx_yo_dt_b_asin_title_o08_s01?ie=UTF8&psc=1) one I got. It looks like this is rated 2.8 amps so would you mind I should set my controller dip switches to reflect 2.8 amps right?
Thanks
David

It's depends on your power supply voltage and what you are driving with the motor. I would start at half of the rated current and see how it works. Yes the NEMA number is the mounting size. What are you driving with your motor?

DavyJones
- 30th September 2020, 00:28
It's depends on your power supply voltage and what you are driving with the motor. I would start at half of the rated current and see how it works. Yes the NEMA number is the mounting size. What are you driving with your motor?

I'm going to be driving a drive pulley for a conveyer belt so things will be going slow don't need a lot of torque or speed.

thanks I will start off at half power and 200 rev's see how things go

Thanks
David

DavyJones
- 30th September 2020, 11:17
Normally I would design and build everything necessary to perform the tasks I need to with a PIC. In this case though to speed up development of my project I decided to use the stepper motor controller and relay module I am using to speed things up. The PIC is still doing all the work. I am working on a conveyer belt system that will move parts under a sprayer to get coated with a substance. I am controlling a solenoid to turn air on and off and a second solenoid to control dispensing the liquid, in this case for testing it is water. One thing I noticed since the nozzle is gravity fed and upside down as seen in my video, the gravity feed will produce a stream of water when the air is not engaged basically a constant drip so controlling the liquid flow (on and off) eliminates the drip. I did find no drip nozzles where I would only need to control the air flow but at $400 a pop that was not going to happen. The ones I am using are $20. My video is a mock up model for testing. I plan on adding a small conveyer pulley today and also control the stepper motor. If that succeeds I plan on moving to the next phase and build the working frame. I plan on using the extruded aluminum like many 3D printers use for frames.
If you or anyone else is interested in my progress as I move through this project I can keep posting the little videos I make.
Thanks for your help so far.
David
The air and liquid are not coming on simultaneously. The air valve is open first then 100ms seconds later I open the solenoid for the liquid. After 500ms of them both being on I turn them both off simultaneously then pause for 2 seconds to start the cycle again. This is producing almost virtually no drippage from the valve but I have on occasion seen a build up and a rogue drip is produced. I will mess with the timing to see if I can totally eliminate that or a tiny drip once in a while is not going to be bad since the part will have moved past the nozzle by that time.
https://www.youtube.com/watch?v=nCDnpe8cDB4

mark_s
- 30th September 2020, 19:05
I am interested in following your project. It's nice to see a real application being developed.

Thanks for posting

DavyJones
- 30th September 2020, 22:34
I am interested in following your project. It's nice to see a real application being developed.

Thanks for posting

Sounds great I will keep posting to the thread as I go through my project... btw I am using a 12F683 since I had one laying around after my last project and I don't really need much for this. I'm setting up the stepper motor and about to give it a try in a few minutes.

David

DavyJones
- 30th September 2020, 23:04
Mark you obviously have experience with this controller (I hope) I am stuck with the connections to ena-, ena+, dir-, dir+ and pul-, pul+
I was assuming ena went to - and ena+ went to + dir - to - and dir+ to + and pul- to - and for pul+ I connected that to the pic to send the 1 and 0
I'm trying to find an example on the web haven't found one yet i am sure I am wrong as the stepper does not spin

DavyJones
- 30th September 2020, 23:22
Mark you obviously have experience with this controller (I hope) I am stuck with the connections to ena-, ena+, dir-, dir+ and pul-, pul+
I was assuming ena went to - and ena+ went to + dir - to - and dir+ to + and pul- to - and for pul+ I connected that to the pic to send the 1 and 0
I'm trying to find an example on the web haven't found one yet i am sure I am wrong as the stepper does not spin

Mark, Never mind I got it... the 12F683 did not like ROTOR=1 and ROTOR=0 I needed to high ROTOR and low ROTOR
it's spinning now going to try and make it smoother and faster mess around with those a bit

DavyJones
- 1st October 2020, 00:09
Mark, so I have been messing around with the time and seems to work pretty smooth. I am running 12v power supply and have the controller set to 1.5a and 1600 pulse per revolution. It is very smooth and easily see how to adjust the timing to speed it up or slow it down. One thing at these settings there is not much torque. I can grab the spindle and dont have to hold to tight to get it to not turn and growl at me. Motor says it is rated at 2.8amps but doesn't list the voltage but many people are saying 24v is optimum and can run up to 48 volts. If I up the current on the driver will that give me more torque or do I have to also up the voltage. At this configuration I doubt this will move my parts on the converyer once I have it built.
Thanks

mark_s
- 1st October 2020, 01:25
You are making a lot of progress. Increase the current setting, just monitor the motor for excessive heat while experimenting. 12 volts is on the low side for what you are doing. For small projects I have used old laptop wall supplies. They are usually around 18v at 3amps. You can find them in the thrift shops for cheap.

DavyJones
- 1st October 2020, 11:30
Mark thanks.... I was looking at power supplies online last night. Do switching type power supplies present any problems for the stepper motor? I see quite a few cheap ones online and some even have 24v/12v/5v output which would be perfect for my project without have to have any type of step down converters. 24v for stepper, 12v for solenoids and 5v for pic and accessories. I've probably pitched to many old pc's with perfectly good power supplies in them over the years whats wrong with me.... I just re-read your post I've got boxes of old laptop power supplies around here I just found an old dell one that is 19v 3 amp

Thanks
David

DavyJones
- 1st October 2020, 12:23
I know we are getting a little off topic with regards to PIC's and Picbasic I hope that's ok my project overall is dependent on the PIC and the programming needed.

Sorry about the noise in the background my wife was watching TV.
https://www.youtube.com/watch?v=acHMc_8X9hg

I'm thinking of something like this to power the overall project which needs 3 different voltages (https://www.amazon.com/gp/product/B019GYOHGI/ref=ox_sc_act_title_2?smid=ATVPDKIKX0DER&psc=1).
Then the step down (https://www.amazon.com/gp/product/B07BKR95PY/ref=ox_sc_act_title_1?smid=AFHAE9RJVUMB&psc=1) for the other 2 both are relatively inexpensive.

DavyJones
- 1st October 2020, 15:42
I was thinking ahead a little bit and for now my testing has been to test the solenoid activation and stepper motor each by themselves. Now they will need to work in conjunction with each other wherein the stepper motor will need to continue to move (and keep the conveyer belt moving) at the same time the solenoids are cycled on and off. There will be gaps in between the items I will be spraying. I am sure I can complete this using 2 picks, one to control the solenoids and another to control the stepper motor. I would add an interupt test to the stepper pic so after the last row has passed I can stop the stepper anywhere in it's loop. I don't see anyway around this since everything is single threaded (at least thats what I've always thought) and branching from the stepper routine would add timing to the stepper loop which I think would through everything out of whack. using 2 pics is no problem and getting them to talk to each other not going to be a problem either because I think I'd just need to use interupts either with an INT function or just checking the state of a pin at some point.

I wanted to know though if anyone has ever used one of these and/or if there is any support in Picbasic for this dsPIC33CH (https://www.allaboutcircuits.com/news/microchip-introduces-its-new-line-of-microcontrollers-dspic33ch-family/). It's funny the example they choose to show what you can do with this is pretty close to what I am needing this for.

HenrikOlsson
- 1st October 2020, 18:12
David,
You've done a great job so far!
As you might know the torque of step motor falls off as the speed increases. Increasing the drive voltage counteracts this drop in torque. Doubling the voltage pretty much doubles the speed at which the motor stalls due to "overload". This is within reason of course, too much will only result in heat in the motor and if you do get what you need out of it with whatever voltage there's no real gain in increasing it even further.

One rule of thumb from a drive manufacturer (Geckodrive) is that supply voltage to the drive could be as high as 32*(sqrt)L where L is the inductance in mH.

Lets say your motor has an inductance of 2.8mH, then the drive voltage can be around 50V. Obviously the drive has to be rated for the voltage as well.
I don't know any details on your particular motor but I'd certainly try a 24V supply or even a 48V if you still need more speed.

Slow speed torque is highly dependent on the current setting of the drive.

Finally, it's hard for a motor to start "instantly". You'll be able to reach much hiher speeds by ramping the speed up/down.

If you generate the step pulses in hardware, like with the CCP module (as with HPWM ) then you have all the time in the world to figure out when to fire the solenoid(s).

Nope, PBP is for 8-bit PICs only, no 16 or 32bit devices.

/Henrik.

DavyJones
- 2nd October 2020, 00:49
Henrik, Thank you and thanks for your explanation. I've not done any work with the stepper motors so I'm still learning. I'm actually not trying to get much speed out of the stepper. I will be driving a conveyer and it will be moving small parts under my spray nozzle so it's not going to go fast at all so the parts can get evenly coated.

I'm going to start to look into generating the pulse with HPWM I've never done that before

Thanks for letting me know about that ds device good to know.

David

mark_s
- 2nd October 2020, 01:06
If you generate the step pulses in hardware, like with the CCP module (as with HPWM ) then you have all the time in the world to figure out when to fire the solenoid(s).

/Henrik.

Henrik, I always wanted to try using the CCP module for this purpose, but not sure how to keep track of the number of pulses. Maybe feed the pwm output into a timer to keep count?

Mark

DavyJones
- 2nd October 2020, 01:24
Mark maybe we can work this out together with Henrik's assistance. I went to the micro chip site and used their processor selector to find one that had the PWM built in. It looks like the 12F752 has what I need to try to get the HPWM to work. The datasheet says

• Capture, Compare, PWM (CCP) module:
- 16-bit Capture, max. resolution = 12.5 ns
- Compare, max. resolution = 200 ns
- 10-bit PWM, max. frequency = 20 kHz

Thats what I am looking for right? I've not read the rest of the datasheet. I picked this one out because I think I have one here already to start to work with.
Thanks
David

HenrikOlsson
- 2nd October 2020, 11:18
Mark,
Yeah, for precise positioning feeding the pulses back into the PIC and count them OR integrate generated velocity over time to calculate position. Possible but not exactly easy to get right, I'd say.
But for the application described here I don't think precise position control is needed, just precise velocity which the CCP module will do without any software overhead - except during acceleration.

Depending on the needed frequency and acceptable jitter perhaps the NCO available in some devices would be even better for this.

David,
At your desired conveyor belt speed, what approximate frequency are you generating? Is it 100Hz, 1000Hz, 5000Hz?
For the CCP module you could use the HPWM command but if you want to implement acceleration then I would ditch HPWM and set the registers manually.

/Henrik.

DavyJones
- 2nd October 2020, 12:52
David,
At your desired conveyor belt speed, what approximate frequency are you generating? Is it 100Hz, 1000Hz, 5000Hz?
For the CCP module you could use the HPWM command but if you want to implement acceleration then I would ditch HPWM and set the registers manually.

/Henrik.

Henrik, Thanks.... well that is going to be trial and error at this point. I actually am going to have to hook up my conveyer belt and use the pulse method I've been using so I can get an idea. i need to see the spray turned on and how fast I can make the part travel under the spray and get it coated good. It's not going to be traveling very fast I'm sure. When I manually spray my parts with my detail sprayer I'm not moving my hand very fast over the parts. At this point I really could not say at how many feet per minute or anything like that. My gearing ratio is going to affect that too. Right now I have about a 1:1 ratio on there. Now that I see what I am working on is do-able I've ordered my aluminum framing material so I can start to bring things together. The speed of the belt will be constant. Start - go a little distance, Stop

What do you think about the 12F752 (http://ww1.microchip.com/downloads/en/DeviceDoc/40001576D.pdf) just to tinker around with the HPWM... I asked because I never worked with PWM before just wanted to make sure that pic will work. Reading the specs and looking at some sample code I think just to mess around that will work.

Thanks
David

HenrikOlsson
- 2nd October 2020, 16:03
I see no reason for it not to work.
But with an 8-pin device you're quickly running out of pins, step pulses out, solenoid drivers, perhaps a sensor of some sort to detect the items on the belt, a start/stop button, perhaps some means to output debug information or parts count to a LCD? It adds up...

If you already have it go ahead and play, if you're ordering it and there's no real reason for an 8-pin device then perhaps something like the 16F1825? More pins, more FLASH, more RAM and an UART. It does also cost more but I reccon you're not building thousands of these so it doesn't matter much :-)

DavyJones
- 3rd October 2020, 11:08
Henrik, agreed about the need for the extra pins. I will be switching to the 16F series for sure I've already thought of the extra pins I will need stop/start, Jog, , manual speed, lcd, direction, sensors, etc... I just quickly looked on microchip part picker and I am pretty sure I had the 12F but I didn't see any on their list that had HPWM in the 16F series that I had and I want to get started and have things worked out. Going to order some 16F's now which will take about a week to get here, I don't want to wait to see it work. I have a good bit of time to test things before I would actually put my conveyer to use I still need to work on the frame and belt mechanism itself. The framing material will be here in about a week I will keep this thread going as I progress through adding different functions to the PIC
Thanks
David

DavyJones
- 4th October 2020, 14:19
This is going to be a stupid question and one I could answer myself by just testing it but I will ask anyway. If the stepper is set to 1600 pulses per revolution and I send it 800 pulses I'm assuming it is going to go around half way and stop... see a stupid question the I guess figuring in the gear ratio you could get very small movement like in a 3D printer (I'm not doing a 3D printer but I thought it would be a good example.)
Thanks
David

HenrikOlsson
- 4th October 2020, 15:27
Yes, exactly so :-)
That's sort of the idea behind the stepper motor - that you can relatively precisely control both the speed and the position without needing some sort of feedback device and "complicated" control algorithms. For that reason steppers have been and are being used in a LOT of mechatronic devices like printers, robots, machining equipment, optical stages, light effects, throttle valves in cars and many many other things.

DavyJones
- 4th October 2020, 17:47
Yes, exactly so :-)

Henrik thank you I thought so. By the way if anyone is interested I got the power supply and dual dc/dc converter and they work beautifully. I have 24v for the stepper, 12v for the solenoids and 5v for my main board.

Power Supply (https://www.amazon.com/gp/product/B019GYOHGI/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1)
Tunable dc/dc converter (https://www.amazon.com/gp/product/B07BKR95PY/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1)

DavyJones
- 5th October 2020, 21:13
Argh... RTFDS! David haha the 12F683 that I have been testing with has PWM in it whats wrong with me. I do have some 16F pics coming to give me more input/output which I know I will need

DavyJones
- 12th October 2020, 11:39
I have not had a chance to work with the HPWM pulsing but I should soon. The past week I have been concentrating on getting the frame together for my small conveyor. Now that I have a more adequate testing apparatus I'll start to work on the HPWM piece of my code. I did order a couple 16F's to work with since I am going to need a few more input/outputs than I originally thought. I made the conveyor belt from window screen so as I pass my parts under the spray the liquid will pass through into a drip pan I plan to mount underneath. I through a hand full of whatever was light and closest to me for my video to show the belt actually moving under the stepper motor control. For now just for demonstration purposes I hard coded the program to move the belt very slow. The belt slips a couple times in the video and I adjusted the rollers so there is no more slippage. I'm probably going to rubber coat the rollers or maybe cut an old bicycle tire up and slip it on the rollers to give more of a rubber grip to the belt. I know we are not talking a lot of picbasic here yet but picbasic is going to do a lot more with this project so there will be more to come just thought folks might want to see this in action.

https://www.youtube.com/watch?v=VIqtZ-3J2-E&t=16s

mark_s
- 12th October 2020, 20:26
Your frame looks great.

What are your rollers made of PVC pipe?

DavyJones
- 13th October 2020, 11:18
Your frame looks great.

What are your rollers made of PVC pipe?

Mark, Thanks... yep they are just PVC pipe with end caps and a flange for 3/8" aluminum rod/axle. You can email me if you want some specifics on the parts I used.
[email protected]