go_away

Author Topic: Multi-tasking Microcontroller  (Read 6159 times)

0 Members and 1 Guest are viewing this topic.

Offline Builder1Topic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Multi-tasking Microcontroller
« on: July 11, 2008, 07:46:59 PM »
Hello Everyone,
Suppose I plan to use several motors to drive a robot and the motors need to communicate with one another. How can I multi-task a microcontroller or a group of microcontrollers so that several motors  can communicate with each other and do what they have to do? Is that possible ? I am a complete noob to building robots so the answers to my questions maybe real obvious to all you experts out there, so please excuse my inexperience. Please explain how what I have just described can be done if it is in fact possible. Thank you in advance for your help.
« Last Edit: July 12, 2008, 11:07:33 AM by Builder1 »

Offline TrickyNekro

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,207
  • Helpful? 15
  • 1.6L Peugeot 307 tuner
Re: Multi-tasking Microcontroller
« Reply #1 on: July 12, 2008, 02:36:27 AM »
From my experience you can not multitask a microcontroller... that's bad I know....
But that's for common micros... Parallax Propeller I heard that handles multitasking but never got the chance to work with it...
And the bad thing about propeller for me is that the 3v3 operating voltage is quite restrictive for new users....
Anyway...

I don't know which microcontrollers can be multitasked.... but 8 bit AVR and PIC won't multitask...

But if you are good in programming and the architecture of the machine you are using you can handle time properly and
manage to get some things done will others are in progress...


Better use a main microcontroller with other "support" and smaller ones...

That's from me...
Lefteris,
Greece
For whom the interrupts toll...


P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #2 on: July 12, 2008, 05:29:22 AM »
Ahem, hell knows what "motors need to communicate to one another" means.

Anyway, nothing can multitask unless it has 2+ cores. Not even your CPU. But it can be faked. Look into a RTOS (real time operating system) for your mcu.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Commanderbob

  • Robot Overlord
  • ****
  • Posts: 146
  • Helpful? 2
  • Embeddedmicro.com
Re: Multi-tasking Microcontroller
« Reply #3 on: July 12, 2008, 10:02:31 AM »
Like izua said you need two+ cores to truly multitask but I have faked multitasking by using the timers of a dsPIC to split up the processing time. I had it update a 3-D LED cube while it was also calculating the patterns. Using this style you have one main task (calculating the patterns) and a side task (updating the cube). I also added in another task, reading a microphone.

If you use more then one processor then you can multitask, one could be driving the motors while the other is watching out for obstacles. Once there is something in the way it could tell the micro controlling the motors to avoid it.

Justin

Offline Steve Joblin

  • Supreme Robot
  • *****
  • Posts: 405
  • Helpful? 2
Re: Multi-tasking Microcontroller
« Reply #4 on: July 12, 2008, 10:08:11 AM »
You can absolutely multi-task on a microcontroller... if the microcontroller is a muti-tasking microcontroller!  I only know of one true one... it is made by Parallax and called the Propeller... http://parallax.com/Default.aspx?tabid=407
« Last Edit: July 12, 2008, 10:08:52 AM by Steve Joblin »

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: Multi-tasking Microcontroller
« Reply #5 on: July 12, 2008, 11:00:23 PM »
No need to flame the new guys izua.

But it is indeed as izua says. If you truly need to do multiple things on a microprocessor, you need to look into an RTOS, or cook up your own timer based solution. I'd go with an RTOS because if you don't have your full requirements (what hobby robot builder ever does?) it will easier to add to an RTOS solution than it will be to add to a custom solution. The best place to start into acessable quality hobby RTOS is the FreeRTOS project. I've been using it for almost 2 years now and am completely happy with it on my ATmega, even more so than the RTOS we use at my work place.

The better question here, that izua alluded to, is what do you mean when you say you need the motors to talk to each other? What functional end requirement do you need? Give us a high level overview of what you want this robot to do and we will be able to help you more.

Offline Steve Joblin

  • Supreme Robot
  • *****
  • Posts: 405
  • Helpful? 2
Re: Multi-tasking Microcontroller
« Reply #6 on: July 13, 2008, 07:20:53 AM »
Sorry Jesse, but I do beg to differ with you... please see my post above... the Propeller by Parallax is a true multi-processor microcontroller.

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: Multi-tasking Microcontroller
« Reply #7 on: July 13, 2008, 10:41:58 AM »
Indeed it you are correct. But for me personally there are a couple of things that I don't like about it.
The propeller takes an 160mhz processor and essentially turns it into eight 20mhz processors by clever hardware.
It has lower pin count, and less support hardware than the standard ATmega 128(where is SPI?)
At this moment it can't be programed in C.

I'm not saying it's not a good processor, I'm just saying that I can do better for my money with other processors at this junction.

If you like it, use it. However for my projects and their budgets, it is a poor fit when compared to an ATmega and FreeRTOS. YMMV.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Multi-tasking Microcontroller
« Reply #8 on: July 13, 2008, 08:43:22 PM »
Hi,

Suppose I plan to use several motors to drive a robot and the motors need to communicate with one another.
I guess you mean something like you want a "brain" to keep track of what your motors do, since the motors in themselves have no reason (or means) to "chitchat"?

How can I multi-task a microcontroller or a group of microcontrollers so that several motors  can communicate with each other and do what they have to do?
For controlling a bunch of motors, you don't need multitasking. In the time it takes you to move a vehicle 1 mm, your average microcontroller can do lots of instructions.

Please explain how what I have just described can be done if it is in fact possible.
If you needed serious speed, true real time multitasking would be better done by parallel processing or processor clustering, but take a deep breath and make a realistic estimate of your needs (speed-wise) and compare that to what you can get out of even a slow µ-controller - I think you will find a good overhead :)

Should you need more apparent speed than what linear programming will let you get, read up on state machines, where the routine in most need of control gets it first, then give control to the next most needy, so to speak.
The same approach can be used to (apparently) speed up response time in time slice multiplex, which is one of the early (and still very useable) forms or multitasking.


Whether you use a single processor with say 4 cores or 4 independent processors for doing 4 tasks gives almost the same yield if you really need true multitasking, but very few apps need that kind of speed and controlling motors is about as far as you get from needing multitasking.

If you need more speed for an app. first optimize your code. If that's not enough, choose a faster processor/controller. Only when these options are not enough, bring in more cores/processors.

But first... Sit down and calculate what speed you need - 1 second will easily give you millions of instructions and you have to be a quite sloppy programmer to waste enough of them to not be able to handle a handfull of motors.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline AndrewM

  • Robot Overlord
  • ****
  • Posts: 255
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #9 on: July 14, 2008, 08:40:47 AM »
It has lower pin count, and less support hardware than the standard ATmega 128(where is SPI?)
At this moment it can't be programed in C.

The only thing I don't like about the propeller is having to use SPIN or assembly, I prefer C myself.  The good thing about the propeller is that while it doesn't have a very high pin count, just about every IO pin can be used for anytype of IO action.  ADC, SPI, I2C, etc.  There is no one pin is just for this function.  People have created 10 pin parallel busses between devices using the propellers, which to me is a very nice feature.

As to answer the original question, multiple controllers is probably going to be your best bet.  I would imagine that each motor controller would need a huge amount of processing power, so you can go with lite weight atmels, and use something beefier for the main controller.  Connect them all up using SPI or I2C and each motor controller can send and receive info from the main controller.  But before embarking on that route, take Soeren's advice and assess what you actually need to accomplish and whether a single controller could handle it all.
blog: www.iamwhen.com
Saving the world from humanity one robot at a time.

Offline TrickyNekro

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,207
  • Helpful? 15
  • 1.6L Peugeot 307 tuner
Re: Multi-tasking Microcontroller
« Reply #10 on: July 14, 2008, 12:22:05 PM »
Also, I don't mean to flame you but the only processors you can multitask for real is
FPGA style processors but.... don't even think about it....  :P
For whom the interrupts toll...


P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #11 on: July 14, 2008, 01:08:09 PM »
Now, I don't mean to add to the flame, but a FPGA is not a processor ;D
*cartman voice: flame wars!*
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline brijesh

  • Full Member
  • ***
  • Posts: 55
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #12 on: July 15, 2008, 11:21:27 AM »
From wikipedia

Multitasking:
In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for that task.


Multiprocessing:
Multiprocessing is the use of two or more central processing units (CPUs) within a single computer system. The term also refers to the ability of a system to support more than one processor and/or the ability to allocate tasks between them.

Based on above definition, Atmel AVR chips can do both Multitasking and Multiprocessing. The Parallax Propeller chip is a Multi-core chip.

Multi-Core:
A multi-core CPU (or chip-level multiprocessor, CMP) combines two or more independent cores into a single package composed of a single integrated circuit (IC), called a die, or more dies packaged together. A dual-core processor contains two cores, and a quad-core processor contains four cores. A multi-core microprocessor implements multiprocessing in a single physical package.




Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: Multi-tasking Microcontroller
« Reply #13 on: July 15, 2008, 11:39:50 AM »
Now, I don't mean to add to the flame, but a FPGA is not a processor ;D
*cartman voice: flame wars!*

lmao , find a video of him saying that , that would make my day
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #14 on: July 15, 2008, 12:19:23 PM »
"With Apologies to Jesse Jackson". When cartman fights the midget. Episode 1154, or s11e01.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 331
  • Helpful? 3
Re: Multi-tasking Microcontroller
« Reply #15 on: July 15, 2008, 12:55:19 PM »
Now, I don't mean to add to the flame, but a FPGA is not a processor ;D
*cartman voice: flame wars!*

It can be.  Many microcontroller architectures can be implemented on FPGAs.

- Ben

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #16 on: July 15, 2008, 12:59:26 PM »
Yes, but its usually slower than the discrete thing.
A virtual machine can implement any CPU architecture too, but that doesn't make the piece of software a real machine.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 331
  • Helpful? 3
Re: Multi-tasking Microcontroller
« Reply #17 on: July 15, 2008, 02:50:36 PM »
But the point is that it isn't virtual.  It's an actual hardware microcontroller implemented out of the gates on the FPGA.  Its potentially being slower than a version built directly out of silicon doesn't negate the fact that it's functioning as a true processor.  You could make something far more powerful than an 8-bit AVR with an FPGA, and you have the flexibilty to make FPGA processors that are much faster at uncommon applications than standard microcontrollers (e.g. 35-bit multiplication).

An FPGA configured with a microcontroller architecture is kind of like a motor driver H-bridge built with discrete MOSFETs while a permanently etched silicon microcontroller is like the motor driver H-bridge built directly into an IC.  You can't really argue that the discrete MOSFET version isn't a legitimate motor driver; all you can argue is that the IC version is more efficient/has higher performance.

- Ben

Offline ahab

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #18 on: July 15, 2008, 05:39:27 PM »
I'm just going to suggest that some of you read this:

http://www.embedded.com/columns/technicalinsights/192503587?_requestid=424085

Last semester I ran a model train layout with 50+ threads on one 586.

I won't consider doing a real time system with fewer than 5 threads. I don't care how many processors it has.

But there aren't any free Ada compilers for common microcontrollers.

Offline bulkhead

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #19 on: July 16, 2008, 12:38:09 AM »
Propeller C compiler $99 http://parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/imagecraft/List/1/ProductID/510/Default.aspx?SortField=ProductName%2cProductName

There's a free 45 day trial.  The compiler is more geared towards making C-trained engineers' transition to the Propeller easier.  For the hobbyist, learning SPIN isn't that big of a deal.  If you didn't already know C, SPIN's syntax is arguably easier to learn.  The complete protoboards start at $20, but require a $30 programmer.  There's also the $45 PRC (http://wulfden.org/PRC/index.shtml) especially geared towards robotics, with jumper configurable ports for up to ~28 servos/peripherals, breadboarding space, and serial port programmer.

Multitasking is as simple as launching a function call into another of the Propeller's 8 cogs (processors).

Offline AndrewM

  • Robot Overlord
  • ****
  • Posts: 255
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #20 on: July 16, 2008, 09:18:22 AM »
Propeller C compiler $99 http://parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/imagecraft/List/1/ProductID/510/Default.aspx?SortField=ProductName%2cProductName

There's a free 45 day trial.  The compiler is more geared towards making C-trained engineers' transition to the Propeller easier.  For the hobbyist, learning SPIN isn't that big of a deal.  If you didn't already know C, SPIN's syntax is arguably easier to learn.  The complete protoboards start at $20, but require a $30 programmer.  There's also the $45 PRC (http://wulfden.org/PRC/index.shtml) especially geared towards robotics, with jumper configurable ports for up to ~28 servos/peripherals, breadboarding space, and serial port programmer.

Multitasking is as simple as launching a function call into another of the Propeller's 8 cogs (processors).


I think $99 is well worth not having to learn a new language.  As it is I have to stop myself when doing any coding to make sure I am using the correct syntax for a given language and not trying to do something the language forbids (ie java).
blog: www.iamwhen.com
Saving the world from humanity one robot at a time.

Offline Builder1Topic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Re: Multi-tasking Microcontroller
« Reply #21 on: July 16, 2008, 02:55:28 PM »
Hi guys,
Are you guys saying that if I decide to go with regular, nonmulti-tasking microcontrollers, I would need as many microcontrollers as there are sensors and motors? If that is so then how do I supply them all with power from the same power source? I don't want to give each device its own power source 'cause I'd like to cut down on weight and cost. Would powering the different devices and microcontroller with the same power source be a problem?
« Last Edit: July 16, 2008, 05:06:18 PM by Builder1 »

Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 331
  • Helpful? 3
Re: Multi-tasking Microcontroller
« Reply #22 on: July 16, 2008, 03:08:08 PM »
You just need one microcontroller.

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Multi-tasking Microcontroller
« Reply #23 on: July 16, 2008, 05:15:52 PM »
Back to the original question....

 As Bens said above, you just need 1 microcontroller and dont really have to multitask either, just running the commands liearly would work well enough. (most people who use motors use at least 2 so its not a assive problem)

 When you say communicate with each other I think that you need to know better how to implement the software, the reason being that the software on the microcontrollers represent what the hardware is doing (as in the software tells the hardware what to do). So in effect you just need the software building in such a way that the different parts of the software can communicate effectively with each other.

e.g. in software you tell the left motor to go forwards so a variable is set in software, if the right motor needs to know what the left motor is doing then the part of the software that controls the right motor can just look at the variable set by the left motor.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: Multi-tasking Microcontroller
« Reply #24 on: July 20, 2008, 05:40:37 PM »
lol this thread got waaaay off topic (but it was still an interesting read)

Hey Builder1, just check this out:
http://www.societyofrobots.com/step_by_step_robot.shtml
It'll give you a good idea how one microcontroller can control many different things.

 


Get Your Ad Here

data_list