Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Running two program at the sam time

Status
Not open for further replies.

AliRazoR

Advanced Member level 4
Joined
Oct 26, 2010
Messages
115
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Activity points
2,001
Hi.

I want to know, how i can run two program at the same time on PIC18F4550.
for example: first program is counting and second one is taking the data.

thanks in advance.
 

yes. various techniques
1. you could do processing the main program while the data acquisition is performed using interrupts, e.g. an ADC read very millisecond.
2. using a scheduler either
(a) priority based running the highest priority until it stops for IO, then the next, etc etc
(b) round robin - runs each program in turn for a time slot
 
Last edited:
You did not inform how data acquisition is performed.
Depending on if are obtained at different rates, you also have to work with queue management concept.

P.S.: Another approach could be a RTOS to that microcontroller.
However due to simplicity of the tasks mentioned above would not make sense.

+++
 
Re: Running two program at the same time

use state machines, one for each program. something like this....

Code:
void Program1()
{
	switch (Task1)
	{
		//change to this task to make program 1 idle
		case PROG1_IDLE:

		break;


		case PROG1_INIT:

		//do some initialisation for program 1
		Task1=PROG1_EXE;
		break;

		case PROG1_EXE:

		//do something here

		break;

		//other tasks can be added here
		case PROG1_OTHER_TASKS:

		break;
	}

}

void Program2()
{
	switch (Task2)
	{
		//change to this task to make program 2 idle
		case PROG2_IDLE:

		break;


		case PROG2_INIT:

		//do some initialisation for program 2
		Task2=PROG2_EXE;
		break;

		case PROG2_EXE:

		//do something here

		break;

		//other tasks can be added here
		case PROG2_OTHER_TASKS:

		break;
	}

}

void main()
{

	Task1=PROG1_INIT;
	Task2=PROG2_INIT;

	do
	{
		Program1();
		Program2();

	}while(TRUE);

}

The task states keep changing from one state to another depending on the various conditions as dictated by the programs.

There can be delay task for each program, where everytime an interrupt occurs a counter is added up, and when the required counts are reached the task state can be changed to another state.

Programs for various tasks like sending and receiving characters thru RS 232 can also be made in a similar fashion.

thanks
n
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top