Generate digital clock of 1 MHz

Hello,

I am new in Arduino so I don't know if it is possible or not in Arduino.

I want to generate 4 phase lock square wave of 1 MHz which can be delayed by certain delays. Minimum delay resolution ideally should 1nS but if I can achieve a delay resolution of 10nS also, it would be nice.

I have Arduino nano (16 MHz), can nano do what I want? If yes, then how would it be possible?

A single clock cycle of a 16MHz Arduino is 16.25 nS. Does that tell you something?

...R

yea, I thought that as well. but still, want to confirm if there is any possibilities like overclocking or something.

Robin2:
A single clock cycle of a 16MHz Arduino is 16.25 nS. Does that tell you something?

...R

Yes, it tells me you can't do arithmetic.
62.5ns (note the lower case 's')

You're asking to overclock a 20 MHz processor (Arduino uses a 16 MHz crystal, but the processor itself is rated to run at up to 20 MHz), to 1 GHz. Seriously? That would also just be able to give you your desired 10 ns resolution. For a 1 ns delay resolution you'll have to look at a clock of at least 10 GHz - you need at least a handful of clock cycles to handle the delay.

GrooveFlotilla:
62.5ns (note the lower case 's')

Grovelling apology :slight_smile:

...R

prabhak:
I want to generate 4 phase lock square wave of 1 MHz which can be delayed by certain delays.

You can use the timer hardware in the Arduino to output a squarewave of 4MHz, you'd then need external logic to generate 4 phases.

You could make a crude variable delay with a couple of schmitt trigger inverters and an RC circuit using a digital potentiometer.

Yours,
TonyWilk

prabhak:
Hello,

I am new in Arduino so I don't know if it is possible or not in Arduino.

I want to generate 4 phase lock square wave of 1 MHz which can be delayed by certain delays. Minimum delay resolution ideally should 1nS but if I can achieve a delay resolution of 10nS also, it would be nice.

I have Arduino nano (16 MHz), can nano do what I want? If yes, then how would it be possible?

Have you done any reasearch on the Arduino prior to asking your question?

Have you looked at the data sheet for the controller?

You need a much faster processor for something like this. you need to make changes at 10ns = ~100MHz, and you need to do math to figure out when to do that - meaning you need the processor to be significantly faster than that. This is far beyond what a typical micro can do, you may have a hard time finding an appropriate part for this.

DrAzzy:
You need a much faster processor for something like this.

Not true, you only need a much faster processor if the rate of change is in the MHz - unless you restrict yourself to direct synthesis from the processor pins.

Yours,
TonyWilk

You could just use the ds1307 real time clock.
it's simple:

  1. wire it up
    VCC >> 5v
    GND >> GND
    SCL >> SCL
    SDA >> SDA
    SQ >> output of 1MHz

  2. code it

here's the code:

// SQW/OUT pin mode using a DS1307 RTC connected via I2C.
//
// According to the data sheet (http://datasheets.maxim-ic.com/en/ds/DS1307.pdf), the
// DS1307's SQW/OUT pin can be set to low, high, 1Hz, 4.096kHz, 8.192kHz, or 32.768kHz.
//
// This sketch reads the state of the pin, then iterates through the possible values at
// 5 second intervals.
//

// NOTE:
// You must connect a pull up resistor (~10kohm) from the SQW pin up to VCC.  Without
// this pull up the wave output will not work!

#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

int mode_index = 0;

Ds1307SqwPinMode modes[] = {OFF, ON, SquareWave1HZ, SquareWave4kHz, SquareWave8kHz, SquareWave32kHz};


void print_mode() {
  Ds1307SqwPinMode mode = rtc.readSqwPinMode();
  
  Serial.print("Sqw Pin Mode: ");
  switch(mode) {
  case OFF:             Serial.println("OFF");       break;
  case ON:              Serial.println("ON");        break;
  case SquareWave1HZ:   Serial.println("1Hz");       break;
  case SquareWave4kHz:  Serial.println("4.096kHz");  break;
  case SquareWave8kHz:  Serial.println("8.192kHz");  break;
  case SquareWave32kHz: Serial.println("32.768kHz"); break;
  default:              Serial.println("UNKNOWN");   break;
  }
}

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  print_mode();
}

void loop () {
  rtc.writeSqwPinMode(modes[2]);
  print_mode();

  //if (mode_index > 5) {
    mode_index = 2;
  //}

  delay(500);
  while(1);
}

@ idesign, I don't see where the 1307 can output a square wave any faster than 32KHz. Can you explain?

Your code comes from here. They don't mention 1MHz there.