14m2 and Touch16 'channels' ids

steliosm

Senior Member
Hello all.

I am making a small audio player using the Picaxe 14m2. For the control buttons (play/pause/prev/next/stop) I am using the touch capabilities of the chip. I saw in the picaxe site that the command refers to 'channels' and not port names but I couldn't trace any details on how the channels are numbered on the chip. I had a look at the datasheet which didn't help match. I used the port B for the touch sensors. I noticed that B.4 doesn't register a touch when using the command: touch16 4, w0. Connecting the touch sensor pad to port C.4 and using the exact same command (touch 16 4,w0) worked properly. So, my question is, does anyone knows where I can find the channel information? I would like to use pin B.4 for a touch sensor but I am not sure which channel number I should use.

Thank you,
Stelios
 

inglewoodpete

Senior Member
I don't know the actual answer to your question. However, if you compare the 14M2 pinout to the PIC16F1825, you will find that RevEd have remapped to pin names across the real ports in the silicon.

You could try experimenting with the base PIC's ADC channel IDs. For instance, PICAXE leg 9 (pin B.4) is actually RC1 in the PIC16F1825, with an ID of AN5 for ADC and touch. The PIC16F1825 has 8 AN (ADC) channels and it may just be a case of identifying them in the PICAXE.
 

AllyCat

Senior Member
Hi,

The valid pin numbers are shown for example in the pinout diagram in PICaxe Manual 1. They appear to be the same as the ADC input numbers, but I don't know if there's a physical (hardware) reason for that (certainly not all pins have ADC input hardware available). "Channel" numbers used to be associated with the ADC inputs (in the Microchip "base" chips) but I believe they were considered "confusing" and now at the M2s (maybe also X2s) just use the normal port.pin names.

According to Manual 1, all the Port B pins should work with Touch (except B.0 which is "output only"), but the sensitivity of all pins might not be the same (so need different threshold detection values). It's Port C which is more limited (particularly Leg4 which is a Programming/Reset pin on the base PICs).

Cheers, Alan.
 

steliosm

Senior Member
I tried cross checking between the datasheet and the 14m2 pin out, but it didn't work. For example, I don't get to use channel ids 6 or 7 (I get compile errors) but 8 is available which, on the other hand, is not defined in the datasheet. That means I have no clue where channel 8 is mapped to.
I also used another 14m2 to check the functionality on B.4, just in case I some how managed to touch the pin with bare finger and damaged it, but I got the same behavior. B.4 didn't register a touch input. I do see values coming in, but they don't change when my finger is on the 'touch' button.

I am using the C.4 pin at the moment, which work fine. This also means that the touch pad is also working fine, and it is not a 'design' failure that causes the input on that pad not to work properly.

The example on this page shows that you need to use the channel id and not the pin name:

I am using the pin names and I guess the compiler it's doing it's magic.
 

AllyCat

Senior Member
Hi,

The compiler always converts the Port.Pin names into numbers using the simple sequence b.0 = 0 ...... b.7 = 7 , c.0 = 8 ...... c.7 = 15 (and onwards for X2 chips). So just because you may use a (port) "number" in the program (to be compatible with "old" PICaxe chips), I don't believe it is a "channel" number (at least with M2s).

It's quite easy to demonstrate this by doing a syntax check on a simple test program, for example:
Code:
#picaxe 14m2
touch 7 , b0
which should report "Error: Pin B.7 does not exist on PICAXE-14M2" and if you try touch 9 , b0 you should get: "Error: Pin C.1 does not have ADC capability". So you can quickly check which pins the simulator "thinks" can be used. But there do appear to be a few "bugs" (perhaps trying to be compatible with the old channel numbers), because touch 0 , b0 is accepted, but touch b.0 , b0 produces the (correct) report: "Error: Pin B.0 does not have ADC capability" (actually it does, but that's another story ;) ).

Cheers, Alan.
 

steliosm

Senior Member
I did the syntax check trick, the results don't make any sense.
So, nobody uses touch pins on Picaxe? Is it maybe 'cos of the calibration hell? Different values when using a power bank, a powered USB hub or power from a 5V phone charger. Not to mention the mess in the touch values when I connect to a line in instead of a head set.
 

AllyCat

Senior Member
Hi,
..... the results don't make any sense.
So, nobody uses touch pins on Picaxe?
It's worth specifying what you think "don't make sense"; bugs won't get fixed unless technical is told! I'll just add that touch c.5 , b0 is not flagged as an error, but is "doubly" wrong in the simulator for the 14m2: PinC.5 is the serial/programming input pin which must be held low with a resistor, and also that pin is not an ADC input on the base PIC.

Certainly I would only (attempt to) use TOUCH16, and then only after carefully reading all the Application Notes from Rev Ed and Microchip. IMHO there are some "features" from Microchip, or implementations from Rev Ed, that are better forgotten about (unless you have a very specific need). My list would start with the SR Latch, ReadInternalTemp and Touch. :( Somewhere there's a Microchip AN called "50 Tips and Tricks....", of which about 10 are "useful", 15 "of some interest" and the other half so contrived that they're worthless.

Cheers, Alan.
 

steliosm

Senior Member
I know what you mean Alan. I had a look at the application notes for capacitive sensing, had some great tips on the size, distance, in between material, so I already know what I had to expect. I wasn't expecting to have a huge variation on the values when switching from headphones to a line in to my amplifier. Still, need to figure out how to fix that.

I wanted to avoid touch sensing originally, but it gives you freedom for very nice and slick interfaces:
24085
 

AllyCat

Senior Member
Hi,

With 5 channels (buttons/pads) you have the "advantage" that if they all change at the same time (or even any more than two of them) then the program can know that "something else" has changed, so a re-calibration is required. Note that because the raw (TOUCH16) data represents a frequency, then you probably need to compare the ratio of values (multiply or divide), not simply compare a linear relationship (addition or subtraction) of "previous" and "present" values.

Also, it's worth noting that TOUCH is a predefined editor macro command (it adds ~24 bytes to the program, with a corresponding execution delay), so it may well be more efficient to write your own routine around TOUCH16 (which itself adds only ~5 bytes to the program). I'm sure it should be possible to get TOUCH(16) working reliably, but it may need considerable planning and coding: It's not just a simple matter of "plug and play".

Cheers, Alan.
 

tmfkam

Senior Member
I know what you mean Alan. I had a look at the application notes for capacitive sensing, had some great tips on the size, distance, in between material, so I already know what I had to expect. I wasn't expecting to have a huge variation on the values when switching from headphones to a line in to my amplifier. Still, need to figure out how to fix that.

I wanted to avoid touch sensing originally, but it gives you freedom for very nice and slick interfaces:
View attachment 24085
That's fabulous! Is the "cassette" detected by NFC? Just curious.

Well done on the design. Really impressed.
 

steliosm

Senior Member
Alan, I am using touch16 already, it's easier to detect the 'touch' on the pads based on the size of the copper pads and the 4mm plywood in between. Currently, I just check the value of the touch against a fixed value, that I managed to find out during the calibration. I do have the available space on the Picaxe, maybe I should opt for an auto-calibration method so I don't have to open up the box every time I need to correct values.

inglewoodpet, that is great. I will read through the thread and see what I can use to improve the experience in my design.

tmfkam, the cassette tapes are just RFID cards. The RFID reader picks up the card's ID, Picaxe associates the (last 4 digits of) ID with a folder name (01 - 99) and the dfplayer module plays the mp3s in that folder. I will write up about this project as soon as I manage to get a stable version of it.
 

Technical

Technical Support
Staff member
As stated above, the compiler will now auto-correct use of pin number to the corresponding channel number. So touch16 4, w0 won't work for B.4 (as channel 4 is C.4) so you need to use touch16 B.4, w0. PortC is channel 0-7 and portB is channel 8-15

On earlier generation chips we found that having different channel numbers confused people (as here!) so the M2 parts correspond 1:1 pin/channel (as well as the compiler auto-correcting use of pin number).
 

steliosm

Senior Member
Thank you for clarifying this Technical. My main issue, though, was that B.4 didn't seem to be able to work as a touch sensor and that was tested on 2 different chips. I did get a value back every time I used the touch16 command but the value didn't change when I was touching the pad.
 
Top