How to keep an 8Mhz pwm signal clean

Hi,

I'm generating an 8Mhz pwm signal on my Duemilanove from pin 10 (OC1B) in order to set the timing for a cmos camera module (OV7670). I'm able to make a reasonable looking signal, but when I run it through a buffer (5v - 3v3 volts) it shows up on the oscilloscope as two signals, one very slightly displaced (phase shifted?), and when I measure the signal at the cmos module the shift is much more extreme. This causes the signal generated by the module's prescaler to be totally unreadable, or at least I assume this is what's happening.

What could be the source of an issue like this? I've never had to work with a signal with frequency > 1Mhz and haven't seen this sort of problem before. Would a noisy supply voltage to the buffer cause bad things to happen? Wire length? Any insight would be greatly appreciated, or even direction to a more suitable form for the question. I'm happy to provide any more information that might be useful.

Thanks,
Sam

Could you show us the setup or the schematics? Maybe your signal picture as well?

It is natural for your first message to be vague, so let me imagine what an articulate message would have been :

"when I run it through an op amp buffer, LM324 it shows up on the Dual Trace oscilloscope as two signals, one very slightly delayed by 12 nanoseconds from the Arduino signal, and when I measure the signal at the module the delay is much more extreme, 60 ns.

What could be the source of the 60 nanosecond delay ? I've never had to work with a signal with frequency > 38.002Khz and haven't seen this sort of problem before I bought the dual trace oscilloscope model TEK 2013. Would a noisy 3.3002 volt supply voltage to the TTL 74HC01 buffer cause bad things to happen? Is a Wire length of 32.002 meters long enough to cause the 60ns delay?

sampullman:
I'm generating an 8Mhz pwm signal on my Duemilanove from pin 10 (OC1B)

No you're not.

You might be generating a square wave but an Arduino can't generate an 8MHz PWM signal.

How are you triggering? This can happen if you have the trigger level too high or too low and you are responding to transients or noise.

sampullman:
Hi,

I'm generating an 8Mhz pwm signal on my Duemilanove from pin 10 (OC1B) .....

:astonished:
As far as I know, PWM signal frquency is about 490Hz, which is very very far from 8MHz

when I measure the signal at the cmos module the shift is much more extreme. This causes the signal generated by the module's prescaler to be totally unreadable, or at least I assume this is what's happening.

I don't see why phase-shifts should matter here. The camera doesn't know what the original phase angle was. OTOH, if the signal is badly distorted, then ...

What could be the source of an issue like this? I've never had to work with a signal with frequency > 1Mhz and haven't seen this sort of problem before. Would a noisy supply voltage to the buffer cause bad things to happen? Wire length? Any insight would be greatly appreciated, or even direction to a more suitable form for the question.

All of the above, plus stray inductance and capacitance on the signal line.

I'm happy to provide any more information that might be useful.

Yes, especially the wire length.

@alnath,
Standard PWM frequency is as you noted.
If you google "arduino pwm frequency" you will see plentu of pages on how to change that frequency.
I think the one with "pwm cheat sheet" was quite good.

Thanks, CrossRoads, I'll have a look :slight_smile:

Hey guys, thanks for all the responses. I'll clarify my issue as well as I can.

@fungus @alnath
I should have mentioned how I was generating the signal, I suppose it's fairly non standard to do this with an arduino.
TCCR1A = 0xA3; // Set up fast pwm mode, top = OCR1A
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // Prescaler = 1
OCR1A = 1; // PWM freq = 8Mhz
OCR1B = 0; // Duty cycle = 50%

I'm not sure why I said buffer in my first post; I'm using this logic level converter from sparkfun: https://www.sparkfun.com/products/8745
I just realized that it has a resistor divider - I guess I'll look into getting a part more appropriate for higher freq. signals.

Anyways, I triple checked and resoldered some connections this morning and the signal is a little bit cleaner now but still not acceptable for the camera. Here is an image from an Agilent DSO-X 2012A digital oscilloscope of the signal after the buffer: Imgur: The magic of the Internet
There's a bit of noise on top if you can't see it in the picture. It's then connected to the camera with a 12'' sparkfun jumper cable. (Here's the signal at the end of the jumper: http://imgur.com/hA6aV91 - It's not as good, but the weird delayed signal I was seeing seems to be gone.) Unfortunately, the signal coming out of the camera is suffering the same issues as before. It looks like this without a prescaler: http://imgur.com/xPEdT5N and like this with a prescaler: http://imgur.com/KjumgWH

I guess my question has changed slightly, but the end result is the same. What could be causing the problems with my signal? A guy in another forum post - OV7670 with both arduino uno and now mega - Sensors - Arduino Forum - seems to have a very similar setup functioning.

Thanks for any input.

sampullman:
Hey guys, thanks for all the responses. I'll clarify my issue as well as I can.

@fungus @alnath
I should have mentioned how I was generating the signal, I suppose it's fairly non standard to do this with an arduino.
TCCR1A = 0xA3; // Set up fast pwm mode, top = OCR1A
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // Prescaler = 1
OCR1A = 1; // PWM freq = 8Mhz
OCR1B = 0; // Duty cycle = 50%

That seems fairly standard to me. I've done it a few times, things like the TLC5940 library do that to generate a clock signal, etc.

What I meant was that a PWM signal with a fixed 50% duty cycle is what most people would call a "square wave". :slight_smile:

In my experience the signal will be quite good, most of the 'noise' is in the measuring equipment (and breadboard if you're using one).

If all you want is to drop the signal down to 3.3V then a simple resistor divider is probably best.

Your images look to me like scope probe grounding problems, basically what this entire other thread is about. See especially links in reply #147,
http://forum.arduino.cc/index.php?topic=176968.135

Your last image looks like the scope isn't triggering properly - possibly off the wrong channel?
http://imgur.com/KjumgWH

The first two pictures - the "noise" there is not a noise but ringing caused by your (~measurement) setup..
Ringing is caused:

  1. by wrong impedance matching (DUT vs. probe, source vs. load)
  2. when you have a lot of inductive reactancies connected in your circuit (ie longer wires).

Mind a 3-5ns rising/falling edge (DUE is fast) does represent a spectrum with BW maybe 500MHz - so any resonant circuit connected to that "edge" will generate nice ringing (Marconi would like that..)

Try to decrease the "slew rate" of the output drivers in the DUE setup (if possible).

@fungus
The whole reason I'm using the logic converter is because I read that a voltage divider will screw with high frequency signals. I'll give that a shot, though.

@oric_dan
Thanks for the link, it does look like that's my issue. I think I'm a bit over my head when it comes to oscilloscope measurements, so I guess I have a lot of reading to do.

What I really don't understand is why the output of the camera is so nasty, even when the input looks ok and the prescaler is skipped.

Thanks again for the help. As a reward, here is a beautiful picture of my hand captured from my current setup: Imgur: The magic of the Internet

fungus:

sampullman:
I'm generating an 8Mhz pwm signal on my Duemilanove from pin 10 (OC1B)

No you're not.

You might be generating a square wave but an Arduino can't generate an 8MHz PWM signal.

That is a lie. The avr has a special mode that allows you to generate any frequency based on this formula. (F_CPU)/(2*(X+1))
I have generated an 8mhz signal using PWM for my ov7670 project.

16MHz/(2*(0+1) = 8 MHz
16MHz/(2*(1+1) = 4 MHz
16MHz/(2*(2+1) = 1 MHz
How much PWMing is going on?
Looks more like extreme frequency swings.

FWIW an R/R voltage divider is a misnomer there is always some C involved so it is either an R/RC divider or an RC/R divider. At DC and for any frequency where Xc is an appreciable fraction of R it will dominate a divider of that type and the Prime reason that a resistive divider isn't recommended for fast clock or data information. There is an app note from NXP that describes a 2 resistor (3V3 and 5V pull-ups) and one logic level mosfet (BSS138). The app note was for interfacing a low voltage TWI device to a higher voltage bus or the reverse. However it is entirely possible to use one to many devices to interface one to many lines or buy them as TXB0102, 0104 or 0108 for dual, 4 or 8 channel use. I like the single fet for simple interfaces and the duals and quads for RS232 and two wire at the same time.

Doc

Hi guys, I agree with the posting indicating that the CRO displays are ringing.
A question, are you using a x10 or x100 probe to sample the signal, if so have you compensated it.
That is in x10 or x100 mode connect the tip to a special square wave output terminal that MUST be on the front of your CRO if it is a decent one.
If the waveform is not a pure square wave, adjust the compensation by the screw driver adjustment on the side of the probe to get a square wave.
Check your probe or CRO manual.

I also agree that the display has some trigger problems, the CRO trigger settings need to be adjusted to get a stable display.

The level converter you use has to have the input and outputs kept as far apart as possible, for 8MHz, even using shielding in cables and on the level converter board. 8MHz is considered RF and behaves entirely different to DC or 9600baud digital signal.

Tom

TomGeorge:
Hi guys, I agree with the posting indicating that the CRO displays are ringing.
A question, are you using a x10 or x100 probe to sample the signal, if so have you compensated it.
That is in x10 or x100 mode connect the tip to a special square wave output terminal that MUST be on the front of your CRO if it is a decent one.
If the waveform is not a pure square wave, adjust the compensation by the screw driver adjustment on the side of the probe to get a square wave.
Check your probe or CRO manual.

That doesn't apply at these nanosecond timescales(*), the probe is nearly pure capacitive divider at these speeds, the
ringing is mainly due to the massive inductance of the scope ground lead (forms a loop of maybe hundred cm^2, thus
oodles of inductance compared with anything else in the circuit). This stray inductance resonates with the capacitive
divider of the probe whenever there's a fast edge. If you want to see what's really happening in the circuit you
must use a low-impedance probe...

(*) High impedance 10:1 probes are mainly resistive from DC to low kHz, mainly capacitive from 50kHz up - at 10MHz it
has an impendance of several kohms. The compensation adjustment involves a small variable capacitor that is tuned
so that the divide ratio is the same capacitively as resistively, which involves looking at square waves of kHz or so. You always have to take what you see at logic speeds with a pinch of salt unless
using the proper low-impedance probe (expensive, very awkward to use).

Here is some sample code to get 8mhz on the arduino uno pin 11

#include <avr/io.h>
int main(void){
	//Generate 8mhz pwm using arduino uno on pin 11
	DDRB|=(1<<3);//pin 11
	ASSR &= ~(_BV(EXCLK) | _BV(AS2));
	TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);
	TCCR2B=(1<<WGM22)|(1<<CS20);
	OCR2A=0;//(F_CPU)/(2*(X+1))
	while(1){}//do nothing
}