Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: PWM gaps? Post ReplyPost New Topic
<< Prev Page of 7
Author
Message << Prev Topic | Next Topic >>
Malibu
Regular Member
Regular Member


Joined: 07 July 2018
Location: Australia
Online Status: Offline
Posts: 61
Posted: 14 August 2018 at 6:03pm | IP Logged Quote Malibu

In a "What if..." moment of clarity, I looped the PWM output to a count pin to see what was going to happen...
Here's the code
j=0
Print "Beta 6"
do
  setpin 52, cin
  For i = 20 To 128000 step 5
    PWM 1, i, 50
    Pause (1000 / i) * 1.1
    Next i
  PWM 1, stop
  print " Stage:";j; "    Pulses:"; pin(52)
  j = j + 1
  pause 3000
  if j = 10 then
    do:loop
  end if
loop

(Basically, same core code as before, but with SETPIN and a few PRINT statements)

Here's the results
Quote:
Beta 6 - STEP 1
Stage: 0 Pulses: 1709251
Stage: 1 Pulses: 1709109
Stage: 2 Pulses: 1709212
Stage: 3 Pulses: 1709278
Stage: 4 Pulses: 1709182
Stage: 5 Pulses: 1708996
Stage: 6 Pulses: 1709310
Stage: 7 Pulses: 1709131
Stage: 8 Pulses: 1709129
Stage: 9 Pulses: 1709181

Beta 8 - STEP 1
Stage: 0 Pulses: 1648042
Stage: 1 Pulses: 1648073
Stage: 2 Pulses: 1648296
Stage: 3 Pulses: 1648248
Stage: 4 Pulses: 1648282
Stage: 5 Pulses: 1648240
Stage: 6 Pulses: 1648331
Stage: 7 Pulses: 1648310
Stage: 8 Pulses: 1648149
Stage: 9 Pulses: 1648094


Beta 6 - STEP 5
Stage: 0 Pulses: 341834
Stage: 1 Pulses: 341814
Stage: 2 Pulses: 341768
Stage: 3 Pulses: 341787
Stage: 4 Pulses: 341809
Stage: 5 Pulses: 341801
Stage: 6 Pulses: 341814
Stage: 7 Pulses: 341824
Stage: 8 Pulses: 341831
Stage: 9 Pulses: 341793

Beta 8 - STEP 5
Stage: 0 Pulses: 329653
Stage: 1 Pulses: 329266
Stage: 2 Pulses: 329445
Stage: 3 Pulses: 329577
Stage: 4 Pulses: 329528
Stage: 5 Pulses: 329676
Stage: 6 Pulses: 329375
Stage: 7 Pulses: 329635
Stage: 8 Pulses: 329470
Stage: 9 Pulses: 329575


The heading shows what Beta version it's running, plus what STEP the value is.
"Stage:" is what part of the 10 cycles it's doing, and "Pulses:" is the pulses counted back on the interrupt pin.
Not concerned with the small variation of pulse counts in each group of 10 - that's expected. A hundred or so count difference over 1.7 million pulses isn't a big deal!
It seems odd that Beta 6 counts and Beta 8 counts (comparing STEP 1 to STEP 1) have such a large difference (around 60-65k). I'd have thought the count would be pretty close to each other.

Any thoughts?

__________________

John


Back to Top View Malibu's Profile Search for other posts by Malibu
 
matherp
Guru
Guru


Joined: 11 December 2012
Location: United Kingdom
Online Status: Offline
Posts: 2198
Posted: 14 August 2018 at 6:19pm | IP Logged Quote matherp

John

I've been following this thread with interest thinking how it might relate to my ports of MMBasic to the MMX, Picromite and Armmite but thinking about it more today my view FWIW is that using PWM is simply the wrong way to drive a stepper motor.

The essence of driving a stepper motor not just rotation speed but also positioning and it is not realistic to position with PWM. A very simple CFunction could be written that would send out N pulses at frequency F and this could include a command stack that would allow subsequent N/F pairs to be pre-loaded (N could be set to zero to indicate continuous until the next command). This would guarantee both perfect pulses and transitions. Pulse accuracy of < 1uS should be easily achievable.

I've already created a CFunction that does something similar - see this thread and could write something based on this if it would be generally useful. Can you specify the range of pulse frequencies that you would require.
Back to Top View matherp's Profile Search for other posts by matherp
 
Geoffg
Guru
Guru
Avatar

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2382
Posted: 14 August 2018 at 7:20pm | IP Logged Quote Geoffg

matherp wrote:
my view FWIW is that using PWM is simply the wrong way to drive a stepper motor.

I believe that you are spot on Peter.

When this started there were a number of flaws in the PWM output that needed fixing (and they are fixed now). But, as I have dived deeper into this it has become obvious that the PIC32 PWM function was never designed to drive steppers. For that you need features like delivering an accurate number of pulses, ramp up/down in speed, etc.

PWM is best left to simulating an analogue output, making simple sounds, etc.

The only problem is that the PIC32 peripherals are not a lot of help in doing the things that a servo would need. So you would need to write some nimble code in the CFunction.

John,
I have gone through some of the traces that I have collected and I can see that break that you are talking about. It is random (which is why I did not spot it before) and quite long (well, a millisecond or two). What causes that I am not sure but unfortunately I have run out of time so I will have to leave it for now.

Geoff

Edited by Geoffg on 14 August 2018 at 7:27pm
Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage
 
KeepIS
Senior Member
Senior Member
Avatar

Joined: 13 October 2014
Location: Australia
Online Status: Offline
Posts: 118
Posted: 14 August 2018 at 7:51pm | IP Logged Quote KeepIS

The PWM function is handy though when you use it to drive a digital stepper controller in the background in a closed loop system. It leaves the main code to decode and monitor the positional sensor data while roughly control PWM frequency as needed, I use PWM for this reason and skips, frequency changes, glitches etc have no affect on the accuracy of the stepper motor position or control.

If Peters C code can run in the background then I for one would love to try it, the only problem I have with using PWM is if the interpreter breaks during development for any reason, the motors just keep on going until they hit the limit switches or I press an external emergency stop override.

Have a nice trip Geoff and thanks again for all the work, upgrades and extra features.

__________________
It's all too hard.
Back to Top View KeepIS's Profile Search for other posts by KeepIS
 
Malibu
Regular Member
Regular Member


Joined: 07 July 2018
Location: Australia
Online Status: Offline
Posts: 61
Posted: 15 August 2018 at 7:45am | IP Logged Quote Malibu

Quote:
my view FWIW is that using PWM is simply the wrong way to drive a stepper motor.

Thoroughly agree for the 'normal' concept of a stepper motor (ie: positional accuracy to the N'th degree of rotation). If I was looking for that sort of motor control, PWM wouldn't be the way to go. In fact, the only reason I selected a stepper is the VERY slow RPM's Vs usable torque compared to a DC motor (or even a BLDC motor) which has next to useless speed/torque characteristics down low (Been there, done that!) - there's a whole subject of discussion in that debate as well, but I'll keep it simple.

Peter if you're happy to have a crack at a CFunction, I'm happy to give it a go in the real world testing. (I looked into the CFunction idea as well, but C & me don't get along, so I got scared off)
Here's a couple of ideas that might get you started, some specific to my application, but a good generalisation...
* DRV8825 requires a high/low width of 1.9uS minimum, but some (like the new DRV8886) are shorter at 970nS width, and the TB67S269 at 300nS.
* Variable frequencies between say, 20Hz LOW (in Full step, that's 36 degrees of rotation and in 1/32 mode it's 1.2 degrees of rotation per second) and 200kHz HIGH (Full step, 1000 revs/second (an impossible goal), and 1/32 mode, 32 revs/second)
* A ramp up/ramp down option. Sending 200kHz to a static stepper in 1/32 mode will put it straight into a stalled condition, so it needs to get there by increasing the HZ. Stopping a stepper from full speed to 0 will see the inertia of the rotor physically jump the motor across the table, hence the ramp down.
* Needs to be run in the background, so the Function is called and the main code will continue to run while it drives the motor.
* re: 'N' - A good general option to have a stepper 'index' a certain point and stop (woo-hoo! That's what a stepper is meant to do! ), with , as you say, set to zero for continuous run would also be needed.

To my way of thinking, a good function call would be something like this -
STEP Start, [End], [Duration]
STEP - obviously to call the function
Start - The starting frequency
End - Optional ending frequency (Set START low and END high will ramp up, START high and END low will ramp down, not set has no ramp)
Duration - optional, but setting that gives the time to run (a default value of zero is continuous run)

That's my two-bobs worth, but may not even be achievable... it's just an idea to throw out there

Quote:
I can see that break that you are talking about

I guessed you may have missed it because it took me ages to nail it down too. I'm glad you can see what I'm blathering on about now instead of thinking me a looney!
I'm probably in a better test position because I have a working motor drive and if there's a problem, I can pick it as soon as the drive starts up.

Quote:
I have run out of time so I will have to leave it for now

Absolutely not a problem! As I've said, I'm more than happy running Beta6 because it runs smooth as silk, so put it out of your mind and go enjoy your EU visit! (Stay safe and have a good time)

Quote:
the only problem I have with using PWM is if the interpreter breaks during development for any reason, the motors just keep on going

Yup, that's a regular occurrence! My setup just keeps going around, so it's not a big deal but can be a problem if there's physical limits involved.

Peter, if you want to go down the path of a CFunction, let me know what I can do to help out and I'm happy to do what I can.


Edited by Malibu on 15 August 2018 at 7:49am


__________________

John
Back to Top View Malibu's Profile Search for other posts by Malibu
 
StoveMan
Regular Member
Regular Member


Joined: 29 March 2013
Location: United States
Online Status: Offline
Posts: 50
Posted: 15 August 2018 at 10:56am | IP Logged Quote StoveMan

@Malibu,
Just saw this thread.... as Peter says driving a stepper this way will be the hard way around. As I understand it you need a programmable speed control for a takeup winder. Have you determined what torque you need at what rpm range. As you are finding, steppers are great at low rpm but torque is almost zero when you get much over 1800. Resizing a stepper wont usually help as larger windings lead to more inductance. A dc motor properly sized is what I would spec. There are loads of small gearmotors from the surplus and hobby world which should do eg www.servocity.com
Utilizing feedback with say a kangaroo controller from dimension engineeringSelf tuning servo will let you do low rpm right up to a (current) torque limit you set. Very easy to drive from MMBasic. Simple serial or 0-5volt works great. You could also do a tandom motor setup to increase low end torque.

Having tried using a stepper thus I will say you probably will never be able to trust you wont stall; unless you use feedback as was suggested. A dc motor, brushed or not, gives you a very predictable torque curve

Back to Top View StoveMan's Profile Search for other posts by StoveMan Visit StoveMan's Homepage
 
Malibu
Regular Member
Regular Member


Joined: 07 July 2018
Location: Australia
Online Status: Offline
Posts: 61
Posted: 15 August 2018 at 11:37am | IP Logged Quote Malibu

I've been pondering the CFunction idea, and now that I'm a bit more awake...
STEP Start, [End], [Duration]
would need a bit more to it...
STEP Start, End, UpTime, DownTime, Num, [Duration]
...to give:
Start: Start Hz
End: End Hz
UpTime: Ramp up time
DownTime: Ramp down time
Num: Stepper channel number (for more than 1 motor)
Duration: Length of pulses

To me, it's starting to sound pretty complicated, so not sure if it's doable.

G'day Stoveman, thanks for those links (the Dimension Engineering one timed out - I'll try again later) and I've looked at servos too. I like those ones you linked to, I'll keep them in mind for other projects in the future!
Torque isn't a problem, there's very little load on the motor shaft. Speed is kept to under 1200RPM so also not a problem. Feedback is on the 'to-do' list (partly for counting, but also as a point of reference for control). If there's a stall (too much load?), the feedback will be compared to the pulses sent to the motor and if the math doesn't work out, I'll fire an 'electronic shear pin' to pull the motor up dead.

A word on the load that will be on the motor; With 42AWG diameter (0.063mm) it's so thin, you'd never get enough tension on the wire to pull the motor up without breaking the wire first.



__________________

John
Back to Top View Malibu's Profile Search for other posts by Malibu
 
Geoffg
Guru
Guru
Avatar

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2382
Posted: 15 August 2018 at 8:41pm | IP Logged Quote Geoffg

At the risk of driving everyone crazy with this long running thread a bright idea came into my head as to what might be causing this new gap.

The details are complicated but it could be caused by a PIC32 interrupt occurring at a critical point when the register controlling the frequency is updated. I have built a new beta (Beta 9) which disables all interrupts at this critical time.

As usual this can be downloaded from: http://geoffg.net/micromite.html
Look for "Micromite Firmware V5.04.10 Beta Test Version" at the bottom of the page.

I have checked with the logic analyser and I cannot see any gaps. This does not guarantee anything but hopefully John you can try it on your long suffering servo.

Geoff
Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
<< Prev Page of 7
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1724 seconds.
Privacy Policy     Process times : 0.05, 0, 0, 0.12