I want a PWM frequency of 4.1KHz.

For general Flowcode discussion that does not belong in the other sections.
Post Reply
rradojko
Posts: 4
http://meble-kuchenne.info.pl
Joined: Thu Dec 24, 2020 9:54 am

I want a PWM frequency of 4.1KHz.

Post by rradojko »

Hello,

I want a PWM frequency of 4.1KHz. I am using Flowcode9 and Arduino Nano (Atmega328)
But, whatever I type in the Overflow Period, the PWM frequency does not change (see picture).

Where is the problem?
Attachments
PWM_FC9_1.jpg
PWM_FC9_1.jpg (114.67 KiB) Viewed 3909 times
PWM_FC9_0.jpg
PWM_FC9_0.jpg (119.14 KiB) Viewed 3909 times

BenR
Matrix Staff
Posts: 1742
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 443 times
Been thanked: 604 times

Re: I want a PWM frequency of 4.1KHz.

Post by BenR »

Hello,

When compiling to chip you likely are getting a warning that your target device doesn't have a period register, hence the value cannot be changed on your device from the default value of 256. I'll see if I can make this more obvious in the component as I'm sure it's very frustrating.

rradojko
Posts: 4
Joined: Thu Dec 24, 2020 9:54 am

Re: I want a PWM frequency of 4.1KHz.

Post by rradojko »

Hello,

Thanks Ben for the answer.
I tried compiling again.
Really issue a warning "Period control register not available on target device, period will default to 255 + 1"
It would be good if the warning was written in red.

I would ask you if you can find a solution to this. The Atmega328 is a very popular processor.
Now I can only select 5 different PWM frequencies. This choice is too small. This is very disturbing.

Thank you and have a nice day.

BenR
Matrix Staff
Posts: 1742
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 443 times
Been thanked: 604 times

Re: I want a PWM frequency of 4.1KHz.

Post by BenR »

Hello I'm afraid it's a limitation of the atmega328 hardware and not the software. You could maybe create software based pwm using a timer interrupt to give you more control over the output frequency.

rradojko
Posts: 4
Joined: Thu Dec 24, 2020 9:54 am

Re: I want a PWM frequency of 4.1KHz.

Post by rradojko »

All right, I understand.

I also tried PWM chanel 3. PWM chanel 3 uses timer1.
Timer1 has multiple registers to set up and is 16bit.
Unfortunately, timer1 does not work either.
Although the datasheet says "Timer1 Variable PWM period".

Why doesn't PWM work? There is no pwm signal on PORT B3.


Thank you and have a nice day.
Attachments
variable PWM period.JPG
variable PWM period.JPG (83.2 KiB) Viewed 3857 times

rradojko
Posts: 4
Joined: Thu Dec 24, 2020 9:54 am

Re: I want a PWM frequency of 4.1KHz.

Post by rradojko »

I tried again.
If I select PWM Chanel3 there is no more warning "Period control register not available on target device, period will default to 255 + 1"

There is no PWM signal on port B1.
What is wrong?

I am also attaching a test program.
Attachments
PWM_RR_9ka.fcfx
(8.18 KiB) Downloaded 166 times
opozorilo prevajalnika.jpg
opozorilo prevajalnika.jpg (32.16 KiB) Viewed 3843 times

zoli2496
Posts: 28
Joined: Wed Sep 22, 2021 7:23 am
Been thanked: 2 times

Re: I want a PWM frequency of 4.1KHz.

Post by zoli2496 »

PWM doesn't work at all for me either. Arduino Nano. Chanel1-6, nothing. Please help me.
pwm.gif
pwm.gif (52.48 KiB) Viewed 1617 times
pwm2.gif
pwm2.gif (125.32 KiB) Viewed 1616 times

medelec35
Matrix Staff
Posts: 1452
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: I want a PWM frequency of 4.1KHz.

Post by medelec35 »

Hello.
Unfortunately, a screenshot does not help.
For any issues, can you please attach your fcfx project.
For example, if the ADC component was set to AREF and you have not connected a jumper from AREF to 5V, then PWM will not work as expected.
Without a jumper, you will need to set AREF to AVCC.
I have done that in the attached project, which works on hardware.
If you want a wider frequency range, then you will need a timer-based interrupt PWM as Ben has suggested in an above post.
Attachments
Nano 328 PWM 1.fcfx
(11.01 KiB) Downloaded 58 times
Martin

zoli2496
Posts: 28
Joined: Wed Sep 22, 2021 7:23 am
Been thanked: 2 times

Re: I want a PWM frequency of 4.1KHz.

Post by zoli2496 »

Hello.

After I switched the potentiometer to AVCC, it worked right away. :) Thank you very much!

Post Reply