Welcome, Guest
Username: Password: Secret Key Remember me
  • Page:
  • 1
  • 2

TOPIC: Picaxe can do psudo multitasking...

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #15859

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Anyone familiar with some of the newer X2 chips (I was working with them just before I abandoned the Picaxe family) knows that they can do "psudo" multitasking.

Each "thread" (1 to 4 max) shares slices of the ticker. Such as, with a clock running at 20 mhz running 2 threads, each will be issued 10 mhz of clock speed, which is necessary to know for timing issues. At 20 mhz and say 4 threads, each thread gets a 5 mhz slice of CPU speed.

I am wondering how they did this? I suspect it has to do with the manipulation of timers and interrupts.

Id love it if Proton/SF were to offer such a "feature", would be nifty to have "4 chips in one".

I was just curious....
Andrew

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #8737

You *can* multitask, although I believe it's a bit different to what you’re thinking.

There are a couple of factors to consider. How often does each task take to complete, and how often must the task be performed.

Say you have 4 tasks. Each task takes a maximum of 200mS to complete. Each task only needs to be serviced once every second. That means that a total of 800mS out of every second can be "spent" servicing the tasks. Everything is achievable, and you could "multitask" in this case.

Say you ran the math wrong, and task one could take upwards of 500mS to complete. Now you can't ensure there is enough time for each task to complete as there are 1.1 seconds of tasks for every 1 second that passes (there are a number of ways to workaround this scenario, it’s just an example).

Long story short, besides a fancy interrupt method the only way to "multitask" is to ensure there is enough time for each task to complete. Also known as "time splicing" or "time sharing" amongst other terms. There are some very neat multitasking approaches out there, although at the end of the day a PIC can only process one command at a time (excluding onboard peripherals humming away).

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #8746

  • bitfogav
  • bitfogav's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Thanks received: 53
Graham didnt you do a Code Example on multitasking!?

http://digital-diy.com/Swordfish-Compiler-Code-Examples/swordfish-code-snippet-multi-tasking.html

I know its not Proton basic?.

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #8749

  • jmessina
  • jmessina's Avatar
  • Offline
  • Senior Boarder
  • Posts: 44
  • Thanks received: 189
It's my understanding that the picaxe would work a little differently.

It uses an interpreted/tokenized form of basic, so in between each of your statements control returns to the basic interpreter code which controls execution. In your program, you can set up to four different sections for parallel tasking, and the interpreter executes one statement from each of those sections in a round-robin fashion. Since it works at the basic statement level, the amount of time spent in each section will/can vary.

Pretty slick really. It would be hard to replicate that sort of functionality with a compiled system running on a pic. You'd need some sort of RTOS-type executive running in the background to do time-slicing for you, but then that opens up all sorts of other issues.
The following user(s) said Thank You: Graham Mitchell

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #8751

I was just having a read on the approach, very impressive! For some reason I don't completely trust it..

Thanks Gav for posting the link. The examples are in Swordfish although the method is pretty straight forward.

Re: Picaxe can do psudo multitasking... 8 years 1 month ago #8752

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Id rather have a dedicated PIC for each special task myself, however I was pretty curious how they could do such a thing.
  • Page:
  • 1
  • 2
Time to create page: 0.238 seconds