Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multitasking?

Status
Not open for further replies.
Hey there,

I know the concept and the theory about Interrupts, but putting it into practice... it looks quite difficult.

Let's say I have a microcontroller, which is playing music and flashing LED at the same time. I know the microcontroller have to flip back and forth between 2 routines almost simultaneously, but I seriously don't have the idea where can I start.

Anyone can give me clues or hints on where to start? Not the full answer, just something that can jump-start my understanding. :rolleyes:

oh btw I'm using ASM here. :)
 
Last edited:
To get a micro to play music and flash LEDs at the same time does not need multitasking. To play middle C you have to change a port pin 440 (*2) times per second. With a pic running at 4MHz (1uS per instruction) that is over 1000 instructions left over to light some LEDs between changing the port pin.

The simple way to accomplish what you are trying to achieve is to generate the notes on interrupt and flash the LEDs in the main code.

If you have a particular application in mind and have a go at writing the code, I'm sure lots of posters here will be willing to help get it working.

Actually, what I describe above is a form of multitasking but not what most people think of as multi tasking.

Mike.
 
To get a micro to play music and flash LEDs at the same time does not need multitasking. To play middle C you have to change a port pin 440 (*2) times per second. With a pic running at 4MHz (1uS per instruction) that is over 1000 instructions left over to light some LEDs between changing the port pin.

The simple way to accomplish what you are trying to achieve is to generate the notes on interrupt and flash the LEDs in the main code.

If you have a particular application in mind and have a go at writing the code, I'm sure lots of posters here will be willing to help get it working.

Actually, what I describe above is a form of multitasking but not what most people think of as multi tasking.

Mike.

Oh, I've already developed routines for the notes, and thus it could play music. Now the most challenging part is, making up the polyphonic music or make it to blare music with flashing LEDs or spin the motor. :)

If only flashing, it'll be ok. But if it's like another output with another music or a set of rotating LEDs and stuff like that... it'll be confusing. :confused:
 
I wrote a tutorial on the subject. It teaches the theory behind cooperative multitasking and how to implement it.

The tutorial is Cooperative Multitasking be sure to download the PDF and the zip which contains the MPLAB C18 project files. link

This tutorial explores cooperative multitasking with NAOS.
“Not An OS”. It requires no software other then your C
compiler. NAOS is a bare bones bag of techniques and code
snippets designed to illustrates Cooperative Multitasking
principals.

It is a draft so I would appreciate feedback.


Hey there,

I know the concept and the theory about Interrupts, but putting it into practice... it looks quite difficult.

Let's say I have a microcontroller, which is playing music and flashing LED at the same time. I know the microcontroller have to flip back and forth between 2 routines almost simultaneously, but I seriously don't have the idea where can I start.

Anyone can give me clues or hints on where to start? Not the full answer, just something that can jump-start my understanding. :rolleyes:
 
When you say you want to play polyphonic music, what exactly do you mean? Multiple square waves played simultaneously? Sine waves? Playing a wav file?

If you think you can use multitasking to play polyphonic music by having each task play a different note then you have overestimated the pics ability (assuming that is what you intend to use) - 16 bit Pics excepted.

As I said, explain what you want to achieve and see what people suggest.

Mike.
 
When you say you want to play polyphonic music, what exactly do you mean? Multiple square waves played simultaneously? Sine waves? Playing a wav file?

If you think you can use multitasking to play polyphonic music by having each task play a different note then you have overestimated the pics ability (assuming that is what you intend to use) - 16 bit Pics excepted.

As I said, explain what you want to achieve and see what people suggest.

Mike.

oh sorry for being inspecific. let me start a simple example: generating polyphonic music from a PIC µC. All square waves as I do not want to use a DSP or some encoder for WAV system.

I have done routines and all the functions for a monophonic music successfully. that's pretty straightforward. Yes - they are all simple square waves. But, 2 different square waves from 2 different outputs together to form a polyphonic music... can't think of how to do it.
 
If you read, understand, and follow the tutorial :) it will allow you to do this, just write the code in assembler instead of C. You will have to modify your existing code to yield execution instead of waiting as explained in the text.

The faster the uC more things you can multitask.
 
I have read 3v0's multitaksing tutorial and I must say it was a very good reading. I imported the methods used in this tutorial into my projects and have used this method (cooperative multitasking) in my major projects since. Despite that the code examples are in written in certain C language implemenations the principle can be implemented in any langue. In fact, it shows the genral idea how to implement multitasking. I recommend reading it to everyone strarting with multitasking. Appropriate place to say thanks again 3v0 for great tutorial.
 
Last edited:
how many channels on what micro? It is not possible to do polyphonic pin toggling on interrupts. At 14, 16, and 18KHz you would be getting 96,000 interrupts per second and need significantly better resolution than that to make it work right.

Of course if you are limiting your self to middle C or the octave above (I looked it up as being 262Hz), that would make it workable.

Dan
 
Status
Not open for further replies.

Latest threads

Back
Top