Go Down

Topic: PWM @ 4MHz (Read 1 time) previous topic - next topic


I hope someone can help me with this, I need to generate a 4MHz signal at 50% duty cicle using a PWM pin. It can be any of the PWM pins, can anyone help me with this. Thanks.


Oct 19, 2011, 11:25 pm Last Edit: Oct 19, 2011, 11:27 pm by hickscorp Reason: 1
Hello CustomDev,

[Notice]Excuse me in advance if i'm out of topic, i started Electronics a week ago, and just received my Arduino 2 days ago[/Notice]

As far as i understand your question, you want to change the frequency from the actual vanilla arduino PWM frequency to a custom one? There would be two distinct solutions, which of course involves that you first look for the actual PWM frequency of an un-hacked arduino. Once you know that, here would be the two solutions which popped into my mind:
- Software hack: a fast search gave me this link: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1152547089 It apparently involves hacking a little bit of the wiring software source code and re-compiling it for your purpose.
- Hardware extension: Here, two different solutions. Lets's say the Arduino PWM native frequency is lower than the one you're trying to get, you'll need a Frequency Multiplier. If the opposite case (Which i think would be correct), you'll need a Frequency Divider. i have found one which divides by two and preserves duty cycle here: http://analog-innovations.com/SED/Div2PercentSame.pdf. You might be lucky if the native Arduino PWM frequency is a multiple of two of the one you're aiming (Eg. 8 or 16 are both luck), because then you would have to modify those schematics or chain them together.

About this matter, i don't really know where to start, but i found plenty of answers on google.

Again: Please someone not novice confirms or informs my thoughts, i never tried any of that myself.



Thanks for your help, but if anyone needs to do it, this is the code I used to get a 4MHz at 50% duty cicle on pin 3:

pinMode(3, OUTPUT);
TCCR2A = 0x23;
TCCR2B = 0x09;
OCR2A = 3;
OCR2B = 1;

With this I get a very nice square wave that I am using as a clock signal for a smart card.

Go Up