Go Down

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

pretent

Hello,
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?

greetings
Pretent

zoomkat

You might search for IR in this and the old forum as there is info for IR remote controls and such.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

johnwasser

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

TomS

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.

John:
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! :)
Tom

johnwasser

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up