1

How to implement three functions, which can execute in the same time (function of input random variables)?

closed as too broad by Gerben, Majenko, jfpoilpret, Code Gorilla, Mikael Patel Mar 18 '17 at 16:47

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

4

No single processor can do more than one thing at a time. The best you can hope for is that each function runs for a short time only and gives the processor to the next one, giving the illusion that there is more than one thing happening at once. This is called multi-tasking or multi-threading.

There are some libraries that will do this for the Arduino (search "RTOS Arduino" or "Arduino multitasking"), or you can write each functions using the principles of Finite State Machine programming to achieve the same effect.

6

You can implement three functions but you can't able to execute them same time.

4

How to implement three functions, which can execute in the same time (function of input random variables)?

Micro-controllers such as the AVR used on Arduino boards have only one processing core but there are many hardware modules (ADC, UART, SPI, TWI, Timers, etc). Using these it is possible to achieve several "functions" at the same time, i.e. pure concurrency.

Some examples, while waiting for ...

  1. ADC (analogRead) there are over 100 cycles
  2. SPI (spi.transfer) there are 16 cycles
  3. UART (Serial) is actually already concurrent with buffering and ISR's.
  4. The same goes for I2C (twi).

These cycles can be used to interleave different functions or improve performance (e.g. pre-fetching, pipe-lining).

Another example; using direct port read it is possible to read the state of several pins at the same time.

With simple collaborative multi-tasking it is possible to context switch between several functions (tasks) on delay or yield. This can be done with a scheduler.

3

How to implement three functions, which can execute in the same time (function of input random variables)?

have three executors / arduinos, one for each function.

3

If the result of each function can be expressed as a single byte (i.e. an integer between 0 and 255) then you could:

  • Connect 3 shift registers (e.g. 74595 ic) to 3 pins on your Arduino
  • Assign one pin to each function
  • Use the shiftOut function to output the result of each function one bit at a time on its relevant pin
  • Use a 4th pin connected to all 3 shift registers as a common latch - when this pin is set HIGH the outputs from the 3 shift registers will all change at the same time.

Not the answer you're looking for? Browse other questions tagged or ask your own question.