RF data and PWM

Hello all!

Has anyone ever met problems receiving data via RF links while doing an analogWrite()?

I'm using a pair of RF transmitter and receiver very smiliar to this: http://www.sparkfun.com/commerce/product_info.php?products_id=7813

I tried both codes by yerg2K and anaidioschrono in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199058664/0 and both methods work like magic, until I add an analogWrite() in setup() to light up some leds.

I found if there is a PWM output, the RF preamble signal (the long HIGH pulse for sync in the case of anaidioschrono's code) recevied by the receiver was cut into short pulses when I check with an oscilloscope. (The receiver is connected to pin 2 and the transmitter to pin 4, and I am using pin 5, 6 and 9 for PWM output.)

Any idea what's going wrong?

Thanks for helping!

Sorry forgot to say, the PWM is used on the receiver side. Thanks!

Did you use the latest code in that thread (the library)?

Regardless, in the receive code I wrote, the function monitors for 5 seconds for valid data, so the analogWrite in your code shouldn't occur while attempting to receive.

I'll have to take a look at how analogWrite works and how it could possibly interfere with timing. That may be where the problem is. If I get time I'll put an analogWrite in my sketch that utilizes the receive code, and see if I can't reproduce the problem.

Yes I used the latest code. Actually I followed the example coming with the library, only added an analogWrite in setup(), so the analogWrite is executed before the receive function.

Hi, I tried adding an analogWrite to the setup() routine of my sketches using RFRecv. I was unable to reproduce the problem. Are you sure it is the analogRead causing the problem? Have you tried removing the line and testing it again?

Hello!

I think I found the cause for this problem. Pin 5 and 6 use Timer0 for PWM and it will affect the system time hence all the time-related functions (millis(), delay(), pulsein()…). Therefore the pulse length of RF signals can’t be read correctly. At least when I didn’t use analogWrite on pin 5 and 6, the receiver seems to function properly again! yerg2k, which pin did you use for PWM when you tried?

But still don’t know why the RF signal looks fragmented on the oscilloscope.

Hmm...after multiple tests it seems my theory is not totally true. Still can't receive RF properly even only use pin 9 for PWM. Though it does receive fine when there is no PWM. Any thought?

Thanks!

I used pin 11 for PWM. The only line added to the RFRecvEx sketch was analogWrite(11, 123); at the end of setup(). HTH