Name:
touch
Syntax:

TOUCH channel, variable

Channel - is a variable/constant specifying the ADC channel (not pin number)

Variable - receives the byte touch reading

Description:

Read the touch sensor on the ADC channel and save reading into byte variable.

This command automatically configures the pin as an ADC and as a touch sensor. Note that the touch command is a 'pseudo' command that actually processes a touch16 command and then scales the 16 bit result to fit in a byte (to give a byte reading 0-255). This makes byte mathematics easier in simple programs but does mean that the touch sensor accuracy is reducing by the scaling process. When possible it is recommended that a touch16 command with a word variable is used instead. This will maintain the highest possible accuracy.

Please note that the touch reading can be affected by long serial cables connected to the project PCB (e.g. the older AXE026 download cable). Therefore it is not recommended that the older AXE026 serial cable (or AXE026/USB adapter combination) is used when trying to calibrate the touch command as it can affect the readings, only use the AXE027 USB cable for this calibration.

Due to the design of the silicon inside the microcontroller each pin will give slightly different readings. Therefore each pin must be calibrated separately. See the touch16 command description for more details about using touch sensors.

Affect of increased clock speed:

The clock speed will affect the count rate and so the result will change for each clock speed. Therefore the touch command must be calibrated at the actual clock speed in use.

Applies To:
08M2, 14M2, 18M2, 20M2, 28X2, 40X2
See Also:
Related Create:
Share:
Print:

Detect a touch

Set output B.2 high only when a touch sensor on ADC channel 1 is touched

Code Example:
main:	touch 1,b0		; read value into b0
	if b0 > 100 then
	  high b.2		; output B.2 on
	else
	  low b.2		; output b.2 off
	endif
	goto main		; else loop back to start
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.