I recently implemented a logic analyzer compatible with the SUMP protocol. It was designed for a 16MHz Arduino with the ATmega328p. It might work fine on the ATmega168 but I haven't tested it. I'm using a Duemilanove. You will have to disable auto reset to make this work. See this topic: http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
The loops that do the sampling have been hand tuned to fairly precise timing using an Open Bench Logic Sniffer to measure the cycles. You absolutely need a 16MHz clock for accurate data. I haven't looked at making a version for other clock speeds but you can file a request at GitHub.
I'm very interested to hear from you if you try it on your hardware and find it useful or have trouble. I have done limited testing of multiple channels as well as basic triggering. If something doesn't work I would appreciate some feedback.
Get the code here: http://github.com/gillham/logic_analyzer
Here's my initial README:
SUMP compatible logic analyzer for Arduino
This Arduino sketch implements a SUMP protocol compatible with the standard SUMP client as well as the alternative client from here: http://www.lxtreme.nl/ols/
This SUMP protocol compatible logic analyzer for the Arduino board supports 5 channels consisting of digital pins 8-12, which are the first 5 bits (0-4) of PORTB. Arduino pin 13 / bit 5 is the Arduino LED, bits 6 & 7 are the crystal oscillator pins. Uncomment CHAN5 below if you want to use the LED pin as an input and have 6 channels.
NOTE: You must DISABLE the Arduino auto reset feature to use this logic analyzer code. There are various methods to do this, some boards have a jumper, others require you to cut a trace. You may also install a precisely 120 Ohm resistor between the reset & 5V piins. Make sure it is really 120 Ohm or you may damage your board.
To use this with the original or alternative SUMP clients, use these settings:
Sampling rate: 1MHz (or lower) Channel Groups: 0 (zero) only Recording Size: 512 (or lower) Noise Filter: doesn't matter RLE: disabled (unchecked)
Triggering is still a work in progress, but generally works for samples below 1MHz. 1MHz works for a basic busy wait trigger that doesn't store until after the trigger fires. Please try it out and report back.