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
Layout in Flowcode 4. Need help. LEDs and Switches
Moderator: Benj
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Layout in Flowcode 4. Need help. LEDs and Switches
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?
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?
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Layout in Flowcode 4. Need help. LEDs and Switches
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
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
Here is a basic version.HMS wrote: can you make a small example for me in a "*.fcf_avr" file?
that would be great.
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
Re: Layout in Flowcode 4. Need help. LEDs and Switches
that looks great.
i will give this a try tomorrow mornig.
thanks thanks
i will give this a try tomorrow mornig.
thanks thanks
Re: Layout in Flowcode 4. Need help. LEDs and Switches
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.
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
- 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
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.
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Layout in Flowcode 4. Need help. LEDs and Switches
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.
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