Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 08, 2016, 07:09:30 19:09


Login with username, password and session length


Pages: [1]
Print
Author Topic: CVD Touch sense - Microchip AN1298 implementation  (Read 4374 times)
0 Members and 1 Guest are viewing this topic.
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« on: June 11, 2012, 06:12:06 06:12 »

Hi,

Attached is the c code implementation of microchip AN1298 - Capacitive Touch Using Only an ADC (“CVD”).

3 Button pwm dimmer using PIC12F675, I just try to make the Proteus simulation but doesn't work - it is works on the real hardware.

I invite peoples to try and discuss about it, in the meantime i will try to find my real board and make some pictures or even video of it.

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #1 on: June 11, 2012, 09:07:47 09:07 »

Hi Ichan,

Code:
switch(index) {
case 0: TRISIO0 = 0;  GPIO0 = 0;  TRISIO0 = 1;  ADCON0 = 0b10000001;  break; // AN0
case 1: TRISIO1 = 0;  GPIO1 = 0;  TRISIO1 = 1;  ADCON0 = 0b10000101;  break; // AN1
case 2: TRISIO2 = 0;  GPIO2 = 0;  TRISIO2 = 1;  ADCON0 = 0b10001001;  break; // AN2
default: break;
}

Explain this sequence to me please: TRISIO0 = 0;  GPIO0 = 0;  TRISIO0 = 1. Why did you started by making the pin output? Is it some way to make sure you discharged the capacitor plate in real HW? Or just for the sake of experimenting with Proteus, because you used a 10pF capacitor instead of the plate? Should I then leave it as is when implemented on real HW?

Could you please give me a quick description for this snippet, it will be easier for me to follow the code:
Code:
adc[index] = ((ADRESH << 8 ) + ADRESL);
adc[index] = adc[index]*16;

TRISIO = 0b11000000;
GPIO  &= 0b11100000;

if (warmup > 0) {warmup--; avg[index] = adc[index];}

if (adc[index] < (avg[index] - (avg[index] >> 6))) {
if (dbc[index] == DBCMAX) {
button = index; result = 1;
} else if (dbc[index] < DBCMAX) dbc[index]++;
} else if (adc[index] > (avg[index] - (avg[index] >> 8))) {
if (dbc[index] == 0) {
button = 0xFF; result = 0;
} else if (dbc[index] > 0) dbc[index]--;
}
if (result == 0) {
avgindex++;
if (avgindex == AVGDELAY) {
avg[index] = avg[index] + (int)(adc[index] - avg[index])/16;
avgindex = 0;
}
}

if (++index >= BUTTONS) index = 0;
Logged

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #2 on: June 17, 2012, 05:34:32 05:34 »

Hi Metal, sorry for a late answer - i am very busy lately.

The code originally from microchip, i do not remember where i found it, perhaps inside microchip solution library. What I did is simplifying it and took only the part that i need.

As explained on the AN, the sensing sequence is:

- charge the c-hold cap to VDD, this done by GP3 digital output driving the AN3 high.
- ground the sensor channel, set the sensor channel as digital output and drive it low.
- prepare to read sensor channel, set it as input and switch adc mux to it.
- read the 10 bit adc

Without any (theoretical) external capacitance on sensor channel the ADC will read a VDD analog value which is hold by the charged c-cold cap. Touching the sensor channel (capacitively) will give another capacitance in parallel to the c-hold cap creating a voltage divider between the two - mean the adc will read lower analog input when the sensor channel capacitively touched.

The 10pf cap on proteus meant simulate the external cap similar with the touch of the sensor line.

I will add comments on the code later, but for now a short explanation:

- for each channel we keep average value of the adc reading for later comparison
- the adc value is scaled up by 16 (left shifted << 4) for efficient averaging
- if the adc reading of a channel is below a threshold of averaged value then we will "assume" that the sensor channel is "maybe" being touched.
- needs a continously DBCMAX times of above assumption to make a final decision that the sensor channel is really touched.

Well, not a good explanation I guess..

-ichan
Logged

There is Gray, not only Black or White.
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #3 on: June 19, 2012, 03:30:32 15:30 »

I've been out "shopping" and noticed that Circuit Cellar 5/12 has an article (cover says so...haven't looked yet) on cap touch sensors. http://www.sonsivri.to/forum/index.php?topic=2027.msg131459#msg131459
Logged
localcrack
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 62
-Receive: 20



« Reply #4 on: October 02, 2014, 09:26:09 09:26 »

I find following link, they have simulated capacitive touch in proteus. Great video demo

http://www.codeforfun.it/2013/09/05/touch-sensor/
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC