Multitasking job for PIC12F675

Status
Not open for further replies.

Thread Starter

Motanache

Joined Mar 2, 2015
540
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.
 

josip

Joined Mar 6, 2014
67
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.
 

atferrari

Joined Jan 6, 2004
4,771
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:

ErnieM

Joined Apr 24, 2011
8,377
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.
 

takao21203

Joined Apr 28, 2012
3,702
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.
 

Thread Starter

Motanache

Joined Mar 2, 2015
540
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:

nsaspook

Joined Aug 27, 2009
13,312
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.
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
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.
 
Status
Not open for further replies.
Top