Touch and Touch16

piclt

Member
I can get both touch and touch16 to work, eg I can sertxt out the of the variable giving its value.
I am using 8 off 8mm dia pads and wire of about 300mm out to them. It is only a test case at this stage so I covered the pads with 1 layer of sellotape. I works but dont get much difference between touched (say 4000 to 5000) and untouched (say 3000 to 4000) and different reads from each pad with some overlap. eg some untouched pads read higher than other touched ones. so it is difficult to get a trigger point to satisfy all eg above the trigger it flags 1 for touched and below trigger flags 0 for untouched.
I was going to try the effect of the config option but get syntax error if I use it.
Normal code is ......... touch16 C.0,w2
This gives syntax error .......... touch16 %10001001, C.0,w2
also get error with ............... touch16 10001001, C.0,w2

and also syntax error with

let b9 = %10001001
touch16 b9.C.0,w2

Also query does using pwmout on B.3 upset touch... ??? I am using a 18M2+
 

piclt

Member
I did a forum search for touch16 config and found the answer to the syntax error............
let b9 = %10001001
touch16 b9.C.0,w2 ..............It should be............ touch16 [b9].C.0,w2

I never thought about the square brackets that were shown on the manual2 page..??

I think its the first time I used { ] square brackets in programming..?
 

AllyCat

Senior Member
Hi,
let b9 = %10001001
touch16 b9.C.0,w2 ..............It should be............ touch16 [b9] . C.0,w2
No, still wrong, it should be touch16 [b9] , C.0 , w2 (note the commas), but there doesn't seem much point in using a variable (b9) in place of a direct constant (%10001001). You haven't said if you're using an M2 or X2, but presumably an M2 (as X2s don't work with touch 16), but IMHO the bit7 change will make hardly any worthwhile difference to the functionality.

8mm seems rather small for the "contact" pads, particularly with leads as long as 30 cms, but IMHO you can't use "fixed" threshold values with the TOUCH{16} command anyway, you need to use "adaptive" calibration (software) for each input pin separately. Again, you haven't identified which PICaxe you're using, so I can't say if PWM on B.3 may cause issues, but I certainly wouldn't risk it on an adjacent pin (or wire) to any of the Touch pads.

Using Touch pads is not a "simple" method to replace conventional hardware switches and most users abandon it. You really need to understand exactly how it works and how it needs to be configured/applied. There are several different Microchip Applications Notes (in addition to the relevant PICaxe's "base" Microchip Data Sheet) which indicates that it's not just a trivial approach.

EDIT: Sorry, I see that you said 18M2 right at the end, but I don't normally use that one, so don't know all its pin connections offhand.

Cheers, Alan.
 
Last edited:

erco

Senior Member
Agreed, you need bigger touchpads for more value differential. And the touch values received vary wildly from day to day, it's not practical to hard-code limits, you need to recalibrate in software often to compare touch and non-touch values. More of an experiment than practical use.

OTOH, cheap little touch switch modules are widely available and much easier to use.



 

piclt

Member
Thanks for the replies
Ok Ally, I mis-typed it in here with a dot instead of a comma, but in the prog had all the commas, it was the square brackets the threw me...??
I was wanting the pads small and Microchip note AN2934 mentions 8mm as typical. I also want speed for quick touches.
I get fastest with b9 = %11101000 ...... also freq at ..... setfreq m32 but still not a large difference between touch and not-touch.
I would probably need something like a gain control...??
""you need to use "adaptive" calibration (software) for each input pin separately" ..... Is that available within picaxe .... ?? any links etc
sometimes adaptive means averages etc over several reads and slows the process down..??
I will have a read or try some of the touch chips some give I2C out,may be easier for decoding what combination is touched etc.
Thanks
 

AllyCat

Senior Member
Hi,

If you want a higher frequency, then changing the configuration bits (4,3) to %10 or %11 should increase the oscillator frequency. Example 2 in the Online Command Reference gives an example of self-calibrating code, although that does include a considerable (2 seconds) delay. Even though the TOUCH16 is capable of recording a full Word value, a count or threshold could be scaled into a single byte, if necessary.

In principle, each pin needs to be calibrated separately, but a single routine can, for example, use an "indexed" POKE or PEEK pointer , threshold , or the byte pointer (@bptr) if the threshold is reduced to a single byte. Furthermore, the TOUCH command can itself be indexed (e.g. TOUCH16 b1 , w1 where b1 = C.0 , etc.), or even an arbitrary list of pins via e.g. LOOKUP b0 , (C.0 , C.2 , C.5 , etc.) , b1 .

Cheers, Alan.
 

piclt

Member
I used Lookup to list a range of touch pins then stored scanned the no-touch values of each pin in a variable for each pin using the Select case command. Found that the best for speed was to set config to give a low reading count, %00011000 gave reading no-touch 1500 - 2000 at setfreq m16 and +200 threshold. Also manual says "do not touch the bare pads" with the low reading range I can touch the bare pads and get a higher touched reading so more differential between touch and Not touch....??
"TOUCH command can itself be indexed (e.g. TOUCH16 b1 , w1 where b1 = C.0 , etc.), " ... couldn't figure this out....what is the relationship b1=C.0 ??? etc.
 

erco

Senior Member
One consideration re: "do not touch the bare pads" is that your potentially static-charged finger could zap an input pin. It's not connected to any other component. so all that voltage goes directly into the pin, possibly damaging it. Best practice is to not touch them directly.
 

AllyCat

Senior Member
Hi,

Indeed, it's the manufacturer (Microchip) who recommends that the pads should NOT be touched directly. Another potential issue is that touching the pin/pad directly may stop the oscillator entirely, which may produce "unpredictable" results.

....what is the relationship b1=C.0 ??? etc.
The relationship is that the compiler (or the Program Editor) always converts the "Port.Pin" name into a "number", which can then be stored and manipulated as a variable (e.g. b1). You can find out the value of the "number" by simulating, for example, SERTXD (#c.0) which will give the same value as if assigned to b1 (i.e. let b1 = c.0). Thus, in a Program the Port.Pin names can be listed and selected in exactly the same way as numbers or variables.

Cheers, Alan.
 

piclt

Member
Thanks for that, yes, on 18m2+ port B is 0 to 7 and port C is 8 to 15. I will have to play with it, probably why I got syntax errors using Table etc to store numbers. need to try again. The other thing is Touch16 channel number....??
 

AllyCat

Senior Member
Hi,

Yes the numbers should be the same on "all" PICaxes, but it's better practice to include the port names themselves in a program, rather than "Magic Numbers".

The "Channels" are the same as the ADC channel numbers (of the corresponding Microchip "base" PIC), but AFAIK are not used (in PE6) with M2 chips, and I'm not even sure about X2s now. So generally, just use the normal Port.Pin name, but check the code on a "real" PICaxe, or in the Simulator.

Cheers, Alan.
 

Technical

Technical Support
Staff member
You can use the Port.Pin notation on all commands with M2/X2.

However note that for the X2 parts the compiler will translate Port.Pin within a readadc/touch/touch16 command as specifically required for that command i.e. the matching ADC channel, so on a 28X2 'touch B.0' would actually output 'touch 12' (the channel number) not the sertxd(#B.0) value (which is 0).
 

piclt

Member
Regards my earlier posts .... " manual says "do not touch the bare pads" " but I find I can get a more "controlled and faster" touch by touching the bare pad and no false triggering of adjacent pads. If I use a small capacitor say 0.1 uf in series between the pin and the pad, that also works well, as does a series 10k resistor. I was wondering which may give best protection from the PICAXE being zapped from static etc. Some of the suggestions in the manuals etc are only apply a layer of lacquer etc to the pad surface...which would wear off due to continuous touching.. With the pad covered by a layer of plastic needs the config needs set up to higher setting and this make scanning of several pads very slow. I think bare pads is best but would welcome opinions..............
 
Top