Multitasking job for PIC12F675

Discussion in 'Embedded Systems and Microcontrollers' started by Motanache, Mar 7, 2015.

Thread Status:
Not open for further replies.
  1. Motanache

    Thread Starter Member

    Mar 2, 2015
    70
    4
    I have two loops rather complicated which I would like to run in parallel.

    Both loops continuously working:

    I tried to write a loop inside another, but I almost impossible.
    That's because the main loop expect some changes of external pins.


    I will try with interruption at a predetermined time.

    I would have liked the controller to execute instructions in parallel in both cycles.

    There is RTOS. I have not used. I do not know how it works.
    I do not know if there is for that simple controller.
     
  2. josip

    Member

    Mar 6, 2014
    63
    12
    You must mix different function to execute together as one, without interrupts. For example, my flasher execute (at least) 3 action in parallel, receiving data form PC over USB and sending them to target device(s) by 1-wire interface, and flashing on target device.
     
  3. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    Is it any flow diagram you could show or a clear explanation of what each task has to achieve?

    Do they have a fixed time-wise relationship (maybe the most relevant detail IMO).

    Is one of them requiring precise timing (whatever that could mean)?

    Is any, or both, expecting / giving info to the other or they contribute independently to something else? Think of this: could they be run by independent micros? (This is NOT the idea but a way to see how they do relate).

    Nothing better than asking questions to look smart. :p :)
     
    Last edited: Mar 7, 2015
    ErnieM likes this.
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    You're not going to fit any OS in that tiny device. Besides, the code will run slower with a RTOS than without one.

    For the moment forget about HOW you think this should be done and just answer this:

    WHAT do you want to be done?

    Make the requirement first, then write the code.
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    write your code then we try to work on it
     
  6. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    I usually put all my effort in a flow diagram and from there I start to work out how each task works vis-a-vis the others (if any).
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You can do multitasking on all PICs.

    You need a granularity, how long do you allow a task to run.
    To make it simple, its prorammed in a way it exits on its own for instance after 200 microseconds.

    Your schedule could be 10 milliseconds.

    Each time the "task" checks if it has more slices to process, or has nothing to do.

    The way of thinking comes from C++ but you are free not to implement unneeded elements, in fact, most arent needed.

    Switching by force is another thing, you can also do that just to run one or two task which need to run, for a short time.

    For a large application you need OS but not for simple multitasking.
     
  8. Motanache

    Thread Starter Member

    Mar 2, 2015
    70
    4
    Well, I tell you one of the device that I want to make:

    Whistle light switch:
    http://www.electroschematics.com/wp-content/uploads/2013/01/whistle-light-switch.jpg

    But how I do not find that IC, I want to replace it with PIC12F675.

    The entire program is written in ASM, but I have to write sometimes in the form of lines in C to be simpler

    Light dimmer:
    http://ww1.microchip.com/downloads/en/appnotes/40171a.pdf
    At the end of pdf the program is given both in C and ASM(.LST)

    This dimmer uses a push-button.

    In place of this push will be driven by whistle:
    http://www.talkingelectronics.com/projects/Elektor/Whistle/Whistle-1.html


    So,
    check whistle:

    aa call _25uS
    btfss GPIO,2 ;Is input HIGH? Start with a HIGH
    goto aa
    bb call _250uS
    btfss GPIO,2 ;Is input LOW?
    goto cc
    goto aa ;freq too low

    cc call _250uS
    btfsc GPIO,2 ;Is input LOW?
    goto dd
    goto aa ;freq too low

    dd incf count,1
    goto bb


    It must run in parallel with the algorithm:
    - Checking line 'passing' through 0V at 50-60Hz
    - triac delay off
    -........
    In this delay microcontroller do other things.

    It have also implemented an IR remote control.
     
    Last edited: Mar 7, 2015
  9. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,910
    2,173
    Going along with everyone else you first need to state the problem in a way that's easy to implement with a controller in a sequential way without 'goto' if possible. A FSM or Finite State Machine is what's typically used. Instead of branching execution on a input, a flag is set with the input state that can be used later.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    What you are proposing is very dangerous and a violation of the terms of service (TOS) here for good reason:

    you can kill yourself doing this.
     
  11. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    The contents is a violation of the terms of service (TOS), so it should be closed.
     
Loading...
Thread Status:
Not open for further replies.