I would like to use one touch button (or pad) with pic and I read the pdf file of Microchip AN1298 about that matter.
The document gives the following instructions to do the job;
* 1. Set 2nd channel to output, set high (VDD)
* 2. Select 2nd channel on ADC (charges CHOLD to VDD).
* 3. Set sensor line to output, set low (GND)
* 4. Select sensor line as input (TRISx = 1)
* 5. Select sensor channel on ADC (V-div sensor:CHOLD)
* 6. Begin ADC conversion
* 7. Reading is in ADRESH:ADRESL
I decided to write a program for 12F676 considering these explanations.
Here is the program . Could you pls someone check the program and let me know if there are some mistakes or missed points. Because the program does not work as I want.
Code:@ DEVICE pic12F675 @ DEVICE pic12F675, WDT_ON @ DEVICE pic12F675, PWRT_ON @ DEVICE pic12F675, PROTECT_OFF @ DEVICE pic12F675, MCLR_off @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT DEFINE OSCCAL_1K 1 DEFINE OSC 4 DEFINE ADC_BITS 8 'DEFINE ADC_CLOCK 1 DEFINE ADC_SAMPLEUS 10 CMCON = 7 RAW VAR byte 56 OPTION_REG=%01001111 GPIO=0 TRISIO=0 ANSEL = %01011111 ADCON0=%00001001 WPU=0 START: ANSEL.2=1 'GPIO.2 Analog selected This is secondary channel GPIO.2=1 'GPIO.2=HIGH this is for charging the C_hold capacitor OUTPUT GPIO.2 'GPIP.2 is output now ADCON0=%00001001 'AN2 (GPIO.2) selected for ADC purpose PAUSEus 10 TRISIO.4=0 'AN3=is output , this is sensor pin GPIO.4=0 'AN3 is LOW yapıldı This for discharging the sensor capacitor TRISIO.4=1 'AN3= is input now ANSEL.3=1 'AN3 is analog input now ADCON0=%00001101 'ADC =AN3 redierected to AN3 and C_hold voltage is divided (CVD ) pauseus 10 'wait 10 us ADCIN 3,RAW ANSEL.2=0 'GPIO.2 is Digital for re-use it on next cycle OUTPUT GPIO.4 'Sensor pin is Output now GPIO.5=1 'GPIO.5=HIGH , sensor pin is HIGH PAUSE RAW 'wait as HAM value (ms) GPIO.5=0 'GPIO.5=LOW Output is LOW now. pause 10 GOTO START




Bookmarks