Prev: Eternal September Rocks!
Next: Where can I get VSI1.1
From: Viper900 on 3 Jun 2010 00:30 Hi I writting a program to run a stepper motor using vb6, it uses the paraell port to communicate with the motor driver. It works, but the motor tends not to run smooth, it chugs around. i thing its got something to do with the delay. I am using this delay Pubic sub Delay(sngSeconds as single) Dim sngDoEventsTime as single Dim sngStart as single sngDoEventsTime=Timer sngStart= Timer Do while Timer - sngStart < sngSeconds if Timer - sngDoEventsTime > o.5 then DoEvents sngDoEventsTime = Timer end if loop For this Sub I set the delay to: 0.5 I have also used this delay Public Sub Delay(ByVal Seconds as single) Dim t as single t = timer do while Timer - t < Seconds loop For this Sub I set the delay to: 0.1 Anyone got any ideads for me Thank you
From: Dee Earley on 3 Jun 2010 09:35 On 03/06/2010 05:30, Viper900 wrote: > Hi > I writting a program to run a stepper motor using vb6, it uses the paraell > port to communicate with the motor driver. It works, but the motor tends not > to run smooth, it chugs around. i thing its got something to do with the > delay. > I am using this delay > > Pubic sub Delay(sngSeconds as single) > Dim sngDoEventsTime as single > Dim sngStart as single > > sngDoEventsTime=Timer > sngStart= Timer > > Do while Timer - sngStart< sngSeconds > if Timer - sngDoEventsTime> o.5 then > DoEvents > sngDoEventsTime = Timer > end if > loop > For this Sub I set the delay to: 0.5 > > I have also used this delay > > Public Sub Delay(ByVal Seconds as single) > Dim t as single > t = timer > do while Timer - t< Seconds > loop > > For this Sub I set the delay to: 0.1 > > Anyone got any ideads for me I;d scrap the Timer function and use GetTickCount and work in milliseconds. You do need to be careful about the rollover though. Note that having DoEvents int he loop can throught the timiongo out widliy. If it decides to do something else costly, your loop will be helpd up. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems (Replies direct to my email address will be ignored. Please reply to the group.)
From: Steve on 3 Jun 2010 09:45 On Jun 3, 12:30 am, Viper900 <Viper...(a)discussions.microsoft.com> wrote: > Hi > I writting a program to run a stepper motor using vb6, it uses the paraell > port to communicate with the motor driver. It works, but the motor tends not > to run smooth, it chugs around. i thing its got something to do with the > delay. > I am using this delay > > Pubic sub Delay(sngSeconds as single) > Dim sngDoEventsTime as single > Dim sngStart as single > > sngDoEventsTime=Timer > sngStart= Timer > > Do while Timer - sngStart < sngSeconds > if Timer - sngDoEventsTime > o.5 then > DoEvents > sngDoEventsTime = Timer > end if > loop > For this Sub I set the delay to: 0.5 > > I have also used this delay > > Public Sub Delay(ByVal Seconds as single) > Dim t as single > t = timer > do while Timer - t < Seconds > loop > > For this Sub I set the delay to: 0.1 > > Anyone got any ideads for me > Thank you If the motor is running but seems to be stuttering, then you need to decrease (or possibly increase) your pause time between energizing each phase. As I explained in a previous thread your started on this issue (http://groups.google.com/group/ microsoft.public.vb.general.discussion/browse_thread/thread/ 8482493e8b123a61/40cc1eebe4c29f23?hl=en(cc1eebe4c29f23), the way this works is as follows: The stepper motor has 4 phases. We energize each of these in turn to pull the rotor around. It is important to understand what is going on here as this will help you to realize what you need to do when things aren't working quite as you would like...so let me try to explain this more visually. Lets use a clock as an analogy for our stepper motor. This clock only has a single hand (we'll use the second hand but that doesn't matter). This single hand will represent the rotor (the part which actually rotates) of our motor. The four phase of the motor are represented by the four quadrants of the clock centered around 12, 3, 6 and 9 positions on the clock. Thus phase 1 is from 11 to 1, phase 2 is from 2 to 4, phase 3 is from 5 to 7 and phase 4 is from 8 to 10. Each of these four phases is a magnet that we can energize with our code. Therefore to make the hand rotate we must turn the magnets on and off in sequence around the clock. So, for instance if phase 1 is currently energized holding the hand at straight up 12 o'clock and we want to rotate it 1 complete revolution in the clockwise direction we would do this: 1) De-energize (turn the magnet off) phase 1 (to allow the hand to move) and energize (turn on the magnet) phase 2 to pull the hand from 12 to 3 3) Wait a moment for the hand to actually complete its move (this is the delay in your code) 4) De-energize phase 2 and energize phase 3 to pull the hand from 3 to 6 5) Wait for the hand to complete the move 6) De-energize phase 3 and energize phase 4 to pull the hand from 6 to 9 7) Wait for the hand to complete the move 8) De-energize phase 4 and energize phase 1 to pull the hand from 9 to 12 What is probably fairly clear from the above illustration is that if we wait to long between steps the hand will get where it is going and just sit there until we energize the next phase. This would make for jumpy stuttering rotation. What is not as clear is what will happen if our delay is not long enough. In this case the hand will start to move but not get far enough before we de-energize the magnet pulling it and then energize one that is to far away to pull it. This means that once the hand has used up its momentum it will stop until our cycling code energizes another phase (could be either ahead of the hand or behind) which is close enough to move the hand. This situation (a delay which is to short) can make for a really jumpy rotation that even goes backwards occasionally. So to summarize, to make a stepper motor run smoothly you must get the timing right. Doing this is a simple trial and error process. As I explained in your previous thread simply lengthen your delay until the stepper is obviously running to slow (when you can actually see it stop at each phase). Then start decreasing the length of your delay. Continue decreasing the delay until the motor first smoothes out. This is the slowest you can run the motor smoothly. Now continue decreasing the delay until the motor starts to get jumpy again (this is the point at which your delay is to short). Now you have defined the longest and shortest delays you can use and still run smoothly. All that is required now it choose a value within that range that provides you the speed your process needs. Hope this helps, Steve
From: Charlie on 3 Jun 2010 11:16 Good explanation. It would be nice if the motor could send a signal (close a circuit, whatever) that would tell the program when the rotor had completed it's travel to the next quadrant, thereby allowing a "hand-shaking" method of synchronizing the device and software. I presume such motors exist. P.S. "To" is spelled with two o's when used in this context: "too long", "too short", "too slow", etc. ;) "Steve" wrote: > On Jun 3, 12:30 am, Viper900 <Viper...(a)discussions.microsoft.com> > wrote: > > Hi > > I writting a program to run a stepper motor using vb6, it uses the paraell > > port to communicate with the motor driver. It works, but the motor tends not > > to run smooth, it chugs around. i thing its got something to do with the > > delay. > > I am using this delay > > > > Pubic sub Delay(sngSeconds as single) > > Dim sngDoEventsTime as single > > Dim sngStart as single > > > > sngDoEventsTime=Timer > > sngStart= Timer > > > > Do while Timer - sngStart < sngSeconds > > if Timer - sngDoEventsTime > o.5 then > > DoEvents > > sngDoEventsTime = Timer > > end if > > loop > > For this Sub I set the delay to: 0.5 > > > > I have also used this delay > > > > Public Sub Delay(ByVal Seconds as single) > > Dim t as single > > t = timer > > do while Timer - t < Seconds > > loop > > > > For this Sub I set the delay to: 0.1 > > > > Anyone got any ideads for me > > Thank you > > If the motor is running but seems to be stuttering, then you need to > decrease (or possibly increase) your pause time between energizing > each phase. As I explained in a previous thread your started on this > issue (http://groups.google.com/group/ > microsoft.public.vb.general.discussion/browse_thread/thread/ > 8482493e8b123a61/40cc1eebe4c29f23?hl=en(cc1eebe4c29f23), the way this > works is as follows: > > The stepper motor has 4 phases. We energize each of these in turn to > pull the rotor around. It is important to understand what is going on > here as this will help you to realize what you need to do when things > aren't working quite as you would like...so let me try to explain this > more visually. > > Lets use a clock as an analogy for our stepper motor. > This clock only has a single hand (we'll use the second hand but that > doesn't matter). This single hand will represent the rotor (the part > which actually rotates) of our motor. The four phase of the motor are > represented by the four quadrants of the clock centered around 12, 3, > 6 and 9 positions on the clock. Thus phase 1 is from 11 to 1, phase 2 > is from 2 to 4, phase 3 is from 5 to 7 and phase 4 is from 8 to 10. > Each of these four phases is a magnet that we can energize with our > code. Therefore to make the hand rotate we must turn the magnets on > and off in sequence around the clock. So, for instance if phase 1 is > currently energized holding the hand at straight up 12 o'clock and we > want to rotate it 1 complete revolution in the clockwise direction we > would do this: > 1) De-energize (turn the magnet off) phase 1 (to allow the hand to > move) and energize (turn on the magnet) phase 2 to pull the hand from > 12 to 3 > 3) Wait a moment for the hand to actually complete its move (this is > the delay in your code) > 4) De-energize phase 2 and energize phase 3 to pull the hand from 3 > to 6 > 5) Wait for the hand to complete the move > 6) De-energize phase 3 and energize phase 4 to pull the hand from 6 > to 9 > 7) Wait for the hand to complete the move > 8) De-energize phase 4 and energize phase 1 to pull the hand from 9 > to 12 > > What is probably fairly clear from the above illustration is that if > we wait to long between steps the hand will get where it is going and > just sit there until we energize the next phase. This would make for > jumpy stuttering rotation. What is not as clear is what will happen > if our delay is not long enough. In this case the hand will start to > move but not get far enough before we de-energize the magnet pulling > it and then energize one that is to far away to pull it. This means > that once the hand has used up its momentum it will stop until our > cycling code energizes another phase (could be either ahead of the > hand or behind) which is close enough to move the hand. This > situation (a delay which is to short) can make for a really jumpy > rotation that even goes backwards occasionally. > > So to summarize, to make a stepper motor run smoothly you must get the > timing right. Doing this is a simple trial and error process. As I > explained in your previous thread simply lengthen your delay until the > stepper is obviously running to slow (when you can actually see it > stop at each phase). Then start decreasing the length of your delay. > Continue decreasing the delay until the motor first smoothes out. > This is the slowest you can run the motor smoothly. Now continue > decreasing the delay until the motor starts to get jumpy again (this > is the point at which your delay is to short). Now you have defined > the longest and shortest delays you can use and still run smoothly. > All that is required now it choose a value within that range that > provides you the speed your process needs. > > Hope this helps, > Steve > . >
From: Jeff Johnson on 3 Jun 2010 11:51
"Charlie" <Charlie(a)discussions.microsoft.com> wrote in message news:582DEE68-38EA-4AE5-88D2-8A9D3C71FB4C(a)microsoft.com... > Good explanation. It would be nice if the motor could send a signal > (close a > circuit, whatever) that would tell the program when the rotor had > completed > it's travel to the next quadrant, thereby allowing a "hand-shaking" method > of > synchronizing the device and software. I presume such motors exist. > > P.S. "To" is spelled with two o's when used in this context: "too long", > "too short", "too slow", etc. ;) P.P.S. "Its" is written without an apostrophe when used as the possessive form of "it." "It's" is ALWAYS the contraction for "it is." |