Page 1 of 1
Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 7:07 am
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
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 10:04 am
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
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 11:59 am
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?
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 5:31 pm
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.
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 7:33 pm
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

Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 8:20 pm
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
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 09, 2011 9:49 pm
by HMS
that looks great.
i will give this a try tomorrow mornig.
thanks thanks
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Mon Jun 13, 2011 2:50 pm
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.
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Tue Jun 14, 2011 10:46 am
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.
Re: Layout in Flowcode 4. Need help. LEDs and Switches
Posted: Thu Jun 23, 2011 8:52 pm
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.