Why does VirtualWire conflicts with PWM signal in

2019-09-06 07:15发布

问题:

After debugging a hardware prototype I'm making with an Arduino-like board and ATmega328, I noticed that the RF library VirtualWire disables PWM signal in pin D10. Why is that?

If I comment out the bit of code below, analogWrite (PWM) on pin D10 works again:

setup() {
  ...
  vw_set_rx_pin(2);
  vw_setup(2000);    // Bits per sec
  vw_rx_start();       // Start the receiver PLL running

  analogWrite(10, 180);
  ...
}

回答1:

VirtualWire uses CTC on timer 1 via OCR1A, which both completely disables PWM operation for OC1A (on D9) and OC1B (on D10) and prevents OC1A from operating freely. OC1B is still usable, but only in the modes prescribed by CTC at the rate programmed into the timer by VirtualWire.



标签: arduino