View previous topic :: View next topic |
Author |
Message |
ran2rg
Joined: 02 Aug 2011 Posts: 6
|
Measure touch sensor according to Microchip |
Posted: Tue Aug 02, 2011 9:34 am |
|
|
Hi
I am trying to implement a touch sensor according to a Microchip document attached here.
I need to output 1 at a certain pin and then "direct" the ADC channel to that pin so the internal capacitor Chold will be charged.
I can't understand how can I do that.
It seems that I need to "direct" (sample) the adc to that port in order to charge its internal capacitor.
So adc is sample its port to get "1" ?
If I output 1 in a port and then set it to be adc and sample that port, will I get 1 ??
How can I do that ??
Can someone direct me on how to do that ?
The article :
http://ww1.microchip.com/downloads/en/AppNotes/01298A.pdf
I am using pic16f690.
Thanks a lot. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ran2rg
Joined: 02 Aug 2011 Posts: 6
|
thanks |
Posted: Tue Aug 02, 2011 1:54 pm |
|
|
Thanks a lot.
How can I translate to CCS the cmtouch.c file??
I couldn't understand it so I have to convert it.
ALSO what are the rest of the files there such as main.c ?
Why is it so big ? It should be done in 10 rows of code as I understand.
How would I convert that and what should I convert from it ?
Thanks a lot. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Aug 02, 2011 2:24 pm |
|
|
You'll have to read, read and re-read the code that PCM programmer found for you. It is well commented.Also read the CCS help files/ onscreen info as well.
Most here do not have the time or desire to translate the code for you but will help after you try and show us your code.
The best way to actually learn is by doing it yourself.Yes, it may take you a few hours ,days or weeks..Heck I've got over 25 years using PICs and I'm still learning,every day !! |
|
|
ran2rg
Joined: 02 Aug 2011 Posts: 6
|
another thing |
Posted: Tue Aug 02, 2011 2:33 pm |
|
|
How can i charge the capacitor Chold with outputing 1 in a pin ?
Does this pin connected hardware to the ADC CAPACITOR ?
Or they connected in software ?
Anyone has a ccs c example?
It should be simple. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Aug 02, 2011 5:55 pm |
|
|
If it was simple you'ld have cut the driver code and posted it by now.
Really, you have to READ the manuals, datasheets, etc., cut code, try it, learn from doing !!
There are examples all over the net and you've been shown one of the better examples ( it does work...)
I rather doubt anyone here will just cut the driver for you, or convert the Microchip C code into CCS C code. Frankly, that kind of work is what I used to get paid to do (now it's just a mindgame).
That being said, if you supply 6 complete systems, and a detailed explanation of what you expect, I might take on the challenge. |
|
|
ran2rg
Joined: 02 Aug 2011 Posts: 6
|
temptronic |
Posted: Wed Aug 03, 2011 1:32 am |
|
|
Please relax. Don't take it too seriously, I have just asked question.
I also have years of experience in pic's and other engineering issues.
I was thinking that there is some kind of software that convert it.
I was tried a lot before I got here, so don't make wrong assumption about people.
The code I already wrote was : (sensor is in b4)
Code: |
output_high(pin_b5); //b5 is vdd
setup_adc_ports(sAN11);
set_adc_channel(11); //charge the adc capacitor to vdd
read_adc();
output_low(pin_b4); // initialize touch capacitor
setup_adc_ports(sAN10);
set_adc_channel(10); //connect internal capacitor to external so they equal
delay_ms(10); //to let it charge???
adc_value1=read_adc(); //get the voltage is is the output capacitor voltage
while(1)
{
delay_ms(10);
adc_value2=read_adc(); //check if output capacitor was changed so internal votage is changed
if( (adc_value1-adc_value2) >10)
{
output_high(pin_c2);
delay_ms(300);
output_low(pin_c2);
} |
|
|
|
msantang
Joined: 04 Mar 2012 Posts: 1
|
|
Posted: Sun Mar 04, 2012 8:41 am |
|
|
You find the solution?
Im trying to do the same for capacitive touch sensing |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
AN1298 |
Posted: Sun Mar 04, 2012 1:42 pm |
|
|
I'm with temtronic again on this one. Neither of us is going to write code for you.
YOU have to do the work, read the manuals etc.
In this particular case, you also have to think outside the box a touch.
I've not seen AN1298 before today, but this is my take on it.
When you do ADC in the normal way, you follow the set procedure. In CCS most of the work is done for you.
In this case it's a bit different.
Assuming a 5V VDD.
The ADC converter does not 'know' how you have set up the drivers to the outside world.
If A1 is a digital output set to 1, and you tell the ADC to select channel 1, Chold will charge to 5V.
Equally if A1 output is set to 0, Chold will charge to 0v.
I ran the program below on a PICDEM 2 PLUS. (It's complete and compilable.)
I used A1 because I'm lazy and did not want to remove the hardware connected to A0.
Code: |
#include <16f877.h>
#device adc=8 //
#FUSES HS // High speed ocillator
#FUSES NOWDT // no WDT
#FUSES PUT // power Up Timer
#FUSES NOPROTECT // no write protec
#FUSES NODEBUG // no debug ICD
#FUSES NOBROWNOUT // no brownout reset
#FUSES NOLVP // No low voltage prgming
#FUSES NOCPD // no eeprom protect
#use delay(clock = 4000000) // oscillator 4 MHz
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
int temp=0;
void main()
{
SETUP_ADC_PORTS(A_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL); //configuring ADC
while(true) //forever
{
output_high(pin_A1); // force a1 high
set_adc_channel(1); // should set Chold to 5V
delay_us(20); // Chold settle
temp = read_adc(); // get adc value
printf("adc_value high= %u ", temp);
delay_ms(200); // slow things down a bit
output_low(pin_A1); // force a1 low
set_adc_channel(1); // should set Chold to 0V
delay_us(20); // Chold settle
temp = read_adc(); // get adc value
printf("adc_value low= %u \r", temp);
delay_ms(200); // slow things down a bit
}
}
|
The output to the PC alternated between 255 and 0.
This ought be enough of a guide.
There should be no need to convert from microchip 'C' code to CCS.
[If you can't get the CCS commands to do the job, you may have to operate some of the registers directly.]
Oh, by the way, re your code:-
Quote: |
delay_ms(10);
adc_value2=read_adc(); //check if output capacitor was changed so internal votage is changed
if( (adc_value1-adc_value2) >10)
|
AN1298 suggests that the conversion is done with minimal delay after setting sensor as I/P.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 04, 2012 3:50 pm |
|
|
If you really must use the Microchip C code. Don't know why as Mike's pointed you to CCS code that's a good start....then it's fairly easy to cut a 'translation program' to convert Microchip C into the equivalent CCS C codes.
Just don't ask me for that program as I wrote it 20 years ago for the then 'new' 16F877..sigh, PICs were simpler, I was younger... |
|
|
|