Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 25, 2024, 11:14:46 11:14


Login with username, password and session length


Pages: [1]
Print
Author Topic: Is it Possible? Execute Concurrent Functions in C.  (Read 4103 times)
0 Members and 1 Guest are viewing this topic.
adrian
Newbie
*
Offline Offline

Posts: 30

Thank You
-Given: 27
-Receive: 14


« on: January 03, 2008, 07:39:48 19:39 »

Hi everyone,
I'm wondering whether C program can execute multiple functions concurrently?
For Example, running count down timer while transmitting data over RS232.
I may need to implement it using CCS PIC C. I had done it with verilog.
But can it be done with C? Is it possible? If Yes, How? Are they the same as using #include function?
Looking forward to hear from you all C experts. Good Day. Thanks in advance.
Logged
future
Newbie
*
Offline Offline

Posts: 16

Thank You
-Given: 10
-Receive: 7


« Reply #1 on: January 03, 2008, 09:20:25 21:20 »

You can not.
What you can do is to write a pseudo multitasking program that does one task at a time.

while(1) {
   CountDown();
   PutChar('a');
}

Also, see http://en.wikipedia.org/wiki/Round-robin_scheduling
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 84


« Reply #2 on: January 03, 2008, 09:40:17 21:40 »

I agree with future , you can not.
But that is not a weakness of C. In my opinion it is imposible to do.

Not even the human brain can do " concurrent " tasks.

Activate the TaskManager if you are running windows and have a look how Bil does the trick. i.e. Time Slices.

If you are programming a PIC , you can let one hardware Timer do the countdown for you and interrupt your RS232 task when it is done. Although I am not shure if this could be named Concurrent Tasks either.

Interesting dilema to do some brainstorming , any more opinions out there ?

Have a look here , started new topic http://www.sonsivri.com/forum/index.php?topic=9231.msg39948#msg39948

Greetings.
« Last Edit: January 04, 2008, 03:10:42 15:10 by frasenci » Logged
omni
Active Member
***
Offline Offline

Posts: 139

Thank You
-Given: 169
-Receive: 176


« Reply #3 on: January 04, 2008, 12:08:11 00:08 »

Sorry to be off topic, but human brain does many concurrent tasks, just because you are not aware of them does not mean they are not there. Take all the autonomous functions for instance, they happen at the same time while you are doing higher functions, etc. Smiley

As to the concurrent execution in PIC, an idea would be to use interrupts and execute bits and pieces at certain times...
Logged
Memoly
Junior Member
**
Offline Offline

Posts: 49

Thank You
-Given: 44
-Receive: 39


« Reply #4 on: January 04, 2008, 10:53:05 10:53 »

Hi,

Of course you can do this, but it is not related with C, it depends on internal PIC structure.
Most PIC series has internal UART, so you can send or receive data without any MCU overhead by using interrupts easily. While data sending over TX with its hardware, the MCU will be working on your main routine.

void main()
{
  while(1)
  {
     --a;
  }
}

void interrupt ISR(void)
{
   if(TXIF && TXIE)
   {
   ...
   Place data to internal PIC's fifo to send over TX
   ...
   }

   if(RCIF && RCIE)
  {
    ...
    read incoming data from fifo over RX
    ....
  }
}
Logged
8K51
Junior Member
**
Offline Offline

Posts: 80

Thank You
-Given: 86
-Receive: 40


« Reply #5 on: January 04, 2008, 11:13:52 11:13 »

HI
'Concurrent' is more a FPGA synthesis notion (VHDL...) where you describe future hardware.
With a microcontroller hardware is done !!!
You can still do :

-hardware 'concurrent' tasks with available hardware modules (timer/counters, Uarts....)
 (So with your examples the answer is yes.)
 Your software has to configure and launch peripheral modules.
 Your running modules lets you know whats happens with flags (frequently used with interruptions).
 Each running peripheral module is 'concurrent'

-sofware 'concurrent' tasks if you use a RTOS.
 Tasks here are pseudo 'concurrent'

Regards
« Last Edit: January 04, 2008, 11:21:34 11:21 by 8K51 » Logged
adrian
Newbie
*
Offline Offline

Posts: 30

Thank You
-Given: 27
-Receive: 14


« Reply #6 on: January 04, 2008, 12:57:21 12:57 »

Thanks ya all for the answer. I agree with 8k51 regarding to the future and done hardware terms. U can only run concurrent task for the built features. But not for pseudo wise. Thanks future for the method but that is the one currently used. Actually i need it for some other application. Real time displaying muxed data while monitoring and processing data from a communication line. Apart from that, there are plenty of countdown timer for the circuit as well. Thanks for clearing off my doubts.

Off topic, Thanks Omni regarding to frasenci's comment. Yes, Human brain can run concurrent functions. eg. breathing, seeing, writting and hearing at the same time. Try typing what u think without looking at the keyboard. Walla!!!
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC