Serial Wombat 18AB Firmware
Classes | Macros | Typedefs | Enumerations | Functions | Variables
touch.c File Reference
#include "serialWombat.h"
#include <stdint.h>
#include "pic24fj256ga702/mcc_generated_files/mcc.h"

Classes

struct  touch_n
 

Macros

#define touch   ((touch_t*) CurrentPinRegister)
 
#define CTMU_MODE_EDGE   0
 
#define RANGE_0_550uA   1
 
#define CTMU_TOUCH_THRESHHOLD_OFFSET   20
 

Typedefs

typedef struct touch_n touch_t
 

Enumerations

enum  touch_state_t { TOUCH_STATE_IDLE = 0, TOUCH_STATE_DISCHARGE = 1, TOUCH_STATE_SAMPLING = 2, TOUCH_STATE_WAITING_FOR_COMPLETION = 3 }
 
enum  TOUCH_CHANNEL_t { TOUCH_CHANNEL_ON_OFF, TOUCH_CHANNEL_MODE }
 

Functions

void initTouch (void)
 
void touchProcessDigital ()
 
void touchCallback ()
 
void updateTouch ()
 

Variables

touch_tdebugTouch
 

Macro Definition Documentation

◆ CTMU_MODE_EDGE

#define CTMU_MODE_EDGE   0

◆ CTMU_TOUCH_THRESHHOLD_OFFSET

#define CTMU_TOUCH_THRESHHOLD_OFFSET   20

◆ RANGE_0_550uA

#define RANGE_0_550uA   1

◆ touch

#define touch   ((touch_t*) CurrentPinRegister)

Typedef Documentation

◆ touch_t

typedef struct touch_n touch_t

Enumeration Type Documentation

◆ TOUCH_CHANNEL_t

Enumerator
TOUCH_CHANNEL_ON_OFF 
TOUCH_CHANNEL_MODE 

◆ touch_state_t

Enumerator
TOUCH_STATE_IDLE 
TOUCH_STATE_DISCHARGE 
TOUCH_STATE_SAMPLING 
TOUCH_STATE_WAITING_FOR_COMPLETION 

Function Documentation

◆ initTouch()

void initTouch ( void  )
\brief Initialization routine for Capacitive Touch sensor

Retrevial of Raw A/D conversions

Configure the A/D using the CONFIGURE_CHANNEL_MODE_0 command before reading values.
Raw A/D conversions are stored in the Pin's 16-bit Public data area. Use the Read Pin Buffer command to retreive it.


CONFIGURE_CHANNEL_MODE_0:

Initialize Cap Touch to Analog mode and set charge time

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC0 Pin To Set 0x16 (CapTouch) ChargeTime (LSB) ChargeTime (MSB) 0x55* 0x55* 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Set pin 0 to Cap Touch, with a charge time of 0x2080

0xC0 0x00 0x16 0x80 0x20 0x55 0x55 0x55


CONFIGURE_CHANNEL_MODE_1:

Configure high and low limits (Hysteresis) for digital mode.

Must not be called before 0xC0 command.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC1 Pin To Set 0x16 (CapTouch) Low Limit (LSB) Low Limit (MSB) High Limit (LSB) High Limit (MSB) 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Configure pin 0 to Captouch mode, Low Limit 0xC830, High Limit 0xF020

0xC1 0x00 0x16 0x30 0xC8 0x20 0xF0 0x55


CONFIGURE_CHANNEL_MODE_2:

Set the values reported as public data for Low (touch present) and High (touch absent) coniditions when in digital mode

Must not be called before 0xC0 command.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC2 Pin To Set 0x16 (CapTouch) Low Value (LSB) Low ValueLimit (MSB) High ValueLimit (LSB) High Value (MSB) 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Configure pin 0 to Report 10000 (0x2710) when touch is present and 2000 (0x07D0) when touch is absent

0xC2 0x00 0x16 0x10 0x27 0xD0 0x07 0x55


CONFIGURE_CHANNEL_MODE_3:

Set the values reported as public data for Low (touch present) and High (touch absent) coniditions when in digital mode

Must not be called before 0xC0 command. Commands 0xC1 and 0xC2 should be called before this command.

Debounce counts are in Cap Touch Samples, not mS. With proper Hysteresis settings this number is typically 0 or in the single digits

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC3 Pin To Set 0x16 (CapTouch) 0: Analog 1: Digital Inversion: 0: Touch Present is logic 1 1: Touch Present is Logic 0 Debounce Counts (LSB) Debounce Counts(MSB) 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Configure pin 0 to Digital mode, no iversion, 3 debounce counts

0xC3 0x00 0x16 0x01 0x00 0x03 0x00 0x55


CONFIGURE_CHANNEL_MODE_4:

Get digital status.

Must not be called before 0xC0 command. Commands 0xC1 and 0xC2 and 0xC3 should be called before this command.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC4 Pin To Set 0x16 (CapTouch) Reset Transition Count: 0:Don't reset 1: Reset 0x55* 0x55* 0x55* 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC4 Pin To Set 0x16 (CapTouch) Current digital state (0 or 1) Transitions (LSB) Transitions (MSB) Time since transtion (LSB), mS) Time since transition (MSB)

Examples:

Read current digital state, transitions, and time in state from Captouch pin 0. Reset the Transition count on read

0xC4 0x00 0x16 0x01 0x55 0x55 0x55 0x55

Response is logic high, 11 transistions, 7000 mS (1B58) since transition:

0xC4 0x00 0x16 0x01 0x0A 0x00 0x58 0x1B

◆ touchCallback()

void touchCallback ( )

◆ touchProcessDigital()

void touchProcessDigital ( )

◆ updateTouch()

void updateTouch ( )

Variable Documentation

◆ debugTouch

touch_t* debugTouch