PWM problem in AVR

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

Post Reply
Jan S.
Posts: 7
Joined: Thu Oct 02, 2008 7:13 am
Contact:

PWM problem in AVR

Post by Jan S. »

MHello,

IΒ΄ve a litte Problem with the PWM in my flowchart in AVR.
After a long search here in the forum, a canΒ΄t find the right solution for my Problem, so I would ask the experts for my special case.

I use a tiny26 as shown in the circuit diagramm above. The LED-Leuchtkopf V3 (LED-lighthead - Iam a German ;) ) schould be dimmed with the tiny26 via PWM.
In the simulation of my flowchart, the PWM works correctly. But if I programm the tiny26 and try it in my diagramm, it doesnΒ΄t work.
the clock frequency is correct adjusted.

I think the problem is, that the PWM doesnΒ΄t know, on witch output it schuld give the signal out.
So i must declare it, but how can I try this? With a C-Code? If yes, can someone help me in this, becaus I canΒ΄t wirte C-Code.

I'm very pleasd, if someone can help me, and I'm sorry for partly bad english :)

Yours sincerely

Jan S.
Attachments
circuit diagram_PWM-dimmer.JPG
circuit diagram_PWM-dimmer.JPG (122.63 KiB) Viewed 6502 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: PWM problem in AVR

Post by Sean »

Hello Jan,

The main PWM outputs of the ATtiny26 are available on pins 2 and 4 (OC1A and OC1B). Pins 1 and 3 provide can provide secondary, inverted, non-overlapping outputs (/OC1A and /OC1B) that can be used for 'push-pull' circuits. This feature is not supported by Flowcode.

The simples solution would be to move your pin 1 connection to pin 2. This will allow direct control from Flowcode using PWM channel 1

Jan S.
Posts: 7
Joined: Thu Oct 02, 2008 7:13 am
Contact:

Re: PWM problem in AVR

Post by Jan S. »

Hi,

first of all, thanks for answer by return!

thats not the problem, becaus I canΒ΄t measure anything with the oscilloscope on each of the four PWM-Pins at the tiny26.
I changed also the Pin 1 with Pin 2
Is maybe the Programm the Problem? This is a lite test programm, can you check it please?

The clock frequency is 12MHz
Attachments
flowchart.JPG
flowchart.JPG (38.19 KiB) Viewed 6478 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: PWM problem in AVR

Post by Sean »

Hello Jan,

I have attached a program that might perform the function you require.
t26pwm.fcf_avr
(4.5 KiB) Downloaded 353 times
It uses the input on A1 to switch the PWM output (pin 2) between two duty cycle values. I have set them to 0 (permanently off) and 26 (approximately 10% duty). They can each have any value between 0 and 255.

This is a very simple program that would benefit from some improvements (it is only necessary to write the PWM duty value when the state of A1 changes).

Let me know if this solves the problem.

Jan S.
Posts: 7
Joined: Thu Oct 02, 2008 7:13 am
Contact:

Re: PWM problem in AVR

Post by Jan S. »

Hello Sean,

no, itΒ΄s the same Problem, nothing happend on any of bove output.
IΒ΄ve also checked, if the clock frequency is the problem, but it isnΒ΄t the problem.
Also I used a second ΒµC, but nothing change.


If tryed another way and I get some output.
If I switch on the switch, IΒ΄ve after 18 seconds a high signal, no frequency, only a DC voltage.
How can this be?

IΒ΄ve attached the AVR file
Attachments
Dimmer test.fcf_avr
(6 KiB) Downloaded 312 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: PWM problem in AVR

Post by Sean »

Hello Jan,

I tested your program on one of our E-blocks systems and it seems to work.

Can you confirm that your circut is working properly - by downloading a simple program to flash some of the outputs slowly?

The 13v zener diode does not have a significant load on the cathode end. Is it possible that the supply voltage to the ATtiny26 is not being regulated adequately? It might be exceeding the maximum voltage for the device.

Have the device configuration fuses been set?

Jan S.
Posts: 7
Joined: Thu Oct 02, 2008 7:13 am
Contact:

Re: PWM problem in AVR

Post by Jan S. »

Hi Sean,

the Voltage is constant enough, I have also connect the tiny26 the a power supply with 4VDC and an parallel connected capacitor with 10000ΒµF, so, thats a really constat voltage ;). The Problem is the same as before.
The diagramm is right connected, becaus when I use the programm in the attachment (I call it "alternativ PWM") the LEDs will be more or less brighter of each high-signal of the switch.

This solution is an alternative way. But the problem in this is, that the delay has a min. time of 1ms. Our eye see 25 pictures/second (Hz) = every 40ms one picture. IΒ΄ve set me a maximum of 20ms for one periode. I canΒ΄t turn the LED on the required darkness. Out of this, I nead the PWM-signal with a frequency of circa 150Hz.
Attachments
Test1.fcf_avr
(8 KiB) Downloaded 300 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: PWM problem in AVR

Post by Sean »

Hello Jan,

Here are some update files that might help with the PWM component problem.
ATTINY26.fcd
(4.88 KiB) Downloaded 321 times
PWM_Code.c
(9.64 KiB) Downloaded 345 times
The .fcd file should be copied into 'FCD' folder of your Flowcode_AVR installation and the .c file should be copied into the 'Components' folder (save the original versions of both the files before overwriting them).

Your original programs might work with these updates (I am using these files with my test system).

Also, if you require program delays less than 1ms, there are two C functions that can be called from Flowcode using the C Code blocks.

Delay_us(x);
Causes a delay of x microseconds (x = 0 to 255)

Delay_10us(x);
causes a delay of 10x microseconds (x = 0 to 255)

It is also possible to pass Flowcode variables to C functions, but his topic is covered in other forum postings.

Jan S.
Posts: 7
Joined: Thu Oct 02, 2008 7:13 am
Contact:

Re: PWM problem in AVR

Post by Jan S. »

Hello Sean,

these fils work at the original programm!
and now it works perfekt, thanks for all!

With best regards

Jan S.

Post Reply