Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Performance with multi-tasking?

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
Chris D



Joined: 28 Dec 2005
Posts: 3

Posted: 28 December 2005, 15:47 PM    Post subject: Performance with multi-tasking? Reply with quote

Hello,

I am working on a project (please keep in mind I am a beginner with electronics) that needs to control 4, possibly 5 stepper motors (via drivers). These drivers take Step and Direction signals.

The controlling component is Windows Software. As I am writing the Windows software, I can pre-process the motion commands pretty good.

However, the problem I am trying to work with using the ZBasic chip is this...

I want to control the 4 or 5 steppers at a pretty high rate of speed. Each stepper will be running a different speeds (or some might not run at all). I suspect that using the multi-tasking feature is required for this and am wondering what sort of step rates I can achieve accross the 4 steppers? In other words, what would be the maximum step rate I could achieve?

If you have suggestions for an alternative method, I am all ears Smile

Also, I have not purchased a Zbasic product yet. I have been tinkering with some PICs programmed in basic and quickly hit the speed limits there. So, I am familiar with PICs and VB programming, and it looks like the ZBasic chips are what I am looking for.

Thanks!
Chris
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 28 December 2005, 19:06 PM    Post subject: Reply with quote

The example code below illustrates a framework to measure the minimum task cycle time. There are four tasks, each of which simply changes the state of an output pin and then relinquishes the remainder of its time slot to the next ready-to-run task.

A logic analyzer was used to measure the period of the resulting waveform on the pins; half of which is the cycle time plus the overhead of the code in each task loop. The resulting half-period time was 226uS.

A task timeslot is approximately 1.95mS. At the end of each timeslot, if the current task is not locked, it will be suspended and the next ready-to-run task will be resumed. You may want to download the ZBasic Language Reference Manual or view it on line. Multi-tasking is described in the Advanced Topics chapter.

Code:

Const stkSize as Integer = 25
Dim ts1(1 to stkSize) As Byte
Dim ts2(1 to stkSize) As Byte
Dim ts3(1 to stkSize) As Byte

Sub Main()
   Register.DDRC = &H0f
   CallTask "task1", ts1
   CallTask "task2", ts2
   CallTask "task3", ts3
   Do
      Call ToggleBits(Register.PortC, &H01)
      Call Sleep(0)
   Loop
End Sub

Sub task1()
   Do
      Call ToggleBits(Register.PortC, &H02)
      Call Sleep(0)
   Loop
End Sub

Sub task2()
   Do
      Call ToggleBits(Register.PortC, &H04)
      Call Sleep(0)
   Loop
End Sub

Sub task3()
   Do
      Call ToggleBits(Register.PortC, &H08)
      Call Sleep(0)
   Loop
End Sub
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 28 December 2005, 20:19 PM    Post subject: Reply with quote

Although I'm a big fan of multi-tasking, I do not think a separate task per stepper motor is the right way to go. I believe you could control all 4 (or 5) steppers in one task and simply flip output bits at the appropriate time i.e. motors travelling at a slower speed get their bits flipped less often. This technique may limit the number of different speeds you can have but probably matches your Visual Basic implementation.

There wasn't a lot of information in your initial question but from what I understand ZBasic will be more than adequate for your needs. Are you using some type of controller circuitry that reduces the interface to step and direction inputs or are you using 4 or 6 inputs directly to the stepper motor?

If you are looking for a great deal of sophistication and the ability to manipulate many other devices at the same time then you may need a dedicated controller for just the stepper motors. This could be a custom stepper motor controller or simply another ZBasic chip.
Back to top
Chris D



Joined: 28 Dec 2005
Posts: 3

Posted: 29 December 2005, 12:30 PM    Post subject: Reply with quote

Hi MIke,

The steppers (or servos) I will be driving take Step & Direction inputs so that makes things a bit cleaner.

As with all stepper and servo applications I have to be very mindful of the accell and decell rates for the motors. This is further complicated if you want smooth continuos motion from one "command" to the next.

I will also need to be able to start and stop the motion at anytime and keep track of the steps processed and report back to the mail application the difference so it can keep track of positions etc.

I could use multiple processors and share the load, but I don't think there is an existing custom "Step dir" controller out there that will do what I need. If you have some suggestions for custom controllers, I am open to anything at this point, this is all in the planning stages.

Chris










mikep wrote:
Although I'm a big fan of multi-tasking, I do not think a separate task per stepper motor is the right way to go. I believe you could control all 4 (or 5) steppers in one task and simply flip output bits at the appropriate time i.e. motors travelling at a slower speed get their bits flipped less often. This technique may limit the number of different speeds you can have but probably matches your Visual Basic implementation.

There wasn't a lot of information in your initial question but from what I understand ZBasic will be more than adequate for your needs. Are you using some type of controller circuitry that reduces the interface to step and direction inputs or are you using 4 or 6 inputs directly to the stepper motor?

If you are looking for a great deal of sophistication and the ability to manipulate many other devices at the same time then you may need a dedicated controller for just the stepper motors. This could be a custom stepper motor controller or simply another ZBasic chip.
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 29 December 2005, 18:15 PM    Post subject: Reply with quote

Chris D wrote:
The steppers (or servos) I will be driving take Step & Direction inputs so that makes things a bit cleaner.

As with all stepper and servo applications I have to be very mindful of the accell and decell rates for the motors. This is further complicated if you want smooth continuos motion from one "command" to the next.

I will also need to be able to start and stop the motion at anytime and keep track of the steps processed and report back to the mail application the difference so it can keep track of positions etc.

Step and direction help a lot because you only need to really worry about the step output for each motor as direction doesn't change that often. However I'm not sure what you mean about stopping and starting the motion at anytime because as you say you need to be mindful of deceleration.

What I meant for example is a controller that generates all of the steps for you rather than have ZBasic do it which is wasteful of resource. For example here is a simple speed controller using a programmable timer chip: http://www.elecdesign.com/Articles/Index.cfm?AD=1&ArticleID=6306.

Alternatively here is a stepper motor controller with a little more sophisication: http://www.active-robots.com/products/motorcon/stepper.shtml

Remember Google is your friend.


Last edited by mikep on 29 December 2005, 18:51 PM; edited 2 times in total
Back to top
Chris D



Joined: 28 Dec 2005
Posts: 3

Posted: 29 December 2005, 18:50 PM    Post subject: Reply with quote

Thanks,

That gives me more to work with. There is a lot to stepper motor control and getting them to work good. Those links will help me a bit more to understand what I need to do. I did find something else too that I am checking into and it appears to be able to handle the speeds I want to achieve.

Chris
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group