The radio transmitter circuit is based upon the one featured in EPE magazine. (Mains Monitor page 35, August 2008), which uses an RF Solutions 433Mhz TX/RX pair. The transmitter sends data to an handheld device, which displays the data on an LCD, or if connected to a PC, displays the data in a VB program, or on hyperterminal via a serial cable.
Initially the Usart TX from the ultrasound PIC(16F690), was connected to Usart RX input on the MAIN PIC. But I didn't like the idea of the main code been constantly interrupted by data from the ultrasound PIC. So I decided to send the data separately. The tricky part was sending messages from 2 pics(the MAIN PIC16F877 and the pic that controls the SRF02 ultrasound sensor, a PIC16F690) that couldn't interfere with each other. So I added an AND gate(74HCT08) and 2 diodes(1N4148).
There are 3 wires from the MAIN PIC to the AND gate.
- Pin1: Enable/disable this gate from MAIN PIC.
- Pin2: Usart TX from MAIN PIC.
- Pin4: Enable/disable Usart TX from ultrasound PIC, from MAIN PIC.
- Pin5: Usart TX Data from ultrasound PIC.
So if the MAIN PIC wants to send data, it first checks that the ultrasound PIC is not sending data via a connection from the ultrasound PIC. If it isn't, it sets its connection HIGH to the ultrasound PIC to indicate it is sending data, and also disables ultrasound PIC's AND gate. When it is not sending data it sets the connection LOW to the ultrasound PIC and it enables the AND gate to allow ultrasound PIC to send data.
When the ultrasound PIC is sending data, it first checks that the MAIN PIC is not sending data,
then it sets its connection to the MAIN PIC HIGH to indicate that it is sending data.
This stops both devices sending data at the same time.
Each output of the AND gates has a diode attached, then both diodes are connected to radio TX input(pin 3)
via a switch. The SPDT switch allows the data to be sent back to the radio TX board, or sent through a
direct connection to handheld device.
The MAIN PIC sends data for the top line of the LCD.
The ultrasound PIC sends data for the bottom line of the LCD.
I know all this seems a bit complicated, but I can't think of another way of doing it, and it does work!
The direct connection from the robot to the handheld display is very useful for testing purposes. When I first built these circuits on 2 plugboards, they worked fine. Several days latter, I was testing them again, but all I got was a load of garbage on the LCD. So was it the sending PIC's that where wrong, or the receiving PIC for the LCD? So I dismantled the circuits, reassembled them, still garbage. So I reset all the baud rate settings to a lower rate, still garbage, double checked the circuits again, or was it a problem with the RX/TX devices? So I connected a direct line to the display, still garbage. I couldn't understand why it work OK and now it doesn't. I must have spent several days trying to get it to work again, then as a last resort, I changed the battery on the LCD display, and it all worked. So in future if something stops working for no reason, I always check the battery first!!
While in the process of building and testing a new HHD for receiving data from this circuit and passing to my PC via USB, I found that the direct cable doesn't work. I think that, because the RF worked so well, I may have never tested the direct cable.
I am not sure why it doesn't work, maybe there is not enough current or voltage coming out of the AND gate, so where as the output from the AND gate goes through a transistor before going to the RF TX pin, the cable does not. So now I have modified the circuit so the output from the AND gate goes through the transistor, then to the switch and back to the RF TX pin or the direct cable. This does now work alot better. The full test will be when I have finished the HHD.