0

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);
  ...
}
Ricardo
  • 748
  • 12
  • 26

1 Answers1

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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • It's good to know that, thanks! Is there any way to circunvent that, I mean change VirtualWire and recompile it so that it frees those two pins? Should I pose this as a separate question in SO? – Ricardo Jan 12 '14 at 11:00
  • 1
    Unfortunately no. VirtualWire requires a 16-bit timer, and only 1 is available on the ATmegaXX8. You would need to switch to a device with more than one in order to move it. – Ignacio Vazquez-Abrams Jan 12 '14 at 11:13