Trying to fix atmega32 need 500khz signal at 5V

does anyone know how to get 500khz signal at 5v from any where i have an arduino and several atmega 32 MCU,s i by mistake set the fuses to external clock to reset fuses I have to have a signal from 3.3-5V
at 500khz-2mhz square wave would be best if any one knows how to program an arduino uno or atmega328p,atmega32A,attiny85,attiny84 to do that I would greatly appreciate the help

Any of the hardware timers should be able to give you that on one of the PWM pins. 500kHz is switching every 1us. Set it for CTC mode with OCRxA as TOP and set the OCRxA to 16. Use a prescaler of 1.

Using Timer 1 on an UNO it would look something like this:

TCCR1A = (1 << COM1A0); // toggle on compare match

TCCR1B = (1 <<WGM12); // CTC mode / no prescaler / OCR1A as TOP

OCR1A = 16; // 16 ticks times 62.5ns/tick is 1us

That should give you 500kHz square wave on pin 9 if I’m not messing it up.

guys ill be honest im not good with peripherals at all if possible do you have any code i could use ?

IIRC, Adafruit has a verion of ArduinoISP that provides a clock signal on one of the pins.

i didnt see any thing like that ?

bandmwhitt2013:
guys ill be honest im not good with peripherals at all if possible do you have any code i could use ?

That was code. You don’t have to be good with peripherals because I gave you the code.

Here, is this better?

void setup(){
     TCCR1A = (1 << COM1A0);
     TCCR1B = (1 << WGM12);
     OCR1A = 16;
////  Pin 9 is now outputting a 500kHz square wave.  

///   do whatever else you want to do

////  if you want to turn the square wave off
/////  TCCR1A = 0;

/////  to turn it back on
/////  TCCR1A = (1 << COM1A0);

}

void loop(){}