1

I found this question: Set PWM frequency to 25 kHz

It is useful, however, I want to use it to generate ~14KHz?

int d = 0;            // pwm value

void setup()
{
  //  Sets Timer1 to Phase Correct
  //  F_CLOCK / ( Prescaler * ORCR1A * 2 ) = Freq in Hz
  //  16000000 / (1 * 512 * 2 ) = 15625 Hz
  TCCR1A = _BV (WGM10) | _BV (WGM11) | _BV (COM1B1);  // Phase Correct
  TCCR1B = _BV (WGM13) | _BV (CS10);                  // Phase Correct / Prescale 1
  OCR1A = 571;                                        // Sets Top to 512 --571
  OCR1B = 0; // Sets Pwm = 
    pinMode(10, OUTPUT);
    pinMode(0, INPUT)
}  

void loop()
{
  d = (analogRead(0)); 
  d = map(d, 0, 1023, 0, 512);
  OCR1B = d;
}

I used this sketch to test the frequency which works good. If I change the pinMode(10, OUTPUT);, into: pinMode(9, OUTPUT); and there is no output, why?

VE7JRO
  • 2,515
  • 19
  • 27
  • 29
laoadam
  • 45
  • 5

0 Answers0