Generating 4MHz signal but not getting 5V in digital pin

Hello,

I need to generate a 4 MHz signal clock with Arduino Uno. I’m using the next code to generate this signal:

void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
TCCR2A = 0x23;
TCCR2B = 0x09;
OCR2A = 3;
OCR2B = 1;

}

void loop() {
// put your main code here, to run repeatedly:

}

To see the signal I conected pin 3 to an oscilloscope and indeed I got a signal of 4MHz. However the signal does not rise 5V as I expected, it just rise 0.7V. Another thing I expected was that signal should be a square signal.(between 5V and 0V). I attached a picture showing the wave form.

Thank you in advance

Using a 1:10 probe that is not correctly adjusted ?

You should check the specs for the slew rate of the uno chip you are using. I suspect that this is to much for the uno. Maybe you could get 2MHz, but 4MHz looks like a long shot. Try 2MHz and see if that works OK first.

Koepel:
Using a 1:10 probe that is not correctly adjusted ?

Yes, you were right, thank you very much.I used the wrong probe(really stupid mistake). Do you know how can I reduce the voltage peak of 7V? Is it possible get a "perfect" square wave, I mean 5V to 0V ?

That peak you see is also probably because of the probe you use :wink:

Does your scope come with a square wave output?

septillion:
That peak you see is also probably because of the probe you use :wink:

Does your scope come with a square wave output?

Did you see the picture I attached in the post?

Yes, what about it?

Did you see the question I asked in reply #4? :wink:

septillion:
Yes, what about it?

Did you see the question I asked in reply #4? :wink:

Sorry I didn't understand you. No, it does not come with a square wave output(do you mean Y=data^2?). I just plot the data that I got from the oscilloscope.

Most scopes come with a square wave output (nothing to do with Y=data^2?) See (for example):

To the right of the intensity knob (below the "Freq" and "Period" buttons).

This is used to adjust the probe. The spike you see probably just is probe oscillation and isn't really there. :slight_smile:

septillion:
Most scopes come with a square wave output (nothing to do with Y=data^2?) See:

To the right of the intensity know (below the "Freq" and "Period" buttons).

This is used to adjust the probe. The spike you see probably just is probe oscillation and isn't really there. :slight_smile:

Yes, you are right. I have been checking it out, it seems this is the reason of the problem. We have quite new oscilloscope(Rohde & Schwarz RTE1022.22 Digital Oscilloscope | TestEquity) and we have to adjust the probe with a different way.

Anyway, thank you so much, you really helped me

Measure the 5V pin of the Arduino Uno. If that is 5.0 V then the Arduino Uno outputs a 4 MHz signal as a good square wave between 0.0V and 5.0V. It is a perfect square wave. It really is. If you see something else, then you measure it in the wrong way.