Will the micontroller do two things

Discussion in 'Embedded Systems and Microcontrollers' started by raychar, Nov 11, 2011.

  1. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    Hello everybody,

    I am using PIC18 and wondering if it will do two things simultaneously..

    Originally, the circuit and IC was designed and programmed to detecting two events; the forward and backward steps of the motor, and then do the calculation and output the position that the moving head located. Events are input to controller as two external interrupts and default as high priority. They will not interrupt at the same time because forward and backward rotation of motor won't happen coinicidently.

    Now, I want to add duty cycle (PWM) to the circuit and use the timer interrupt in the same controller.

    What will happen at certain time that timer enable and make duty cycle on and off changes and at the same time that there is external interrupt occurs that mentioned in the first parallgraph, will it work?

    Thanks,
    Charles
     
  2. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hello.

    Yes, You can use the PWM module. That way the PWM is able to be used whilst the micro is doing something else. All you have to do is update the PWM module with the value, then jump back into your program.

    Daniel
     
  3. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    I don't think it does anything simultaneously.

    It takes 1 instruction cycle to do 1 task.
     
  4. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    Kinda. If your micro has autonomous modules -- which the PIC apparently does -- you can start the module running and basically forget about it. And, I have a Propeller from Parallax which effectively has 8 cores, or processing units, which run independently from each other. So in my project, one core (or hub as they call it) is doing PWM, while another is blinking LEDs in a pseudo-random fashion.

    --Rich
     
  5. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    I have heard propeller is pretty powerful. It has independent cores.
     
  6. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
    simultaneously = at the same time, to nearest pico second, nano second, milli second. The last is usually fairly easy. You need more definition to you requirement.
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You missed microsecond :)
    If an interrupt happens while another is being processed, the second interrupt will still happen, just after the first has been processed. Care needs to be taken to make sure code inside the interrupt routine takes a suitably short amount of time so that, for example, two of the second type of interrupt don't have time to happen while the first is being processed.
    Newer PICs have interrupt priority which lets you choose which type needs to be serviced the most quickly.
     
  8. raychar

    Thread Starter Member

    Nov 8, 2011
    82
    0
    I'll try to use the PWM module in the PIC18...Hoping that the duty cycle in the PWM cycle or etc. don't have any time lag during the servicing of the the external interupts.

    The stupid method is using an ordinary controller without the PWM module and writing it on my own. By choosing external interupt as high interrupt priorty, letting the duty-cycle subroutine in timer interrupt as lower. Are there any time lag for the jump of high interrupt to low interrupt? (i.e. the time at the moment when finishing first interrupt and starting next interrupt). If there is not, then my tolerate delay will be the instructions' cycle time in the first interrupt. Am I right?

    Thanks,
    Charles
     
Loading...