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

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.

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 andmanage 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

Logged

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..

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.

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

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.

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.

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.

Logged

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

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.

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.

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.

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).

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).

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?

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.