External Oscillator

Hello Everyone!

I want to ask that how can I use external clock with my arduino since I need a clock much higher than 16Mhz and I saw in the datasheet that one can use external clock by doing pre scaling so I want to ask that it it possible to use a clock much higher than 16 MHz and if someone can suggest that how I can do it?

Thanks in advance!

You can use any external oscillator you want, as long as you pre-scale it to 16 MHz. For example you could use a 64 MHz oscillator and a divide-by-4 external pre-scaler to feed 16 MHz to the ATmega.

@Johnwasser

Thanks for your reply but actually that's what problem is I need a higher clock than 16 MHz to feed to the arduino as I am reading a pulse width whose resolution is not very good and I cannot measure it accurately since the pulses are between 8 to 15 microseconds and now I am finding a way of either to use a external clock of higher frequency or to use a external fast counter so any ideas?

Thanks again

You can't clock the 328 at a faster clock rate - (there is a 20Mhz version) the chip won't work properly at faster clocks. The internal circuitry won't work much faster. If you are trying to work with something at that high a frequency you probably need a different device.

@kf2qd

Thanks for your reply and letting me know about that, that's what I was also thinking that may be I can't use higher clocks so the only solution now for me is to use a external fast counter since I have to measure the width accurately and the pulses are just too short 8-15 microseconds. I have a algorithm in arduino but that is not good since it takes one count every microsecond so it cannot measure widths accurately and I need a high resolution so I need to use some external fast counter with arduino so any ideas about that? Here is my code which is doing a count every microsecond

#include<stdlib.h>

unsigned int pulse_counts = 0;
char buffer[20];
char buffer2[20];
char s[4]=" , ";

unsigned int count = 0;
void setup()
{
Serial.begin(9600);
// Serial.println("pulse width measurment");

pinMode(3, INPUT);
}

void loop()
{
count = 0;
pulse_counts++;
while ((PIND & B00001000) == B00000000); // wait for HIGH
while ((PIND & B00001000) == B00001000) count++; // start counting until LOW

float usec = 1.0 * count * 0.50;

// For text file output - Uncomment this

// Serial.print("#S|AAA|[");
// Serial.print(dtostrf(usec,5,2,buffer));
// Serial.print(s);
// Serial.print(itoa((pulse_counts), buffer2, 10));
// Serial.println("]#");

// For serial output display - Uncomment this

Serial.print("Count = ");
Serial.print(pulse_counts);
Serial.print(" , Width = ");
Serial.print(usec, 2);
Serial.println (" microseconds");

// delay(1000);
}

scorp84:
I want to ask that how can I use external clock with my arduino since I need a clock much higher than 16Mhz and I saw in the datasheet that one can use external clock by doing pre scaling so I want to ask that it it possible to use a clock much higher than 16 MHz and if someone can suggest that how I can do it?

How high is "much" higher? I think you are cross-posting:
http://arduino.cc/forum/index.php/topic,98482.0/topicseen.html

Rather than float multiple potential solutions, and ask how to make them work, how about giving us a nice concise problem statement so we can discuss what a possible solution might look like. If you read the datasheet, then you saw that 20MHz is the maximum system clock frequency. In my book, that's not "much" higher.

If I wanted to measure an 8µs pulse, I might look to the Timer/Counter1 Input Capture Unit. With the timer running at system clock speed (prescaler = 1), that gives a 62.5ns resolution, so a measurement within a couple percent ought to be possible. If orders of magnitude more precision is needed, then I'd look to other hardware.

@ Jack

yes I need a higher resolution as I want to measure even if the pulse width is let's say 5.15 microseconds it should display accurately and I believe I have to use a external fast counter now but unfortunately I am not finding any :frowning: any ideas about that?

I see I'm late to the party, yet another thread where input capture was discussed and evidently tried:
http://arduino.cc/forum/index.php/topic,96971.0.html

How accurate is "accurately"? When you say 5.15µs, are you implying 0.01µs accuracy? It'd be pushing it to expect even 0.1µs accuracy with Timer1 running at 16MHz.

There's also a bigger picture here, namely, once a measurement is taken, what is done with it? How often do measurements need to be taken? If the intent is to measure each cycle, then that leaves precious little time to do the associated processing.

Sorry Jack but even if it is 5.1 then that would be fine means that 0.1 microsecond is good enough so what do you think now?

if my counter which I have developed by doing programming can do one count every 0.1 microsecond means 10 counts in 1 microsecond then even that is going to be good enough so what do you have to say about that?

float usec = 1.0 * count * 0.50;

You did not copy my code correctly , the right formula should be

float usec = 1.0 * count * 6 / 16; // See - Measuring Pulse Width - #20 by robtillaart - Project Guidance - Arduino Forum -

if my counter which I have developed by doing programming can do one count every 0.1 microsecond means 10 counts in 1 microsecond then even that is going to be good enough so what do you have to say about that?

An Arduino is 16Mhz. suppose the count++ takes one clock cycle and the test if the pin goes high 3 (load register and do a compare and do a jump ) that would mean that you need at least 4 instructions. 4/16 is about 0.25 micros so if you could do this in assembly that would be the ultimate limit in software on an Arduino.

If you use an NXP MBED at 100Mhz (6x as fast) you can get approx 0.1 usec accuracy in software.

@Robtillaart

Yes in your code it was 6/16 but when I changed it to 6/12= 0.5 then the results were better so thats why I used it like that

OK, I understand, but that means you can measure with 0.5 micro-seconds precission. Not bad for SW only.

Question: how many pulses are there? is it a continuous "train of pulses" or just one?

@ Robtillaart

its continuous train of pulses and not just one...if I can measure 10 counts in 1 microsecond then I can get much better accuracy but I don't know how can I achieve that I am trying to find some external fast counter but I am not finding any :frowning:

Your other topic has a link to a library that does what you want (within reason for a 16 MHz processor).

@ Robtillaart and others

Can I use the external high speed counter given by the link below with arduino, if I can use this then I would be able to achieve very good resolution and hence the accuracy. So please guide

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00000337.pdf