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

TomS

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

tempmj

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

the link to my page about it is:
http://www.controllerprojects.com/2011/03/31/automatic-audiovideo-channel-checker-part-3-%e2%80%93-ir-transmitter-circuit-take-2/

The current version of the code is at:
http://www.controllerprojects.com/wp-content/uploads/2011/03/SApower1_6_5.zip

Hope this is of some help to you.  I just used direct port manipulation and did not mess with timers.
http://www.controllerprojects.com
My hobby controller projects site.

TomS

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?

tempmj

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.
http://www.controllerprojects.com
My hobby controller projects site.

Go Up