Atmel PTC Touch - Bare Metal  - Page 1
Forum section: electronics / general

author: Nick Novak
author_rank: Contributor
timestamp: March 28, 2020, 05:14:23 am
content: Hi All,Wondering if anyone has taken the time to reverse engineer Qtouch or has found some information on the PTC module in Atmel/Microchip SAM chips and written a bare metal touch sense application? I'm looking to add a quick proximity sensing function to an existing SAMR design without Qtouch. Something with a small code footprint and simple: let me setup the clocks, pick the frequency, charge current etc, polled and just tell me the charge time numbers, I'll figure out the rest.I did a similar proof of concept with a freescale chip years ago and it took about 2 hours from opening the data sheet to saying gee wiz guys look at this (and probably about 32 bytes of code space).I don't know what to say about Qtouch composer though, I'm probably 8h deep over 4 sessions of idle time and I still haven't even gotten it installed correctly. Atmel studio 6.2 and 7 freshly installed on 2 computers and universally AT studio Extension manager errors out trying to open the downloads page, direct download .vsix packages seem unopenable without some extension you need to get through the extension manager. Catch-22 or what?I'm at step 0 and its already broken, the advice I read is: maybe you didn't double click the installer right.So, am I a lone dinosaur who likes to see documented registers or has anyone else gone down this particular path before me?

author: westfw
author_rank: Super Contributor
timestamp: March 28, 2020, 09:07:41 am
content: Adafruit didhttps://github.com/adafruit/Adafruit_FreeTouchfor SAMD21; I haven't used it or heard much about it.AFAIK, the internals are kept pretty secretive. Atmel bought a a whole company to acquire that tech. ("Quantum Research Group UK":https://www.marketscreener.com/ATMEL-8479/news/Atmel-Atmel-to-Acquire-Quantum-Research-Group-A-Leading-Developer-of-Touch-Sensing-Technologies-456506/)

author: chris_leyson
author_rank: Super Contributor
timestamp: March 28, 2020, 12:02:36 pm
content: EDIT: I've never had much luck with Qtouch Composer and couldn't believe how much code it generated just for a single touch button. The technique used for a single touch sensor is really elegant thanks to Harald Phillipp and not too difficult to reverse engineer. The only downside is that two IO pins are needed for each sense electrode but no A-D conversion required. Very elegant.Atmel aquired Quantum Research Group who manuactured Qprox touch sensors. QT110 for example was based on a PIC12C508. Eariest patent I could find is US5730165 but I suspect there might be earlier applications. A few of the many patents as follows:US5730165 Time Domain Capacitive Field Detector, 1998US6466036 Charge Transfer Capacitance Measurement Circuit, 2002US8749251 Proximity Sensor, 2014US9081572 Proximity Sensor, 2015Charge is transfered from the sense capacitor, Cx, to the integrating or storage capacitor, Cs, in short bursts of 8 pulses and the newer Atmel Qtouch sensors work in a similar fashion. Some of the Atmel sensors use bursts of 4 pulses. Disassembly of the first 64 instructions from a QT110 touch sensor, read protect didn't work for the first 64 PIC12C508 instructions.Code:Line Address Opcode Disassembly1 000025 MOVWF 0x52 0015A3 BSF 0x3, 0x5Program Page PA0 = 13 002A0A GOTO 0xa4 003 LBL_0074 CLRF 0x145 004073 CLRF 0x136 005C1F MOVLW 0x1f7 006006 TRIS 0x6GP1 = in GP0 = in8 007210 MOVF 0x10, WW = ?9 008D02 IORLW 0x2W = 0b0000001010 009026 MOVWF 0x6GPIO = 0b0000001011 00A LBL_1C1D MOVLW 0x1dStart ?12 00B LBL_2006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx13 00CC1E MOVLW 0x1e14 00D006 TRIS 0x6GP1 = in GP0 = '0'15 00EC1D MOVLW 0x1d16 00F626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs17 010A40 GOTO 0x40Branch if GP1 = 1 LBL_318 011006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx19 012C1E MOVLW 0x1e20 013006 TRIS 0x6GP1 = in GP0 = '0'21 014C1D MOVLW 0x1d22 015626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs23 016A43 GOTO 0x43Branch if GP1 = 1 LBL_424 017006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx25 018C1E MOVLW 0x1e26 019006 TRIS 0x6GP1 = in GP0 = '0'27 01AC1D MOVLW 0x1d28 01B626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs29 01CA46 GOTO 0x46Branch if GP1 = 1 LBL_530 01D006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx31 01EC1E MOVLW 0x1e32 01F006 TRIS 0x6GP1 = in GP0 = '0'33 020C1D MOVLW 0x1d34 021626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs35 022A49 GOTO 0x49Branch if GP1 = 1 LBL_636 023006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx37 024C1E MOVLW 0x1e38 025006 TRIS 0x6GP1 = in GP0 = '0'39 026C1D MOVLW 0x1d40 027626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs41 028A4C GOTO 0x4cBranch if GP1 = 1 LBL_742 029006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx43 02AC1E MOVLW 0x1e44 02B006 TRIS 0x6GP1 = in GP0 = '0'45 02CC1D MOVLW 0x1d46 02D626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs47 02EA4F GOTO 0x4fBranch if GP1 = 1 LBL_848 02F006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx49 030C1E MOVLW 0x1e50 031006 TRIS 0x6GP1 = in GP0 = '0'51 032C1D MOVLW 0x1d52 033626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs53 034A52 GOTO 0x52Branch if GP1 = 1 LBL_954 035006 TRIS 0x6GP1 = '1' GP0 = inCharge Cx55 036C1E MOVLW 0x1e56 037006 TRIS 0x6GP1 = in GP0 = '0' Next burst starts 8us later57 038C1D MOVLW 0x1d58 039626 BTFSC 0x6, 0x1Skip if GP1 = 0Read Cs59 03AA55 GOTO 0x55Goto 0x55 LBL_1060 03B2B3 INCF 0x13, FInc burst counter61 03C743 BTFSS 0x3, 0x2Skip if 'Z' = 162 03DA0B GOTO 0xbGoto 0x0b LBL_263 03E2B4 INCF 0x14, F64 03FA0B GOTO 0xb65 040LBL_366 04167 04266 043LBL_469 04470 04571 046LBL_572 04773 04874 049LBL_675 04A76 04B69 04CLBL_778 04D79 04E80 04FLBL_881 05082 05183 052LBL_983 05365 05466 055LBL_10It's not too difficult to see what's going on by probing the sense pins with a high impedance probe. Not sure why the integrating capacitor is charged up in short bursts of 8 when you could do this with a continuous stream of charge cycles.

author: Nick Novak
author_rank: Contributor
timestamp: March 28, 2020, 01:38:19 pm
content: Okay. Adafruit. That looks promising. Thanks very much.I'll try to get my kids watching a movie then work on this for an hour or two. Will post the results.

author: Nick Novak
author_rank: Contributor
timestamp: March 28, 2020, 02:06:57 pm
content: I wasn't aware of the history behind atmel's peripheral touch implementation. I guess there is some secret sauce but it sounds like they have patent protection so why not at least expose the registers. I feel like Qtouck composer is causing them to sell less chips not more.I expect I could even do what I want with a single GPIO using internal pull-up / pull-down to produce the charge ramps, use the input buffer's low / high transition as a window comparator and a precision timer for the measurement. The accuracy and temperature stability of the input buffer transitions would probably make it suck but if you high pass filter the output... maybe a poor mans PTC, but I digress.A neato fact: my company makes a big version of this (like 150m wide by 6m tall) and has been for decades:https://senstar.com/products/above-ground-sensors/xfield/

author: chris_leyson
author_rank: Super Contributor
timestamp: March 28, 2020, 02:38:44 pm
content: Some background reading