A Bit About Multicore

In the last tutorial, a function you created only ran when it was called by the run function block.  There are, however, situations where you need a function to run continuously on its own in the background while the rest of the program keeps going, Such a background function might keep watch on a button press or a sensor reading. The Propeller chip on the Activity Board (original or WX version) can do more than one thing at a time easily, because it is a multicore microcontroller. You will try that in the next lesson. But first, let's visualize this multicore thing before we work with it directly.


First, a bit about microcontrollers and multicore

A microcontroller is an integrated circuit that includes a tiny processor "brain" to do the “thinking” and some memory for "taking notes" so it can keep track of what it is doing. Microcontrollers also have input/output pins, I/O pins for short, that can exchange electrical signals with other devices such as lights, switches, beepers, motors, and sensors.

A single-core microcontroller has just one processor inside. It is multitasking when it executes several tasks that must share its single processor. The processor must interrupt each task and switch briefly to another, to keep all of the processes going.

Imagine a chef in a kitchen alone, making bread, roast beef, and sauce. The chef must knead the bread dough for 15 minutes, interrupt that task every minute to stir the sauce, and remove the roast from the oven as soon as a thermometer reaches 120 °F. At any moment, the chef (processor) is executing only one task, while keeping all three processes (kneading, stirring, roasting) going at once.

Now imagine being that chef.  The more tasks you must do at once, the more difficult it gets to keep track of them all, and keeping the timing right becomes more of a challenge.

A multicore microcontroller has two or more processors inside. It is multiprocessing when it executes several tasks at once, with each task using its own processor. This is also referred to as true multitasking.

Imagine a chef in a kitchen with three assistants, making bread, roast beef, and sauce. The chef puts one assistant at the stove to stir the sauce every minute. Another assistant is sent to keep watch on the thermometer, and remove the roast when it reaches 120 °F. Now the chef is free to knead bread dough for 15 minutes. The three cooks (processors) are keeping all three processes (kneading, stirring, roasting) executing at the same time, without any task-switching interruptions, and without missing the moment when the thermometer reaches 120 °F. There is even an extra assistant ready to help if something more is needed.

Multiple cores makes it easier to do many tasks at once, especially if precise timing is needed.

The Propeller microcontroller has 8 cores (sometimes called cogs) and so can do multiprocessing, also called true multitasking. The cores are all the same. It has 32 I/O pins, which are also all the same. Each core can work with every I/O pin. This means that all of the Propeller cores and I/O pins are equally good at any tasks they must perform. Each core has a bit of its own memory. Each core also takes turn accessing its Hub, where a larger Main Memory (a big "notepad") allows them to share information.

Got it? Now, let's try using the new processor block to run a function in its own Propeller core.