Multitasking on PIC microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by cpleng7, Dec 4, 2010.

  1. cpleng7

    Thread Starter Active Member

    Dec 18, 2008
    Is that possible for a PIC microcontroller work in multitasking?
    Which mean that do 2 job in the same time?
  2. Papabravo


    Feb 24, 2006
    Certainly it is possible.
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    PICs can do a form of co-operative multitasking using either a library or a programmer's clever use of interrupts and code.

    I suggest Boost C w/Novo RTOS Real Time Operating System. The compiler is free to cheap depending on the version, and all but the free version comes with NovoRTOS for 3 tasks simultaneously. It is "coding time decision" multitasking, where the priority and order are set when the program is written.

    I've used it a good deal and have had great results with it. Using interrupts gets you far as well. The more one can stay away from using a delay() function, the more "real time" any program will "feel" to a user. Novo RTOS does that easily without the user having to come up with the interrupt scheme and priorities in the interrupts. The code only needs to specify what needs to be done and return control to the RTOS until something else needs to be done. It IS a bit to learn, but worth it.

    What sort of multitasking were you looking at doing? I've ran programs on PICs that were rather intensive at first glance to the point I thought of running more than one uC, but didn't need to. Example was a line following and obstacle avoiding robot my kid made that needed to run 2 RC servos, 2 full H-Bridge drivers, and a few IR detectors. Ran without lagging/glitching on the servos or the ranging. If a 14 yr old can learn it, most everybody can.
  4. cpleng7

    Thread Starter Active Member

    Dec 18, 2008
    actually I am trying to step down the voltage from the three phase system and feed into the microcontroller. since the three phase system is working so fast as my country is 50Hz voltage, so every cycle is 0.02s. I am using microcontroller act as a zero crossing detector.

    so in this case, i have to multitasking to detect the three line.

    is that suitable, if i using this.
  5. Markd77

    Senior Member

    Sep 7, 2009
    That's loads of time, with a slow micro you get nearly 20000 (assembler) instructions in 0.02 seconds.
    The ADCs on a lot of micros are quite slow so you might have difficulty reading 3 analog voltages fast enough, but a few external components should be enough to find the zero crossing points.
    Presumably you will be using transformers to step down the voltage.
    Maybe a few more details of what this is for would help us understand better.
  6. maxpower097

    Well-Known Member

    Feb 20, 2009
    I think like the iphone, you can simulate multitasking, but since it really only has one core it really can't.
  7. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    Zero Crossing Detection Circuits at

    There are ICs for this as well, but I can't recall any off hand that would be useful for 3 phase, you could use 3 single phase though.

    A PIC will have plenty of time to act between phases for minor output and processing, they typically run at 4 MIPS (Million Instructions Per Second) when clocked at 20Mhz.
  8. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    If you are using a micro you could almost just aim for syncing to the line frequency unless you have highly reactive circuits that bounce around with lead and lag.