Multitask LEDs?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times

Multitask LEDs?

Post by rocket200 »

Is it possible to multitask LEDs with Flowcode? I would like to have two LEDs flashing, one flashing at 1Hz and the other at 5Hz. Would it be done with interrupts?

Thank You!

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Multitask LEDs?

Post by medelec35 »

Hi rocket200,
Yes I would personally use an interrupt. I have used timer0 since all timers only simulate with Flowcode V5.

I have attached a flowchart I believe is the simplest way to flash two LED's at two different rates.

If you want to experiment you could try just using 1 variable and toggle two bits!

Notes about the flowchart. LED1 = ! LED1 means LED1= NOT LED1 which just toggles value of LED1. so if LED1 = 0, LED1 = 1 etc.

I calculated value used in decision branches by:
If 1 HZ required then since togging LEDs they need to be toggled at 2Hz
If 5 HZ required then since togging LEDs they need to be toggled at 10Hz

So if interrupt frequency is 150Hz then for 2Hz value for decision branch = 150/2 = 75
for 10Hz value for decision branch = 150/10 = 15

Don't forget simulation is much slower than real time.


Martin
Attachments
Multitask LEDs.fcf
(8 KiB) Downloaded 272 times
Martin

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times

Re: Multitask LEDs?

Post by rocket200 »

medelec35 wrote:Hi rocket200,
Yes I would personally use an interrupt. I have used timer0 since all timers only simulate with Flowcode V5.

I have attached a flowchart I believe is the simplest way to flash two LED's at two different rates.

If you want to experiment you could try just using 1 variable and toggle two bits!

Notes about the flowchart. LED1 = ! LED1 means LED1= NOT LED1 which just toggles value of LED1. so if LED1 = 0, LED1 = 1 etc.

I calculated value used in decision branches by:
If 1 HZ required then since togging LEDs they need to be toggled at 2Hz
If 5 HZ required then since togging LEDs they need to be toggled at 10Hz

So if interrupt frequency is 150Hz then for 2Hz value for decision branch = 150/2 = 75
for 10Hz value for decision branch = 150/10 = 15

Don't forget simulation is much slower than real time.


Martin

Simulates just fine, but when I download it to the microcontroller, both leds come on and just stay on.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Multitask LEDs?

Post by medelec35 »

rocket200 wrote: Simulates just fine, but when I download it to the microcontroller, both leds come on and just stay on.
That could be your hardware.
You will need to adjust Flowchart to suite the hardware you have got.
Take a look here on Flowchart settings:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

Flowchart I posted is assuming you have a EB006 that's set to external crystal oscillator with a frequency of 19660800Hz
and target device is 16F88

What I would do 1st if I was you is so a simple 1Hz osc.
e.g in main have
Loop: A3=1
delay 500ms
A3=0
delay 500ms
Go back Loop

Sounds to me like your oscillator is running much slower than 19MHz (if running at all?).

If you get stuck then perhaps you can say what your set up comprises of?


Edit: Just compile Flowchart to chip and can confirm working as intended. LED connected to A0 is flashing at 1Hz and LED A1 is flashing at 5Hz so Flowchart is ok for my set up.

If you have adjusted flowchart, then if you re-post it I will take a look.

Martin
Martin

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times

Re: Multitask LEDs?

Post by rocket200 »

medelec35 wrote:
rocket200 wrote: Simulates just fine, but when I download it to the microcontroller, both leds come on and just stay on.
That could be your hardware.
You will need to adjust Flowchart to suite the hardware you have got.
Take a look here on Flowchart settings:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

Flowchart I posted is assuming you have a EB006 that's set to external crystal oscillator with a frequency of 19660800Hz
and target device is 16F88

What I would do 1st if I was you is so a simple 1Hz osc.
e.g in main have
Loop: A3=1
delay 500ms
A3=0
delay 500ms
Go back Loop

Sounds to me like your oscillator is running much slower than 19MHz (if running at all?).

If you get stuck then perhaps you can say what your set up comprises of?


Edit: Just compile Flowchart to chip and can confirm working as intended. LED connected to A0 is flashing at 1Hz and LED A1 is flashing at 5Hz so Flowchart is ok for my set up.

If you have adjusted flowchart, then if you re-post it I will take a look.

Martin
I setup the 1hz osc. test and it works just fine.

My hardware is an Attiny2313(AVR) running at 4mhz. I have attached the adjustments I made to your flowchart.
Attachments
Multitask LEDs.fcf_avr
(7.5 KiB) Downloaded 245 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Multitask LEDs?

Post by medelec35 »

Ah that's the difference.
You have AVR, I have PIC.
I'm not sure on the differences to be honest. I don't know enough about timer 0 interrupts on AVR, and if it uses fosc/4 like PIC chips do?
One thing I have noticed unlike PIC version the interrupt frequency is grayed out on my AVR version 4.3. yours the same?

I have altered your Flowcode assuming it does since you left timer0 int on 1:1.
If this does not work then maybe some one who does know enough about both can convert for you?

Martin
Attachments
Multitask LEDsModified.fcf_avr
(7.5 KiB) Downloaded 243 times
Martin

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times

Re: Multitask LEDs?

Post by rocket200 »

medelec35 wrote:Ah that's the difference.
You have AVR, I have PIC.
I'm not sure on the differences to be honest. I don't know enough about timer 0 interrupts on AVR, and if it uses fosc/4 like PIC chips do?
One thing I have noticed unlike PIC version the interrupt frequency is grayed out on my AVR version 4.3. yours the same?

I have altered your Flowcode assuming it does since you left timer0 int on 1:1.
If this does not work then maybe some one who does know enough about both can convert for you?

Martin
It works!!! Thank you sooo much! What did you change?

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Multitask LEDs?

Post by medelec35 »

Your welcome.

I am guessing what happened is when you import PIC into AVR then prescaler of timer0 interrupt defaults to 1:1 is similar to PIC (it may not be?),
then the interrupt at osc frequency of 4MHz is 3.9KHz instead of intended 150Hz

What I did was double clicked timer0 interrupt, selected properties then changed prescaler from 1:1 to 1:8
(I think I may have left it on 1:64 by mistake, if so can you try 1:8 please and recheck the LED's Flash rate.)

Assuming this gives an interrupt frequency of approx 488Hz (as it does with PIC @4MHz) then I also altered value in 2Hz decision branch to 488/2 = 244
and altered value in 10Hz decision branch to 488/10 = approx 49
Martin

Post Reply