Go Down

Topic: PWM frequency 40kHz (Read 7852 times) previous topic - next topic


I'm trying to get a PWM signal out of the Uno with a frequency of 40kHz but i can't reach the required frequency.
Can anyone help me reaching this frequency?



You might search for IR in this and the old forum as there is info for IR remote controls and such.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


It's not clear if you want to modulate a 40kHz carrier, turning it on an off in pulses of varying width like for a IR remote control, or modulate the width of pulses happening 40,000 times per second.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


I am obviously not the original poster, but since I will have to tackle the same problem very soon, I thought I might jump in here as well.

I will have to use a 40KHz frequency to control a transistor, so 40.000 times per second on/off.
Do you have any suggestions for this?

Thanks a lot! :)


The AVR ATmega processors have several counter/timer registers that can be set up to output PWM.  Here is a tutorial on how to set that up: http://sites.google.com/site/qeewiki/books/avr-guide/pwm-on-the-atmega328

The system clock is 16,000,000 Hz so to get to 40,000 Hz you will use a divisor of 400 which would be a Prescaller_value of 2 and a TOP_Value of 199.  That should get you 200 levels of PWM at 40,000 samples per second.

You can enable an interrupt at the end of each cycle so you can change the PWM value between each pulse.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Thank you very much, I will look into this and give it a try!


I have 56kHz modulation for a remote control working on arduino.

the link to my page about it is:

The current version of the code is at:

Hope this is of some help to you.  I just used direct port manipulation and did not mess with timers.


I couldn't have a look at your code yet tempmj, but do I understand you right, that you are not using PWM but rather direct port manipulation + delay + NOP to arrive at a certain frequency?

But this would tie up the entire Arduino whereas with PWM you are not burdening the processor, right?


I believe you are correct.  However in my example i am using it to send IR Remote Control codes, so the processor will be busy with sending the codes regardless of the carrier modulation that i'm creating with the 56kHz.  If you are needing real PWM independent of a single task my example would not work.  I wasn't sure the use that you were needing.  It sounds like it may not fit your needs.

Go Up