Pages: [1]   Go Down
Author Topic: PWM frequency 40kHz  (Read 4387 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Tesla Member
***
Karma: 147
Posts: 9741
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might search for IR in this and the old forum as there is info for IR remote controls and such.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8974
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley
Tom
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8974
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

http://www.controllerprojects.com
My hobby controller projects site.

Offline Offline
Full Member
***
Karma: 0
Posts: 110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

http://www.controllerprojects.com
My hobby controller projects site.

Pages: [1]   Go Up
Jump to: