I have a problem that’s been driving me nuts for weeks. I can’t figure it out.
I am building an R/C transmitter for model planes. I’m using a Nano as the encoder board, doing analog reads of the stick inputs and converting to a PPM stream to be fed to an RF module to transmit to the receiver (It’s an FrSky hack module for those interested.)
My problem is this. I’ve been using Xoscope to look at the PPM output signal from the Nano. I can display it when the Nano is plugged into the computer by USB cable (and is therefore powered by the USB), or I can unplug the USB and power the Nano from a battery, and still display the signal on Xoscope. I am using my sound card to communicate to Xoscope, and I have found that, when using the battery, I have to connect one side of the input (microphone) to pin10 of the Nano, and the other side to Nano ground. Not entirely sure that’s kosher but it seems to work. I don’t need the ground connection when the USB is plugged in, presumably because there is a ground connection via the USB cable.
The problem is this. When the Nano is plugged into the PC via the USB cable, it works perfectly. In the screen shot it can be seen that all the pulses (eight of them) are present and correct. However, when I unplug from the USB and connect the battery it’s a different story. Now the first three channels (the only ones with analog reads in my test program) produce pulses that are way too wide, about 5,000us. The other five, which are hard coded to 1500us (it’s 3000 in the code as the size must be doubled for the PPM generator timer) are spot on.
If I hard code the values to 3000 for the first three channels as well, they are also correct. It’s only a problem when I read an analog input and map it to my output values.
I ran another test as well to write the values from the first three channels to EEPROM, conditional on a switch setting. So when I plugged it into the battery I had the switch on and the values were written to EEPROM. I then unplugged it, turned the switch off, then plugged in the USB and read the values from EEPROM. The values are correct. This was the only way I could think of (given that serial monitor was not available without the USB plugged in) to see what values were being generated by the analogRead and map functions while it was running on battery.
So, why does it work when connected to the USB but not the battery? Do I have to add some resistors or capacitors or something? Do I need to feed 5v to aref? Does the board behave differently when powered from a battery instead of the USB? Mine certainly seems to…
It also doesn’t work when I hook up the PPM output to my RF module and switch on my receiver. The servos move slightly, but don’t respond to stick input. I thought it might be some weirdness with Xoscope, but the fact that the servos don’t respond to stick input would seem to indicate a problem elsewhere.
I’ve attached a copy of my testing program which does basically nothing except read the first three adcs (aileron, elevator and rudder on my transmitter) and feed them to the PPM generator.
I’ve also attached a couple of screenshots of the Xoscope output. Battery.png shows what it looks like when running on the battery. USB.png is with the USB plugged in (and what it should look like).
The others are a couple of shots of my transmitter, for no particulare reason. The battery pack is an eight cell NiMh pack (Sanyo Eneloops, excellent quality and show 10v on my multimeter), the FrSky hack module you can just see stuck to the right hand side witih double sided tape. The gaggle of wires on the circuit board connect all the adcs to the pots in the box. The yellow wire is on pin 10 and is the PPM output. The pcb switches will one day be reversing switches to reverse the channel direction. The round black thing on the left is a momentary button, that can be held down on power up to do various rare functions, like stick calibration or whatever else I think of.
All advice gratefully received,
PPMtesting.ino (2.54 KB)