Simple four channel ~150KHZ signal plot
(c) 2006 by Malte Marwedel
Use this programs under the terms of the GPL version 2. See gpl-license.txt for
more details.

The AVR program reads data from four digitally ports and transmit them via
RS232.
The PC program reads the data a RS232 interface and plots them on the screen.

The protocol format is the following:
Every read byte contains the status of all four input pins (lower 4 Bits) and
a value how often this input states were the same (upper 4 Bits).
Examples:
0xf8 was read: In this case input 1,2 and 3 were low and input 4 is
     high. This was the same for the previous 15 samples.
0x3f was read: All four pins are high and this was the same three times in a
    row.
0x0y was read: If the first part is zero, the data should be ignored,
    regardless what y is.
By transmitting the times all read inputs were equal to the previous read, it
is possible to transmit a higher sample rate than the interface could
do without this simple compression. The disadvantage is that data will get lost
when the input pins change very often, resulting in a transmit after every input
read. There is a FIFO in the transmitter which make short high input switching
rate possible without data loss. But after a while the FIFO get filled and data
will get lost.

Known problems with the PC program:
The drawing of the lines by the PC takes quite some time. More input switches
result in more lines to draw. The PC seems to support only 256 Bytes of FIFO
which were read by the PC program not often enough if there is much to draw.
If the FIFO overflows the received data gets lost of course. Since the used
drawing libray supports graphic hardware acceleration it might be possible that
this problem could be reduced by using a graphic driver which supports hardware
acceleration for your graphic card. But this was currently not tested by me.

Known problems with the AVR program:
None so far

Hardware needed:
An AVR ATMEGA8 or better with a typical serial interface. The read input pins
were PINC 0, PINC 1, PINC 2 and PINC 3. Because of the very high baudrate
(230400baud), you need a crystal optimised for right baudrates. By default I
assume you use a 11.0592 MHZ crystal. If you would like to use a 14.7456 MHZ
crystal you have to correct the UBRRL value in the source. See datasheet how to
calculate this value. The sample rate you get is the crystal frequency divided
by the OCR2 incremented by one.
Example: You have a 11.0592 MHZ crystal and OCR2 is set to 73, then you get a
sample rate of 11059200/(73+1)=149448.6 samples per second.
So by modifying the OCR2 value you could increment or decrement your sampe rate.
With a 18.432MHZ crystal you might get a sample rate up to 250000 samples/sec.
But remember that the PC interface and the PC program are not faster by using a
faster crystal.

How to compile the programs:
In the sample-avr directory run make and then upload the hex file with your
favourite programmer.
There is an already compiled binary for the PC in the plot-pc directory called
a.out. But I suggest you to compile your own binary. Do this by deleting the
a.out file and then type make to compile. The program needs the glut library
for the graphical interface. The glut package names for Ubuntu are freeglut3,
freeglut3-dev and libglut3. Install all three. I guess the package names were
equal or similar on other systems.
Then run ./a.out. By running in a console you will see some useful information.

Testing example:
Connect an TSOP1738 to one of the AVR input pins and watch the signals various
infrared remote controls generate.

Changelog:
2006-03-28 Version 1.00 is out
2006-04-23 Version 1.10 is out:
   * Three times higher sample rate of the AVR, as disadvantage the FIFO on the
     AVR has been reduced down to 256 Byte
   * The PC Application now uses an additional software FIFO and is
     multithreaded which reads the hardware FIFO much more frequently providing
     higher sample rates. As disadvantage the PC CPU is now used permanently by
     100% as long as the PC program is running.

END OF FILE