Generating 18kHz signal

This is one way:

const byte LED = 10;  // Timer 1 "B" output: OC1B

// 16 MHz clock divided by 18 KHz frequency desired
const long timer1_OCR1A_Setting = 16000000L / 18000L;

void setup() 
 {
  pinMode (LED, OUTPUT);
  // set up Timer 1 - gives us 18 KHz 
  // Fast PWM top at OCR1A
  TCCR1A = _BV (WGM10) | _BV (WGM11) | _BV (COM1B1); // fast PWM, clear OC1B on compare
  TCCR1B = _BV (WGM12) | _BV (WGM13) | _BV (CS10);   // fast PWM, no prescaler
  OCR1A =  timer1_OCR1A_Setting - 1;                 // zero relative  
  OCR1B =  (timer1_OCR1A_Setting / 2) - 1;           // 50% duty cycle
  }  // end of setup

void loop() {}

Output is 18 KHz:

Frequency analysis (there are harmonics, which you expect with a square wave):