rflinkbetweenavrs

RF Link Between AVRs

DIY RC system.

this doc is Unfinished.

i will rectify that at some point in the future.

no promises as to when.

A cheaper way to do this is documented here: Interfacing CYRF6936 to AVR

Why do this?

I decided i wanted to build a radio controlled aircraft with the ultimate goal of turning it into an autonomous aerial platform or UAV (Unmanned Aerial Vehicle).

Rather than use off the shelf R/C equipment i decided it would be better to build the R/C equipment myself so it will be relatively easy to add sensors and logic later to enable autonomous operation.

The setup.

I will be using an ATmeg8 AVR microcontroller in the transmitter and another in the receiver.

At the transmitter end i am using a Sony PS2 controller as an input device as it is an ergenomically sound input device with lots of spare functionality. (2 x 2 axis analogue sticks and lots of spare digital inputs.)

The interfacing of an ATmega8 microcontroller to a PSX controller is described in my article here: PS2 Controller on an AVR.

Information is passed between the AVRs using off the shelf radio modules connected to the microcontroller UARTs. This allows simplex communication (ie. in one direction. Transmitter to receiver.)

The AVR microcontroller on the receiver receives information from the radio module on it's UART and translates that information into PWM signals suitable for driving R/C servos and motor controllers.

The servos and motor controllers are the only bits of "off the shelf" radio control equipment i have used in this project.

*** insert block diagram here ***

Hardware.

The transmitter side of this project is exactly the same hardware as i used in my PS2 Controller on an AVR project. An ATmega8 connected to a PS2 controller and a RF TX module.

There is also a voltage regulator on the TX board so you can choose to either supply 5V bypassing the regulator or anything up to 30V through the regulator.

*** insert schematic here***

The receiver is also based round an ATmega8 with the RF RX module connected to it's UART and servos connected to I/O pins.

Again there is a voltage regulator so you can choose to either supply 5V bypassing the regulator or anything up to 30V through the regulator.

*** insert schematic here***

Problems with the RF modules.

I only ran into two unanticipated problems while building this project.

One of them was related to the operation of the RF modules.

The modules i am using are relatively high power (a range of 1 mile according to the Datasheet) which means the manufacturer has had to optimise them to fit with in the various countries radio transmission regulations.

One of the things that I eventually found out is that most RF modules like this are optimised for sending an equal number of "1"s and "0"s. This way the peak radio power level is always the same. Ie, there is no difference in the power output no matter what the data transmitted is.

This had the unfortunate effect for me (who does not really care about the RF regs) that when i just connected the RF modules to my microcontroller UARTs i was only sucsessful when sending bytes that change between "1" and "0" oftain. For example I could send 01101001 fine but i would get errors if i tried to send something like 01111111 or 00010000.

How is this supposed to be done? The most common technique for balancing radio transmissions is Manchester Encoding. In brief this means a "0" will be transmitted as a "01" and a "1" will be transmitted as a "10" so there are always an equal number of "1"s and "0"s in any transmitted byte.

Obviously this halves the speed you can transmit and receive data at but in exchange you get some crude error checking built into the signal.

So I had no real interest in bit-banging my serial communications. I wanted to use the hardware UART so i did not have to worry about the precise timing of the serial comms running in parallel with the servo PWM. At the same time the hardware UARTs send start and stop bits that do not conform to Manchester Encoding.

As it turns out, as long as i split my data byte into 2 x 4 bit nibbles, manchester encode those and sent them out of the microcontroller's hardware UART the transmission works OK. The RF modules are forgiving enough to not worry about Manchester encoding the UART start and stop bits. So that's what i'm doing. The function fakeMacheter performs the splitting and encoding described.

Problems with RF interference.

So this issue was obvious in retrospect. My radio transmissions were working perfectly until i plugged in the servos. I spent a long time convinced it was back EMF from the servos causing interference the radio modules.

In the end it was just my battery pack was too old and not capable of supplying enough current.

It turns out the RF modules are far more sensitive to brownout than any of the other component's i'm used to dealing with.

The firmware.

Functionality:

    • Up to 4 analogue channels and 16 digital outputs could be provided for with simple firmware modification.
    • Pesudo manchester encoding catches all single bit errors.
    • Multi bit errors are 85% likely to be caught as well.
    • Warning LED indicator on error rate threshold reached.
    • Adjust servo trim via button press. Trim positions saved to EEPROM.
    • Double sensitivity of analogue controls by button press.

Appart from the 2 issues with manchester encoding and the RX module brown outs discussed above writing the firmware was quite straight forward.

The pesudo manchester encoding provides some level of error detection. Errors are counted and if a certain threshold is reached the status LED goes off. (Will add functionality to center servos and shut down motor on signal failure later.)

The transmitter unit firmware can be modified to send as many control packets as you like.

Packets should take the form: [start byte][channel number][data][stop byte].

I can't think of any reason why you would need more different channels than there are output registers on the PS2 controller but maybe you intend to use a different input method...

*** insert section on servo mixing***

mrdunk(at)gmail.com