AVR Capacitive Sensing -- Lowest Part-Count?

First and foremost -- I will not be using Arduino (Wiring) code for this project. This is my first foray into ASM/C on AVR. This means that the Arduino libraries I mention below will not actually be used in this project. I'm focussing on the hardware first, and the code will follow.

Second and possibly most important -- I have examined plenty of possibilities for capacitive touch sensing, but I want to accomplish it with the minimum in external components and expense. I want most of the heavy lifting being done by the AVR. This means no QTouch chips or anything of the sort. I am making this project on the lowest budget possible, since it's purely for education and entertainment, and it's kinda difficult to fit SOIC chips on veroboard/stripboard without an adapter.

That said, my quandary follows.

I have been examining many capacitive-touch USB-HID interface options out there. I would like to have at least 8 capacitive inputs, while maintaining the following qualities: - minimum calibration required (I don't want to have to manually recalibrate every time I plug it in -- an auto-calibration-on-boot routine is acceptable if necessary and if possible) - minimum external components relied on (no QT chips or other ICs, just an AVR and maybe a few resistors or capacitors -- ideally only one pin is used per capacitive "button")

I have looked at the following examples: - http://www.artemlive.com/cgi-bin/news?c=v&id=749 -- this project is pretty nice, but it only provides 6 inputs, and uses 12 pins to do it. Not elegant enough. - http://www.arduino.cc/playground/Code/CapacitiveSensor -- I have used this library before. I quite liked it, though I never tried to expand beyond the 6 PORTB pins it uses. Is it possible to get more than 6 inputs out of this approach? - http://www.arduino.cc/playground/Main/CapSense -- I like the way this sounds. One send pin, and an unspecified number of receive pins. Is there a limit? The documentation doesn't explicitly mention the maximum number of inputs that can be configured in this way, nor if two or more can be sensed simultaneously. What is the maximum number of inputs I can achieve using this method? Can those inputs be pressed and sensed simultaneously? - http://simon.derr.free.fr/site/spip/spip.php?article5 -- This is a perfect example of what I'm looking for...except it uses a PIC and I have lost my PIC programmer. 10 inputs, and the only extraneous equipment needed are two resistor networks. I even already have this one soldered together on some veroboard awaiting the day that I find my PIC programmer or cave and purchase a new one...but then I need to learn PIC programming. :P - http://sheepdogguides.com/arduino/art3capsen.htm -- This is another similarly elegant example. The schematic is reminiscent of the PIC project in its simplicity, and the only issue is that it stops at 8 inputs. Can this approach support more than 8 inputs?

If anyone can provide any decent advice or pointers to good resources on this kind of stuff, I wold be very apreciative.

Thank you.

Man, I almost got pushed off the bottom of the second page, and all in one day. :(

I'll take the hint if it happens a second time, but for now, I'm going to bump my own topic.

will not be using Arduino (Wiring) code for this project

Think that might be anything to do with a lack of response on an arduino forum?

You can't devorce the hardware from what you are trying to do. The reason why many of those examples stop at six sensors is that there are only six analogue inputs. So you either use the same technique on a processor with more or you put on an external multiplexer.

That’s exactly the kind of stuff I need to hear. Obviously I missed making that mental connection when looking at the 168/328 datasheet.

I’m not worried about the coding aspect, I’m worried about the hardware limitations, and how I can get around them; perhaps I should have stated that plainly in my first post. I guess relying on an external analog multiplexer defeats the purpose of my attempt to stick with just the AVR…maybe I’ll look at some QTouch chips and see about getting DIP adapters for them. Like this one: http://www.atmel.com/dyn/products/product_card.asp?part_id=4908&category_id=170&family_id=697&subfamily_id=2027.

Thank you, Grumpy_Mike. What about the other methods? http://www.arduino.cc/playground/Main/CapSense seems like it’s designed to overcome the hardware limitations you mentioned. Is that correct, or am I jumping to conclusions? Anything that saves me input pins and external hardware is worth looking at.

The reason I posted this question here, in these forums, is that I posted a similar question to AVR Freaks, and they have been plenty helpful about the AVR itself and how to program it, etc. but they haven’t answered any of my questions about the capacitive sensing part, other than pointing me to QTouch and TouchSemi devices.

The dedicated chips are much better than the sort of job you can do with a couple of processor pins, so I would consider those.

But I enjoy reinventing the wheel... :(

Thanks. I'll go find some SOIC/DIP adapters.

Dash_Merc: they haven't answered any of my questions about the capacitive sensing part, other than pointing me to QTouch and TouchSemi devices.

Your question and application are interesting, but I don't think too many people here have much experience with capactive sensing... so you'll probably have the same experience.

Dash_Merc: But I enjoy reinventing the wheel... :(

Thanks. I'll go find some SOIC/DIP adapters.

In that case, you can always make your own adapters... ;)

I guess that leaves an opening in the community for a capacitive sensing application expert.

Maybe I'll show up and claim that title someday, if this QTouch documentation doesn't kill me first. :P

Good. You be the expert then I'll ask you questions. I'd like to incorporate cap-sensing into a project I'm working on... ;)

Well, so far the QTouch documentation I have found is not very clear or helpful. In different places on Atmel's website, they claim specific chips support a varying number of QT inputs. The same chip will be listed with a different number of QTouch inputs on different pages and in different documents.

Beyond that, simple software implementation of capacitive sensing is apparently limited to ADC pins, because they need to be able to detect an analog signal and calculate a "touch" based on comparing the time it takes to discharge a capacitor across a contact to a calibrated threshold value. This makes the ATmega328 a very poor contender when compared to chips such as the ATtiny40 (many many more ADC) or the PIC 18F2455 (10 ADC and hardware USB). The ATmega 48/88/168/328 has 8 ADC pins, but on the PDIP version of the chip, only 6 are broken out to actual pins; the other two are just...missing. This means that without the help of external chips (which, as far as I've been able to surmise, are only available in surface-mount varieties -- no matter the vendor), the ATmega will never be able to sense more than 6 capacitive inputs without serious software hackery to multiplex those inputs (perhaps a 3x3 matrix using the 6 pins?) or using a more complex combination of discrete components to make up for this "shortcoming." Now I understand why PICs are so popular with hobbyists, despite the lack of simple/free tools to work with them -- the chips with nice features still come in PDIP packages.

Anyway, it seems I need to either rely on an external chip, or I'll have to go with some other MCU. That sucks, but oh well. Either way, I'll be delving into surface-mount territory -- unless I decide to go with another vendor's offerings for the core MCU (BLASPHEMY!).

You only need two IO pin to make a capacitive sensor. One to charge the sensor and another over the measure the time it takes to charge. Since you are relying on an IO changing its state you will be detecting the time it takes for the PIN to transit from a logical 0 to a logical 1. To improve reliability and sensitivity you can use a differential measurement, i.e. measure the time it takes to charge and discharge. Finally, you can also invert the use you make of the two pins, by changing it's functionality. Where one of the pins was the IO charging it can change todo the sensing and viceversa. All done by your SW. So you can have as many cap sensors as IO pins in the MCU.

The only thing you will find you need to do is to carter for changes on ambient conditions: temperature and humidity Calibration, tracking of ambient changes and a bit of filtering come to the rescue. All this done by SW.

Cypress are big in touch sensors, they made the one used in some of the iPods http://www.cypress.com/?id=1575&source=header

They have a processor with built in capacitive sensor inputs the PSoc http://www.cypress.com/?id=1353 This is a good system I have used it, that is I have played with the demos I haven't actually incorporated it into any project I have done.