PDA

View Full Version : Help Make Sense of QT510 SPI Protocol



GCollier
- 13th January 2006, 16:10
Not sure if anyone out there is working with this chip but I am having a bit of trouble figuring out how to communicate with it via SPI. You can find a link to the datasheet here:

http://www.qprox.com/downloads/datasheets/qt510_604.pdf

As far as I can tell I need to wait for the DRDY pin on the QT510 to go high then set the SS pin low, read the 8 bits using SHIFTIN mode 6. The QT510 datasheet states that the maximum clock rate is 40kHz for this chip, do I need to add a DEFINE SHIFT_PAUSEUS x to account for this.

By the way I'm using a PIC16F88 with the internal oscilator set to 8MHZ.

Any help/sample code would be greatly appreciated.

GCollier
- 15th January 2006, 04:20
Well, after a few failed attempts I got the thing to work. I need to tinker a bit with some of the settings, but for the most part it is doing exactly what it is supposed to. It was actually a whole lot easier than I had expected!

bbarney
- 15th January 2006, 13:43
hi
are you using their evaluation board or did you make your own.I've tinkered a bit with their other touch switches and they sure open up some interesting applications for using them.I would be interested in any progress you have.
Good Luck
BB

GCollier
- 16th January 2006, 19:44
Hey bbarney!

Actually I made my own board for the QT510 with a 2.5" diameter slider wheel. I modified the design to suit the parts I had on hand. Funny thing is the version on their schematic didn't work until I added a pull up resistor on the DRDY line.

It's not working great right now, I'm not sure if its my program or the board itself. The datasheet is very vague to say the least on a lot of aspects with these sensors. I may have it set a bit too sensitive, although I am using the default setting. I'm going to try and iron out a few of the bugs tonight if I get a chance.

G.

bbarney
- 17th January 2006, 14:26
the only thing I've found is this site
http://www.tigoe.net/pcomp/code/archives/arduino/000331.shtml

GCollier
- 18th January 2006, 04:00
Well I've been tinkering a bit more. I did a new board layout on some thinner material. I'm using a 5V regulator instead of a 3.3V one so that my levels are the same between the pic and the sensor IC. Still, I cant seem to get DRDY to go high...but if I force it data transmits just fine. I've attached my code below, it could use a bit of improvement but it works with a PIC16F88

'************************************************* ***************
'* Name : QT510.BAS *
'* Author : George Collier *
'* Notice : Copyright (c) 2006 *
'* : All Rights Reserved *
'* Date : 01/13/2006 *
'* Version : 1.0 *
'* Notes : QTouch 510 Interface Test *
'* : *
'************************************************* ***************
@ DEVICE WDT_OFF, MCLR_OFF
@_INTRC_OSC_NOCLKOUT ' Set to internal osc
DEFINE OSC 8
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_COMMANDUS 2000
DEFINE SHIFT_PAUSEUS 1000

'added for the 16F88
'OSCCON = %01100000 ' set internal osc to 4 MHZ
OSCCON = %01110000 ' set internal osc to 8 MHZ
CMCON = 7 ' shut off comparators
ADCON1 = 7 ' PORTA digital
TRISA = %11000000 ' Set PORTA to all outputs, A6 and A7 Input
TRISB = %00000000 ' Set PORTB to all outputs
'@_INTRC_OSC_NOCLKOUT ' Set to internal osc
'end add for 16F88
ANSEL = 0 'set all ports digital

I CON 254 ' Control Byte
CLR CON 1 ' Clear the display
LINE_1 CON 128 ' Point LCD to beginning of line 1
LINE_2 CON 192 ' Point LCD to beginning of line 2
LINE_3 CON 148 ' Point LCD to beginning of line 3
LINE_4 CON 212 ' Point LCD to beginning of line 4
CGRAM CON 64 ' Point to Cgram within LCD
SHIFT_L CON 24 ' Shift LCD display left
SHIFT_R CON 28 ' Shift LCD display right

SDO var PORTB.1 : LOW SDO ' PIC Data out pin
SDI VAR PORTA.6 : LOW SDI ' PIC Data in pin
SCLK var PORTB.6 : high SCLK ' PIC Clock out pin
qtSS var PORTB.7 : HIGH qtSS ' QTouch Slave Select Pin
DRDY VAR PORTA.7 : LOW DRDY ' QTouch DRDY Pin (INPUT)
'INPUT PORTA.7 'set DRDY pin to input

QT_POSN VAR Byte : QT_POSN = %01000000 ' Stores QTouch Position Data
QT_CFG_NULL VAR BYTE : QT_CFG_NULL = %00000000 'QTouch Null Command
QT_CFG_PROX VAR BYTE : QT_CFG_PROX = %01001010 'Qtouch Proximity Sensitivity
QT_CFG_TOUCH VAR BYTE : QT_CFG_TOUCH = %10001010 'Qtouch Touch Sensitivity
QT_CFG_DRIFT VAR BYTE : QT_CFG_DRIFT = %00000011 'Qtouch Drift Compensate
QT_CFG_CAL VAR BYTE : QT_CFG_CAL = %00000001 'Qtouch Calibration Command
READS VAR BYTE : READS = 0 'Counter for periodic drift compensation
STAT VAR QT_POSN.7 'QTouch STATUS

Pause 2000 ' Wait for LCD to startup

Lcdout $fe, 1 'Clear the LCD
LCDOUT " QWheel Test "
GOSUB INITIALIZE
PAUSE 2000
LCDOUT I, CLR
LCDOUT I, LINE_2, "READY FOR DATA"
GOTO LOOP

INITIALIZE:
IF DRDY = 1 THEN 'check if QTouch ready for data
PAUSEUS 13
Low QTSS 'Ready the QTouch to receive Data
SHIFTOUT SDO, SCLK, 5, [QT_CFG_PROX] 'Configure Proximity Sensitivity
HIGH qtss
PAUSEUS 100
LOW QTSS
PAUSEUS 13
SHIFTOUT SDO, SCLK, 5, [QT_CFG_TOUCH] 'Configure Touch Sensitivity
HIGH qtSS
PAUSEUS 100
LOW QTSS
PAUSEUS 13
SHIFTOUT SDO, SCLK, 5, [QT_CFG_NULL] 'Send NULL Command
HIGH qtSS 'Close the connection
pause 500
LCDOUT I, LINE_2, "INITIALIZE COMPLETE"
ENDIF
RETURN

LOOP:
if DRDY = 1 THEN GOSUB READ_QT
GOSUB QT_LCD
PAUSE 500
GOTO Loop

CALIBRATE:
PAUSEUS 13
LOW qtSS
SHIFTOUT SDO, SCLK, 5, [QT_CFG_CAL\8] 'send the recalibrate command
HIGH QTSS
RETURN

QT_LCD:
SELECT CASE STAT 'determine touch status and output data

CASE 1 'board is touched
LCDOUT I, CLR
LCDOUT "TOUCHED"
QT_POSN = QT_POSN / 2 'strips the position bit from QT_POSN
LCDOUT I, LINE_2, "POSITION: ", DEC QT_POSN 'prints position 0-127 on LCD
PAUSE 100
CASE 0 'board is not touched
LCDOUT I, CLR
LCDOUT I, LINE_1, "NOT TOUCHED"
LCDOUT I, LINE_2, "NO POSITION"
'if (QT_POSN.1 = 1) and (DRDY = 1) then GOSUB CALIBRATE 'recalibrate on error flag
' LCDOUT I, LINE_2, "RECALIBRATED"
' Pause 1000
END SELECT
RETURN

READ_QT:
LOW SDO 'Send all 0 on SHIFTIN = Null Command
LOW qtSS 'Activate QTouch
PAUSEUS 13
SHIFTIN SDI, SCLK, 6,[QT_POSN\8] 'read position data to QT_POSN
HIGH qtSS 'Deactivate QTouch
STAT = QT_POSN.7 'get the touch status from the output 0 = not touched
READS = READS + 1 'increment reads counter for drift compensation
if (READS > 10) and (STAT = 0) then 'drift compensate every 10 reads if no touch
LOW SDO
LOW qtSS 'Activate QTouch
PAUSEUS 13
SHIFTOUT SDO, SCLK, 5, [QT_CFG_DRIFT] 'Drift Compensate
HIGH qtSS
PAUSEUS 20
READS = 0 'reset the reads counter
ENDIF
RETURN

END