Pages: [1] 2   Go Down
Author Topic: Cheap External Chip Needed  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Thanks for your help!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12917
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
do a little bit of subtraction

As opposed to what?  A whopping big chunk of subtraction?   smiley-evil

Quote
and then output the values

What sort of values?  Floating-point?  Discrete?  Randomly generated?

Quote
I've looked at the attiny, but that appears to just have the SPI interface

The ATtiny2313 (and family) has a UART.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and then output the values

What sort of values?  Floating-point?  Discrete?  Randomly generated?

Integers. I'm getting pulse lengths to read a RC receiver I had lying around.

Quote
I've looked at the attiny, but that appears to just have the SPI interface

The ATtiny2313 (and family) has a UART.

Huh. The ATtiny13A datasheet had no mention of it, and neither did the 45. The 2313 seems a little large for my application, but I will definitely consider it.[/quote]
« Last Edit: May 15, 2011, 12:45:22 am by WizenedEE » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12917
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm getting pulse lengths to read a RC receiver I had lying around.

What is the price if a pulse is missed?

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?
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm getting pulse lengths to read a RC receiver I had lying around.

What is the price if a pulse is missed?

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12917
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


How accurate do the measurements need to be?
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

<10 us error
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12917
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Shortest pulse expected?  Longest pulse expected?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 127
Posts: 8517
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Using the Arduino is too slow
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.

Quote
I probably did something wrong though,
Yep smiley

If you use 4 pulseIn()s in a row

Code:
pulseIn(1,y);
pulseIn(2,y);
pulseIn(3,y);
pulseIn(4,y);
process_results();

you will get consecutive pulses and there will be the inter-pulse delay between each one so the time taken may be quite long. But if you don't mind missing pulses then

Code:
pulseIn(1,y);
process_results_for_1();
pulseIn(2,y);
process_results_for_2();
pulseIn(3,y);
process_results_for_3();
pulseIn(4,y);
process_results_for_4();

Should have a pretty fast response.

Quote
I found something that might work
168 pages of data sheet, what part exactly might work.
______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Using the Arduino is too slow
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?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 127
Posts: 8517
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 133
Posts: 6755
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It appears that the pulses are indeed offset, so I can use the OR gate.

I might write a playground article on how to read servo pulses, since I don't think it's very well document and really isn't all that hard. I'm working on creating a library to do it also.

Thanks for all the help though!
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SPI is pretty easy to work with on AVRs - you'll have to use slave mode on the Arduino and master on the pulse detector though which might not be compatible with any other use of SPI.

If you can use pin-change interrupt on your Arduino that might be a better solution.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1] 2   Go Up
Jump to: