Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
theoneandonly2002
Posts: 4
Joined: Wed Feb 05, 2014 5:32 pm
Contact:

Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

Post by theoneandonly2002 »

Hi,

I need to controll the brightness of 8 LEDs individual using my atmega8.
I tried to build something, but it only works for 4 Leds.
If I use more, then the LEDs are just flickering.

Is there any other solution in flowcode to solve this Problem?

Thanks very much
Attachments
SoftPWM_Art4.2.fcf_avr
(14 KiB) Downloaded 243 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

Post by kersing »

Please do not post questions in the Tips and Tricks forum. That is reserved for posting (clever) solutions that may benefit other users.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

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

Re: Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

Post by medelec35 »

The only small issue I can spot with your flowchart is the LED's will never be off with duty of 0.
To correct that, instead of Timer_Count = PWMx
You should have Timer_Count >= PWMx
I don't believe adding the greater than sign will cure the flickering.

If you can see flickering then hardware speed is running to low for the application.
I would suggest you do the 1Hz test to make sure hardware is running at the correct speed.
If it is there either hardware has to run at a higher speed.
Or
Preload timer with a value that stops flickering but still allows main code to run with no issues.
If you preload with too high value, program will fail to run correctly

Can you try the attached flwochart.
I have preloaded timer0, but I'm not sure what is the best value to preload timer with?
It may need to be a bit of trial and error.

Martin
Attachments
SoftPWM_Art4.3.fcf_avr
(14 KiB) Downloaded 214 times
Martin

theoneandonly2002
Posts: 4
Joined: Wed Feb 05, 2014 5:32 pm
Contact:

Re: Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

Post by theoneandonly2002 »

Hi,

thanks for this.
It still shows the same problem. 4 Leds work. 5 or more no chance. Only flickering
But I checked the timing and it seems that my microcontroller is a little bit to slow.
When I do a delay of 200ms between the LEDs to get from dark to bright it takes around 1 second.

I set the fuses of the Atmega to 8Mhz and in Flowcode I did the same. I used AVR Studio 5.0 to set the fuses.
Is there anything else I can do?
Attachments
fuses1.png
(73.84 KiB) Downloaded 2776 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
Contact:

Re: Flowcode v4: Software PWM. Atmega8 8 LEDs Problem

Post by medelec35 »

I
theoneandonly2002 wrote:When I do a delay of 200ms between the LEDs to get from dark to bright it takes around 1 second.
It looks like your internal osc is running at the default 1MHz
That's why it's always a good idea when staring a new project to do a 1HZ test and make sure that on/off timings are correct.
Loading compiling your flowchart then loading hex file into my AXIS presto programming software shows:
AVR hex file.png
(90.76 KiB) Downloaded 2765 times
For some reason it's still showing 1MHz after you have selected 8MHz.
So if my programming software is showing correct information, it looks like your hardware is running 8 times slower than expected hence flickering.

How you got means of loading hex code directly and check the fuse settings?

Also after setting up fuses can you post the generated hex file so I can check it's fuse settings.
Martin

Post Reply