Hello,I'm looking for a microcontroller (preferably an AVR, since I know how to work with them) that will let me read four digital inputs extremely quickly (ideally read each one within a few microseconds or, even better, have four external interrupts), do a little bit of subtraction, and then output the values to my Arduino for further processing (it would only need to output about every 10-20ms).

I've looked at the attiny, but that appears to just have the SPI interface. Is that easy to work with on both ends?Is there another microcontroller that has the easy-to-use USART interface? Is there another type of communication that doesn't use many pins and is well-supported?

In your post you mention "cheap" and "four digital inputs". Why not just use four pins on your Arduino and use pulseIn to read the pulses?

Don't care that much if a pulse is missed. Using the Arduino is too slow -- when I tried, it upped my looptime from 1-2ms to 70ms. I probably did something wrong though, since I set the timeout to be 20ms and I was reading two pulses..

I found something that might work:http://ww1.microchip.com/downloads/en/DeviceDoc/40044b.pdf

The Arduino is just an AVR like most others. If you can do it with a tiny13 you can certainly do it with a mega328.

The Mega328 is already doing lots of things - I basically want a dual-core.

Quote

Quote

I found something that might work

168 pages of data sheet, what part exactly might work.

The PIC 16F628A

As for the pulseins, what do you mean by an inter-pulse delay? What's happening is that I have a timeout of 20000 us on the pulsein, use two of them, and I end up with a loop that's 70ms slower. The worst that should happen is to be 40ms slower, if it never receives a pulse. Does the command take a while to initialize or something?

pulseIns() waits for an edge then times to the next edge. So it could wait for quite a long time. If you do 4 in a row each one may wait for a long time so in total the procedure takes a very long time.

A lot depends on the nature of your pulses, if they all start at the same time but have varying lengths and a 10mS period each pulseIn() reading could take 10mS worst case. If the pulses are not synchronised you can't determine how long things will take.

How long are these pulses?What is the period of them?Are they synchronized or independent?

If you really need to offload this job I don't see why a tiny85 couldn't do it, use SPI to return the data. The 85 interrupts the Arduino when data is ready. The Arduino does N SPI.transfer()s to get the data. Clock the 85 using the clock output pin from the Arduino (PB0 or DIG8) so you have accurate timing.

Have you scoped the four lines to see if they start simultaneously? If they do, you can hook them all up to to a single hardware interrupt pin (via diodes), and just count the cycles until the pulse ends for each one - the maximum time taken in this case is equal to the maximum pulse length (should be <= 2ms).

Alternatively, you could write some code in the PCINT ISRs - they trigger on every pin, so you'd need to read which pin is being triggered, but it's simple enough to record the micros() when the pulse changes low -> high (beginning of pulse) and again when it changes high -> low (end of pulse). Subtraction will give you the pulse length. This method is used on one of the quadcopter platforms (I forget which one), so it's quite reliable.

Also, if the pulses trigger sequentially, stagger them - pulseIn 1, 3, 2, and then 4 - you will reduce the time spent waiting for the next pulse to start that way.

You could use another ATmega8, 168, or 328 (just like an Arduino chip.) That way you would be REALLY familiar with it.Bare 328s are less than $5, and I've seen mega8s for about $2. Usually it doesn't make a lot of sense to hunt for cheaper than that unless you're planning on making tens of thousands of units or something.