Layout in Flowcode 4. Need help. LEDs and Switches

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
HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

OK I have to do a little project in Flowcode 4 in university but I have some problems.
I am using an ATmega8 micro controller.

I have 4 Input signals and 8 output LEDs.

0 = off / LED (PWM 0%)
1 = on / LED (PWM 100%)
2 = LED (PWM 30%)

IF THEN
INP0 = 0 OUT0 .. OUT2 / OUT4 .. OUT6 = 1
INP0 = 1 OUT0 .. OUT2 / OUT4 .. OUT6 = 2

INP1 = 1 OUT1 = 2
INP2 = 1 OUT5 = 2

INP3 = 1 OUT3 / OUT7 = 1

Whats the best way to do this?

I know that I have 2 PWM Generators on this micro controller.
Can I use the calculations like:
eg:
IF Input 0 is high send "PWM signal 1" to Output Port (eg. PB1, PB2, PC1, PC2)

Thanks

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: Layout in Flowcode 4. Need help. LEDs and Switches

Post by Benj »

Hello,

You may be better off looking at this guide to creating software PWM and you can only control up to two outputs pins with PWM.

http://www.matrixmultimedia.com/article.php?a=52

HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Re: Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

and with the software pwm it is possible to do this?
then i will try this.

one other question.
I want to light up one of the leds when a toogle to make switch is pressed for one time, but the the led should light up 2 seconds longer then the switch is pressed. The delay funktion is not working, because the whole system waits the 2seconds.
is there a formula to set the time the led should light up?

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: Layout in Flowcode 4. Need help. LEDs and Switches

Post by Benj »

Hello,

You need to create an endless loop to keep reading your switches etc.

Inside this loop add a small delay eg 10ms.

When you detect the switch is pressed output 1 to the LED and then reset a count variable to 0.

Every iteration around the loop add 1 to the count value and do a test to see if the count value is greater then 200. If it is then you have waited 2 second and you can switch off the LED.

That should give you a nice 2 second delay without holding up your program.

HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Re: Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

Hi,

thanks for this info, but i dont understand this, because my english is not the best :-(
can you make a small example for me in a "*.fcf_avr" file?

that would be great.


the pwm signals are working at the moment :-)

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: Layout in Flowcode 4. Need help. LEDs and Switches

Post by medelec35 »

HMS wrote: can you make a small example for me in a "*.fcf_avr" file?

that would be great.
Here is a basic version.
You will need to alter configuration settings so will work on your hardware.

Martin
Attachments
2 Sec Delay.fcf_avr
(7 KiB) Downloaded 245 times
Martin

HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Re: Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

that looks great.
i will give this a try tomorrow mornig.

thanks thanks

HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Re: Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

Hey thanks very much for everything.
I tried now to add a second switch and a second led.

but without success.
Only the first macro starts.

whats the best way to do this.
Attachments
2 Sec Delay_modified.fcf_avr
(15.5 KiB) Downloaded 229 times

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: Layout in Flowcode 4. Need help. LEDs and Switches

Post by Benj »

Hello,

Your macros had while 1 loops so once you jumped into one you would never come back.

Here is a example that allows 2 channels. Note that the simulation is a bit slow but the timings on actual hardware should be pretty much bang on.
Attachments
2 Sec Delay_modified.fcf_avr
(9 KiB) Downloaded 235 times

HMS
Posts: 8
Joined: Thu Jun 09, 2011 6:58 am

Re: Layout in Flowcode 4. Need help. LEDs and Switches

Post by HMS »

Hi,

thanks very very much again.
I had to to a lot of work, so i was not able to work on this.
Today I programmed my Atmega8 the first time.

And now there is a Problem.
Its not really working.

The LED is not turning on when I push and release the button.
No It only turns on when I hold the button 2 seconds and goes of when i release it.

i am not sure whre is the problem. in the simulation it works perfectly.
Attachments
2 Sec Delay_x.fcf_avr
(7 KiB) Downloaded 247 times

Post Reply