Purpose of this article is to inform readers about implementations UDP protocol (only transmitting) into singlechip microcontroller, which this interface directly not supports. Simply: implementation UDP/IP on firmware level (similar as emulation of RS232 interface in microcontrollers, which not have RS232 support). Given project is the next follower of my project of basic USB module IgorPlug-USB (AVR) (computer remote control IgorPlug with USB).
At present time many small devices can communicate through
computer networks. This devices are used mainly in office technology: printers,
scanners, copiers. But in the industry are also many useful devices for
processing controlling and monitoring: thermometers, alarms, cameras, ... . In
case of some event can this devices send through Ethernet networks some
notification to controller system. For example: empty paper tray in printer,
temperature is too high in server room, somebody is inside the secure room. Then
the user can control/monitor the devices also through computer network: switch
on the backup fans, restart server, (or manually fill the paper tray in
printer). Very good products you can also find on http://www.hw-group.com,
where is focus on industrial ethernet products.
The trend is that some home appliances have network interface (DVD
players, fridges, microwave oven, washing machines, set top boxes ...). The
result is that the computer networks is more and more used in houses and not
only for computer to computer connection but for computer to home/industrial
devices also.
Therefore I also try to construct very very simple and cheap device,
which works as remote control of computer. This device is connected directly to
twisted pair 10/100 BASE TX network. It receives signal from standard infrared
remote control (used for TV, DVD players, ... ) and send it to group of
computers on the network. Therefore signal can be collected by more computers
also. Received signal is then decoded by given computer and in the next is
performed associated action (for example increase volume on PC).
My solution offer very simple and cheap hardware.
All intelligence is in firmware. Construction is designed as infrared
remote control of computer through Ehhernet (successor of construction
for serial
port and for USB port).
This device allow:
Principle of operation:
Firstly see the schematic above.
Device receives infrared code from the sensor and stores it to internal
buffer as array of duration of every ones and zeros. Time base for time
measurements is XTALL/1024 = 19531.25 Hz (time step is 51.2us). Each infrared
code bit duration has limitation of max. 12.8ms, which fits into one byte
storage: 12.8ms < 255*51.2us. After no signal change observed during 12.8ms
then the receiving is finished. Then is received infrared code stored as
oscilograph to the internal buffer .
If some code receiving is finished, then device sends content of internal
buffer to Ethernet network. Buffer is transmitted by UDP/IP protocol as
broadcast to specified network. Default destination firmware values are:
but can be easily changed (see the firmware files).
Limitation of this simple design is, that the microcontroler speed is
"only" 20MHz and 10 Mbit twisted pair network has max. frequency
10MHz. But 10MHz means that signal changes every 50ns (in half of period also).
Therefore for transmitting 10MHz we need 20MHz = 1/50ns microcontroller
performance.
Above limitations give us next transmit rules. Each byte in the buffer is
transmitted in one UDP packet. And each bit in this byte is in the UDP packet
coded in one byte (+ 4 additional bytes for ethernet CRC32 correction). The
result is that each byte in buffer is transmitted in UDP packet containing 44
bytes. And the number of UDP packets is equal to number of bytes in internal
buffer.
Example for RC5 code (which you can see on the picture below):
- number of bits = 23 (zeroes and ones together)
- bytes in internal buffer = 26 (because 3 additional bytes is buffer
header)
- number of transmitted UDP packets = 27 (because 1 additional termination
packet)
- number of bytes in one UDP packet = 44 , because each bit is in 5 bytes
(1byte + 4bytes CRC32 correction) + finally 4 bytes of CRC32 correction
Device supports only transmitting, because receiving is not possible at this microcontroller speed. Therefore we must use device on full duplex networks only! Otherwise is probability that on network occurs collisions during device transmitting and because device not checks collisions (not receiving), then the transmitted code is not delivered to destination. Full duplex networks are for example direct connection to computer network card through crossover cable. In the future I want to test the device on complex network with network switch and more active computers connected - if you have access to some network give me please your test result ;-) .
I develop for programmers DLL library "IgorUDP.dll", which offers access to the device from your programs in the simple way. It contains only 3 functions: InitUDP, CloseUDP and DoGetInfraCode. See the source codes for detailed interface of this DLL library. Library is written in Delphi.
Interface for Delphi users:
function InitUDP(DestinationAddress:PChar; ListeningPort:PChar):integer; stdcall;
function DoGetInfraCode(var TimeCodeDiagram:array of byte; var DiagramLength:integer):integer; stdcall;
function CloseUDP:integer; stdcall export;
Interface for C++ users:
int __stdcall InitUDP(char * DestinationAddress, char * ListeningPort);
int __stdcall DoGetInfraCode(char * TimeCodeDiagram, int DummyInt, int *
DiagramLength);
int __stdcall CloseUDP;
In the next I have developed testing application "IgorUDPBdemo.exe" which uses DLL library and shows how to build own application. In the next picture is screenshot from this application. Application only checks if some code was received from device, and if received some then displays it to the screen in real time. Application is written in Delphi.
I implement this receiver also to final product - plugin for Girder. Then you can fully control your PC through computer network also.
And here is testing application "IgorUDPBdemo.exe" (infrared code receiving from remote control):
On the following picture is Project structure (source codes, firmware, binaries, documentation, ...) :
and full project is available as Zip archive (cca 800kB) for DOWNLOAD. There are all source codes inside !!!
www.cesko.host.sk - Hardware section
http://www.cesko.host.sk/IgorPlugUSB/IgorPlug-USB (AVR)_eng.htm - baseline
project of simple USB device
www.cesko.host.sk/girderplugin.htm -
infrared remote control of computer
and others: ...
This webpage will be continuously updated - new information (about which you are interested). Last update: 06.11.2004.
author: Ing. Igor Češko:
e-mail: cesko@internet.sk
homepage:
www.cesko.host.sk