Page 1 of 1

Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 9:06 am
by palanivel
Hello,
I'm new to Flowcode. Is it possible to run two or more loops (While loops) simultaneously? Ex: Flashing LED in PortA-1 and generate PWM in other port and Button's in other ports. While I access the buttons LED flashing and PWM signal should not affect. Link (Data sharing) between loop to loop is through Variables (Global variables). Can any one please help to provide the details and examples in Flowcode?

Palanivel,
India.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 9:17 am
by QMESAR
Hi.
Flowcode is a sequential Programming it does not contain a Real Time Operating System as any other Programming tools you need a tool that allows you to add a RTOS system too it

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 9:41 am
by palanivel
Hi QMESAR,
Thanks for your reply. Is there any other method to run two function simultaneously in flowcode?

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 9:56 am
by QMESAR
Hi
It is hard to say as I am not aware of what you need to do however your mcu should have multiple Interrupt sources and we use
the Interrupts to execute another set of code depending on the Interrupt source triggered .
This is the standard industry way of doing things as you would realize to run a a RTOS on a small 8 bit PIC or AVR makes not much sense
if you run a high performance MCU like a PIC32MZ or a ARM(STM32F4) then again an RTOS might make sense depending on the task to perform.

This is a general comment without knowing your application or need

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 10:50 am
by Benj
Hello,

The Raspberry Pi hardware can run multiple Flowcode programs simultaneously thanks to the underlying operating system and multi core CPU.

Otherwise you can use timers or other interrupts to allow you to perform pseudo parallel operation of your code.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 11:04 am
by LeighM
Another trick is to use a timer interrupt, or delay in a main loop, for your fastest operation.
Say you want to scan your keypad every 10mS, then have a 10mS timer or delay in the main loop, and check the keypad each time round the loop.
For the slower LED flash, say every second, then add a counter in the loop and when it gets to 100 then change the LED state and reset the counter.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 11:06 am
by palanivel
Hi Benj,
Could you please share some Example program (pseudo parallel operation) for my understanding?

Thank you very much QMESAR.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 11:42 am
by QMESAR
Benj wrote: The Raspberry Pi hardware can run multiple Flowcode programs simultaneously thanks to the underlying operating system and multi core CPU.
I still have to get use to that FC8 support RPI now and that runs an OS :D Yes so as Ben said the RPI you can use for Multitasking

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Thu Jun 14, 2018 1:21 pm
by Benj
Hello,
Could you please share some Example program (pseudo parallel operation) for my understanding?
Here is a very basic example of a stopwatch.

The main macro reads the switches to perform the start/stop/reset functionality.
Timer0 controls the TmrMultiplex macro that is responsible for multiplexing between 4 different 7-seg displays.
Timer2 controls the TmrCount macro that is responsible for measuring the passage of time.

https://www.matrixtsl.com/wiki/images/b ... Test3.fcfx

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Fri Jun 15, 2018 10:40 am
by palanivel
Hi Benj,
Thanks, I understand the Interrupt example. But my requirement is bit different.
Ex: I made a motor controller with LCD display. I want to make two operations,First one is motor controller which 2 PWM and speed sensors runs independently and other operation is LCD with Button control, LCD should Display the real time and user can control the Motor speed and sense the other sensors seperatly. While I modify the user data in LCD, the Motor and sensors works without any disturbance. If I use Interrupt i just can stop the Motor & Sensor function and switch to LCD functions. So it seems not good. I this case I need to use two MCU's once for motor control and another MCU is for LCD and RTC control and link two MCU's through I2C/SPI. Please guide me how to proceed my above plan in single MCU. Thanks.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Fri Jun 15, 2018 10:58 am
by kersing
Up until a few years ago when all controllers were single core all multi-threading was done by quickly switching between tasks. With multi core controllers (except the Raspberry Pi I don't think Flowcode supports any) two threads can run simultaneously.
To fake multiple threads running in parallel on a single core controller you usually use either cooperative multi threading (when a thread is finished it releases control of the CPU and another task can use it) or pre-emptive multi threading (an interrupt forces a thread switch). While you can implement both by hand most people will use some form of RTOS to implement this. At this time Flowcode does not support any RTOS (or OS except for the RPi)

In you case I would use interrupts for the speed sensors, PWM can be set and will run independently and use the main loop for LCD/Button control.

Re: Multi-threading (Parallel operation/Loops) is possible in Flowcode 8?

Posted: Fri Jun 15, 2018 11:06 am
by QMESAR
kersing wrote:Up until a few years ago when all controllers were single core all multi-threading was done by quickly switching between tasks. With multi core controllers (except the Raspberry Pi I don't think Flowcode supports any) two threads can run simultaneously.
To fake multiple threads running in parallel on a single core controller you usually use either cooperative multi threading (when a thread is finished it releases control of the CPU and another task can use it) or pre-emptive multi threading (an interrupt forces a thread switch). While you can implement both by hand most people will use some form of RTOS to implement this. At this time Flowcode does not support any RTOS (or OS except for the RPi)

In you case I would use interrupts for the speed sensors, PWM can be set and will run independently and use the main loop for LCD/Button control.
I can only agree with this :D