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

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

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

Postby palanivel » Thu Jun 14, 2018 9:06 am

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: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

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

Postby QMESAR » Thu Jun 14, 2018 9:17 am

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: 8
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Postby palanivel » Thu Jun 14, 2018 9:41 am

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: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

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

Postby QMESAR » Thu Jun 14, 2018 9:56 am

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: 13070
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3782 times
Been thanked: 3626 times
Contact:

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

Postby Benj » Thu Jun 14, 2018 10:50 am

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: 1453
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 373 times
Been thanked: 528 times
Contact:

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

Postby LeighM » Thu Jun 14, 2018 11:04 am

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: 8
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Postby palanivel » Thu Jun 14, 2018 11:06 am

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: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

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

Postby QMESAR » Thu Jun 14, 2018 11:42 am

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: 13070
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3782 times
Been thanked: 3626 times
Contact:

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

Postby Benj » Thu Jun 14, 2018 1:21 pm

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: 8
Joined: Thu Jun 14, 2018 8:54 am
Contact:

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

Postby palanivel » Fri Jun 15, 2018 10:40 am

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: 1799
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 477 times
Been thanked: 992 times
Contact:

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

Postby kersing » Fri Jun 15, 2018 10:58 am

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.
These users thanked the author kersing for the post (total 4):
QMESAR (Fri Jun 15, 2018 11:05 am) • Benj (Fri Jun 15, 2018 12:00 pm) • medelec35 (Fri Jun 22, 2018 6:15 pm) • EtsDriver (Sun Jul 01, 2018 10:36 am)
Rating: 23.53%
 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

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

Postby QMESAR » Fri Jun 15, 2018 11:06 am

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
These users thanked the author QMESAR for the post (total 2):
Benj (Fri Jun 15, 2018 12:00 pm) • kersing (Fri Jun 15, 2018 2:20 pm)
Rating: 11.76%