void setup()
{
pinMode(freqOutputPin, OUTPUT);
Serial.begin(9600);
// Set Timer 2 CTC mode with no prescaling. OC2A toggles on compare match
//
// WGM22:0 = 010: CTC Mode, toggle OC
// WGM2 bits 1 and 0 are in TCCR2A,
// WGM2 bit 2 is in TCCR2B
// COM2A0 sets OC2A (arduino pin 11 on Uno or Duemilanove) to toggle on compare match
//
TCCR2A = ((1 << WGM21) | (1 << COM2A0));
// Set Timer 2 No prescaling (i.e. prescale division = 1)
//
// CS22:0 = 001: Use CPU clock with no prescaling
// CS2 bits 2:0 are all in TCCR2B
TCCR2B = (1 << CS20);
// Make sure Compare-match register A interrupt for timer2 is disabled
TIMSK2 = 0;
// This value determines the output frequency
OCR2A = ocr2aval;
Serial.print("Period = ");
Serial.print(period);
Serial.println(" microseconds");
Serial.print("Frequency = ");
Serial.print(freq);
Serial.println(" Hz");
}
void loop(){}
I am working on a project where i need an ultrasonic pulse of 8Mhz every one second and emitter is piezo disc. Please help me with the code.