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

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Post 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.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

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

Post 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

palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Post by palanivel »

Hi QMESAR,
Thanks for your reply. Is there any other method to run two function simultaneously in flowcode?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

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

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

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

Post 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.

palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Post by palanivel »

Hi Benj,
Could you please share some Example program (pseudo parallel operation) for my understanding?

Thank you very much QMESAR.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

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

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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

palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Post 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.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

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

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

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

Post 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

Post Reply