| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Capacitive Sensing with PIC10F Author: Marcel Flipse Microchip Te
Top Searches for this datasheetAN1202 Capacitive Sensing with PIC10F Author: Marcel Flipse Microchip Technology Inc. IMPLEMENTATION Capacitive sensing implemented turning comparator into relaxation oscillator. output comparator used charge discharge sensing capacitor, that formed circuit board. charge rate determined time constant, created external resistor capacitance pad. Introduction additional capacitance from person's finger ground causes frequency change. This change measured PIC® processed detect finger press. basic oscillator circuit shown Figure parasitic capacitance. During start-up this capacitance charge voltage zero. Therefore, output comparator will high touch rapidly charged through until reaches VDD. INTRODUCTION This application note describes method implementing capacitive sensing PIC10F204/6 family controllers. assumes general knowledge sensing process; also recommended that application note AN1101, "Introduction Capacitive Sensing", read order understand hardware concepts. PIC10F204 PIC10F206 microcontrollers have onboard comparator that used capacitive sensing single key. FIGURE BASIC OSCILLATOR SCHEMATIC Data FOSC/4 Band Buffer 0.6V Touchpad 1:256 Prescaler TMR0 output comparator will change state. Then, discharges slowly through until reaches trip point internal band reference 0.6V. output comparator will high again cycle repeats itself. 2008 Microchip Technology Inc. DS01202B-page AN1202 scope plot this charge/discharge cycle seen Figure Trace shows output comparator trace voltage across (Cp). full circuit schematic illustrated Appendix output comparator frequency that related capacitance pad. base frequency used this example. frequency 100-400 range will work. Using higher frequency makes measurement cycle shorter. read. Reading both prescaler TMR0 value will give 16-bit value frequency oscillator (frequency counts). order read prescaler directly PIC10F, software technique used estimate value prescaler. After measurement, relaxation oscillator stopped clock source TMR0 internal oscillator (FOSC/4). software then polls increase roll-over TMR0 value. amount time takes TRM0 change value indication prescaler value. Thus, following sequence needed measure frequency: Turn oscillator Clear TMR0 prescaler Wait fixed time duration (100 Example Stop oscillator Read TMR0 value Select FOSC/4 clock source TMR0 Count number cycles takes before TMR0 changes value, estimate prescaler FIGURE OSCILLATOR OUTPUT MEASURING FREQUENCY Once oscillator constructed, frequency must monitored detect drop frequency caused finger press. measure frequency, oscillator started output comparator into TMR0. TMR0 8-bit timer/counter with 8-bit software programmable prescaler. After fixed software delay, prescaler value TMR0 SOFTWARE detection scheme used detect finger press based principle that there rapid drop frequency counts from running average. finger touches pad, capacitance increases frequency drops. initialize oscillator, following sequence needed: EXAMPLE MOVLW TRIS MOVLW INITIALIZATION CODE ;set gp1,gp2 output b'11111001' gpio b'11110111' ||||||||_ |||||||_ ||||||_ |||||_ ||||_ |||_ ps2set prescaler 1:256 psaprescaler assigned tmr0 t0se increment high t0cs transition t0cki #gppu pull-ups disabled #gpwu wake-up change disabled OPTION MOVLW b'00001011' ||||||||_ #cwu wake-up comp disabled |||||||_ cpref cin+ ||||||_ cnref internal 0.6V |||||_ cmpon comparator ||||_ cmpt0cs comp. used tmr0 source |||_ output inverted #couten output placed cout cmpout -read only bitMOVWF cmcon0 CLRF tmr0 clear tmr0 1:256 prescaler DS01202B-page 2008 Microchip Technology Inc. AN1202 After this sequence, oscillator turned prescaler TMR0 will increment. Longer shorter discharge times obtained varying value this example, software waits stops oscillator. chosen obtain large value prescaler TMR0. Choosing different base frequency oscillator require different delay. Make sure delay chosen long enough good reading, short enough that TMR0 does overflow. FIGURE FREQUENCY BURSTS EXAMPLE MOVLW gatedtime CALL delay constant equals wait mSec DETECTING FINGER PRESS this point system complete, except detection signaling button press. remaining portion handled main loop program. simple watch decrease frequency variables constant. These are: MOVF cmcon0,cmpon; turn oscillator tmr0,w high byte freq value stored tmr0 MOVWF freqhi value still prescaler EXAMPLE value prescaler directly readable. estimate prescaler, clock source TMR0 changed FOSC/4 software loop counts time needed TMR0 increment roll over. freqhi:freqlo averagehi:averagelo triphi:triplo Current sensor data Running Average const Trip point EXAMPLE MOVLW OPTION measureprescaler: INCF freqlo MOVF XORWF BTFSC GOTO b'11010111'; change clock source Fosc/4 freqhi:freqlo holds current sensor data. averagehi:averagelo running average previous samples, calculated follows: EQUATION initialised here tmr0,w current value tmr0 freqhi,w compare with original value tmr0 status,z tmr0 increment? measureprescaler; loop increment ((2n) averagevalue currentvalue example, current reading given weight 1/16th, while running average weighed 15/16th. necessary store variables 16-point average. Using number which power N-point average saves processing time because right-shifts used instead software division. simplest button press algorithm would test current value fixed distance below average pseudocode example below. This loop takes instruction cycles, maximum value freqlo will This value multiplied clipped 255. Least Significant bits (LSb) useful and, therefore, result divided Figure snapshot free running oscillator. upper trace shows oscillator being turned periodically lower trace shows microcontroller transmitting real time data serially over free available pin. EXAMPLE (freq (average button user code Else button user code EndIf trip) then pressed here pressed here 2008 Microchip Technology Inc. DS01202B-page AN1202 provide illustrative example, assume oscillator reads 10,000 without finger pressing button. average current value will both 10,000. designer, assume trip value 1,000 good value. When someone presses button, value immediately drops 8,500, average still 10,000. statement" Example will prove true, because 8,500 less than 9,000. button pressed. Then, flag response performed reaction. Note: example above very simplistic demonstrate frequency drop fundamental change common all. Alternative software algorithms detecting button presses found application note AN1103, "Software Handling Capacitive Sensing". FIGURE CONTINUOUS TOUCH Average value still tracking current value Keypress detected average locked constant value subtracted from average value released average algorithm restarted IMPLEMENTING CONTINUOUS TOUCH averaging mechanism software, finger press will deactivated when average value reaches current value again. dotted line Figure average value, black line value. seen, average value slowly tracking current value. difference between current value average value less than trip point, will released. Refer firmware source code more information enable this feature. IMPLEMENTING PROXIMITY SWITCH proximity switch non-contact type switch. typical proximity switch sense presence absence object, like hand, without actually contacting object. This useful applications like electric hand dryers door access control. circuit described easily turned into proximity switch. This done using larger sensing element adjusting value discharging resistor, trip point (triphi:triplo) must also adjusted make proximity sensor. trip point must lowered significantly make proximity sensor instead touch sensor. rule thumb, maximum detectable distance from hand sensor equal diameter sensor pad. Thus, larger pad, greater distance. material between hand sensor influence maximum distance. FIGURE AVERAGING MECHANISM A-key released implement continuous touch, different algorithm used. averaging must cease track current value when crossed trip threshold. prevent stuck key, additional hysteresis subtracted from average value. drift, current value reach same value before finger press. average value locked after finger press seen Figure Slight changes will still tracked. FIGURE PROXIMITY SWITCH DS01202B-page 2008 Microchip Technology Inc. AN1202 sensor large copper area printed circuit board constructed with conductive tape inside plastic enclosure, therefore allowing single double curved surface. Even objects like metal enclosure used sensor, long physically connected ground. When using large proximity switch, capacitance will larger than standard button. Therefore, frequency will lower. Adjust value that base frequency will remain within range. FIGURE RISE TIME PRECAUTIONS PIC10F20X Timer0 Overflow Since principle measurement read from TRM0 value, TMR0 must overflow. longer period will allow more counts, select measurement period short enough that this does happen. Increasing oscillator frequency allows shorter measuring cycles without losing resolution. CIRCUIT BOARD DESCRIPTION full schematic illustrated Appendix board powered external power supply serial port. (Request Send) (Data Terminal Ready) pins supply enough current power board. These pins tied through MCP1703 used make stable supply MCU. free routed buzzer, connected serial port setting jumper correct position single transistor (Q1) used shift voltage levels RS-232 compatible level. negative level (V-) derived from PC's transmit pin, through jumper that used switch between modes. With jumper place, PIC10F transmits real time data, like average value, current value, trip point averaging depth. Without jumper circuit functions button operates buzzer. jumper correct position depending mode. programming connector. PICkit2 used program board. Disconnect programmer after programming. from programmer shared with touch inhibits correct operation free running oscillator. Stuck Buttons When implementing continuous touch algorithm, averaging mechanism will stop. drift, current value reach same value. Make sure hysteresis large enough compensate drift current value. Power Supply Fluctuations trip point oscillator internal 0.6V reference. capacitance discharged from 0.6V, therefore rapid change will cause oscillator change frequency. This could trigger false finger presses. Slow variations, like running battery, will compensated averaging mechanism. possible, regulated power supply decoupling capacitors close microcontroller. Also, take rise time into account. minimum Rise Rate cannot met, device must held Reset until operating parameters met. Alternatively, circuit shown Figure below used. This way, MCLR still used general purpose input pin. 2008 Microchip Technology Inc. DS01202B-page AN1202 CONCLUSIONS Software provided with this application note understanding expediting design. software drive capacitive sensing either very simple handle complex algorithms button detection. Additional reference materials include: AN1101, "Introduction Capacitive Sensing" AN1102, "Layout Capacitive Sensing" AN1103, "Software Handling Capacitive Sensing" AN1104, "Capacitive Mini-Button Configurations" DS01202B-page 2008 Microchip Technology Inc. CAPACITIVE SENSING WITH PIC10F Appendix Full Circuit Schematic 2008 Microchip Technology Inc. DS01202B-page Capacitive Sensing with PIC10F NOTES: DS01202B-page 2008 Microchip Technology Inc. Note following details code protection feature Microchip devices: Microchip products meet specification contained their particular Microchip Data Sheet. Microchip believes that family products most secure families kind market today, when used intended manner under normal conditions. There dishonest possibly illegal methods used breach code protection feature. these methods, knowledge, require using Microchip products manner outside operating specifications contained Microchip's Data Sheets. Most likely, person doing engaged theft intellectual property. Microchip willing work with customer concerned about integrity their code. Neither Microchip other semiconductor manufacturer guarantee security their code. Code protection does mean that guaranteeing product "unbreakable." Code protection constantly evolving. Microchip committed continuously improving code protection features products. Attempts break Microchip's code protection feature violation Digital Millennium Copyright Act. such acts allow unauthorized access your software other copyrighted work, have right relief under that Act. Information contained this publication regarding device applications like provided only your convenience superseded updates. your responsibility ensure that your application meets with your specifications. MICROCHIP MAKES REPRESENTATIONS WARRANTIES KIND WHETHER EXPRESS IMPLIED, WRITTEN ORAL, STATUTORY OTHERWISE, RELATED INFORMATION, INCLUDING LIMITED CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY FITNESS PURPOSE. Microchip disclaims liability arising from this information use. Microchip devices life support and/or safety applications entirely buyer's risk, buyer agrees defend, indemnify hold harmless Microchip from damages, claims, suits, expenses resulting from such use. licenses conveyed, implicitly otherwise, under Microchip intellectual property rights. Trademarks Microchip name logo, Microchip logo, Accuron, dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC, SmartShunt UNI/O registered trademarks Microchip Technology Incorporated U.S.A. other countries. FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor Embedded Control Solutions Company registered trademarks Microchip Technology Incorporated U.S.A. Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, WiperLock ZENA trademarks Microchip Technology Incorporated U.S.A. other countries. SQTP service mark Microchip Technology Incorporated U.S.A. other trademarks mentioned herein property their respective companies. 2008, Microchip Technology Incorporated, Printed U.S.A., Rights Reserved. Printed recycled paper. Microchip received ISO/TS-16949:2002 certification worldwide headquarters, design wafer fabrication facilities Chandler Tempe, Arizona; Gresham, Oregon design centers California India. Company's quality system processes procedures PIC® MCUs dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory analog products. addition, Microchip's quality system design manufacture development systems 9001:2000 certified. 2008 Microchip Technology Inc. DS01202B-page WORLDWIDE SALES SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. Chandler, 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.microchip.com Address: www.microchip.com Atlanta Duluth, Tel: 678-957-9614 Fax: 678-957-1455 Boston Westborough, Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca, Tel: 630-285-0071 Fax: 630-285-0075 Dallas Addison, Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills, Tel: 248-538-2250 Fax: 248-538-2260 Kokomo Kokomo, Tel: 765-864-8360 Fax: 765-864-8387 Angeles Mission Viejo, Tel: 949-462-9523 Fax: 949-462-9608 Santa Clara Santa Clara, Tel: 408-961-6444 Fax: 408-961-6445 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Asia Pacific Office Suites 3707-14, 37th Floor Tower Gateway Harbour City, Kowloon Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Australia Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 China Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 China Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 China Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 China Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 China Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China Shenzhen Tel: 86-755-8203-2660 Fax: 86-755-8203-1760 China Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 China Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 China Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 ASIA/PACIFIC India Bangalore Tel: 91-80-4182-8400 Fax: 91-80-4182-8422 India Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 India Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 Japan Yokohama Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Korea Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 Korea Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 82-2-558-5934 Malaysia Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 Malaysia Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 Philippines Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan Hsin Tel: 886-3-572-9526 Fax: 886-3-572-6459 Taiwan Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 EUROPE Austria Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Italy Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands Drunen Tel: 31-416-690399 Fax: 31-416-690340 Spain Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 01/02/08 DS01202B-page 2008 Microchip Technology Inc. Other recent searchesVPW05980 - VPW05980 VPW05980 Datasheet SN74AUC32 - SN74AUC32 SN74AUC32 Datasheet SDS0603B - SDS0603B SDS0603B Datasheet PXC14SFBN - PXC14SFBN PXC14SFBN Datasheet LSD335 - LSD335 LSD335 Datasheet 61-XX - 61-XX 61-XX Datasheet RP117-PF - RP117-PF RP117-PF Datasheet ERA-33SM - ERA-33SM ERA-33SM Datasheet RDF-1079C - RDF-1079C RDF-1079C Datasheet ARTIC960RxD - ARTIC960RxD ARTIC960RxD Datasheet ADS7812 - ADS7812 ADS7812 Datasheet AD7678 - AD7678 AD7678 Datasheet
Privacy Policy | Disclaimer |