Touch_Buffer[0][Touch_Counter]>>=3;
Touch_Buffer[0][Touch_Counter] = 4096-Touch_Buffer[0][Touch_Counter];
Touch_Buffer[0][Touch_Counter] -= 280; // subtracts theoffset THESE ARE MEASURED CALIBRATION VALUES
Touch_Buffer[0][Touch_Counter] *= 0.0936768; // Multiplied by the range (320/(3696-280))
SpiChnPutC(SpiChn, 0b10011100);
SpiChnPutC(SpiChn, 0b11011100); // Sends the control byte
In your new code, did you use the 8 bit mode instead of 12 bit mode ?
Regarding, void ReadTouchXY(void)
-How do you fill-in the 30 convertion into it , i do not see a 'for' loop ( for i = 0 i<30 i++ ) in there ?
void ReadTouchXY(void)
{
Touch_Counter++;
if(Touch_Counter==30) Touch_Counter = 0;
if(Touch_Counter>30) Touch_Counter = 0; // The pointer for the FIFO buffer
...
...
Touch_Buffer[1][Touch_Counter] = xxx;
unsigned short Touch_Buffer[2][50];
First, it seems you read Y+ channel in 8 bits mode, don't you ?
Here A2-A1 address is 101 ( bit 6 to bit 4 )Code:SpiChnPutC(SpiChn, 0b11011100); // Sends the control byte
But i don't see when you X+ channel afterward .
Many thanks for your help,
else
{
Touch_PenIRQ_TRIS = 0; // Sets the PenIRQ to an output
Touch_PenIRQ_LAT = 0; // Drives the PenIRQ low so the diode is not forward biased
Touch_CS = 0; TDelay(); // Asserts the CS line and gives a required delay
* SpiChnPutC(SpiChn, 0b11011100); // Sends the control byte
SpiChnGetC(SpiChn); // Reads the dummy data to clear the receive buffer
while(Touch_Busy == 1); // Makes sure the controller isn't busy
SpiChnPutC(SpiChn, 0x00); // Sends a dummy byte in order to clock the data out
unsigned char rxd1 = SpiChnGetC(SpiChn);// Puts the received data into rxd1
* SpiChnPutC(SpiChn, 0b10011100); // Sends the next control byte to read the other axis
unsigned char rxd2 = SpiChnGetC(SpiChn);// Reads the lower byte of the first received data
// The following figure is the result (rxd1 & rxd2) inverted (4096-) - the offset (measured) * the range
Touch_Buffer[1][Touch_Counter] = 4096-(rxd1<<5) + (rxd2>>3);
// if(Touch_Buffer[1][Touch_Counter]<Ymin){Touch_Buffer[1][Touch_Counter] = 0;}
// else{Touch_Buffer[1][Touch_Counter] -= Ymin; Touch_Buffer[1][Touch_Counter] *= Yrange;}
// if(Touch_Buffer[1][Touch_Counter]>239) Touch_Buffer[1][Touch_Counter] = 239;
...
and
...
// The following figure is the result (rxd1 & rxd2) - the offset (measured) * the range
Touch_Buffer[0][Touch_Counter] = ((rxd1<<5) + (rxd2>>3));
// if(Touch_Buffer[0][Touch_Counter]<Xmin){Touch_Buffer[0][Touch_Counter] = 0;}
// else{Touch_Buffer[0][Touch_Counter] -= Xmin; Touch_Buffer[0][Touch_Counter] *= Xrange;}
// if(Touch_Buffer[0][Touch_Counter]>319) Touch_Buffer[0][Touch_Counter] = 319;
if(Touch_Buffer[1][Touch_Counter]>239) Touch_Buffer[1][Touch_Counter] = 63;
...
and
...
if(Touch_Buffer[0][Touch_Counter]>319) Touch_Buffer[0][Touch_Counter] = 127;
// These are measured calibration values
// Place your own measured calibration values here
#define Xmin 320
#define Xmax 3744
#define Ymin 352
#define Ymax 3792
#define Xrange 0.093458 // =(num of x pixels/(Xmax-Xmin))
#define Yrange 0.069768 // =(num of y pixels/(Ymax-Ymin))
//
unsigned short int PEN_X_pos = 0;
unsigned short int PEN_Y_pos = 0;
...
PEN_X_pos = ADS7843_read(0x90);
PEN_Y_pos = ADS7843_read(0xD0);
void Init_ADS7843(void)
{
// Configure PENIRQ pin
Touch_PenIRQ_TRIS = 1; // Touch_PenIRQ is input
Touch_PenIRQ_IO = 0;
// Set up the SPI module on the PIC for communications with the ADS7843 :
ADS7843_CS_IO = 1; // Disable ADS7843 CS pin
ADS7843_CS_TRIS = 0; // Pic CS pin is output
ADS7843_SCK_TRIS = 0; // Set SCK pin as an output
ADS7843_SDI_TRIS = 1; // Make sure SDI pin is an input
ADS7843_SDO_TRIS = 0; // Set SDO pin as an output
ADS7843_SPI_IF = 0; // Clear SPI Flag
ADS7843_SPISTATbits.CKE = 1; // Transmit data on rising edge of clock
ADS7843_SPISTATbits.SMP = 0; // Input sampled at middle of data output time
}
unsigned short int ADS7843_read(unsigned char address)
{
volatile BYTE Dummy;
unsigned char msb, lsb;
ADS7843_CS_IO = 0; // Enable CS
ADS7843_SPI_IF = 0; // Clear SPI Flag
_asm NOP _endasm // Generate some µS delay after CS pin goes low
ADS7843_SSPBUF = address; // Transmit Start bit ( SSP1BUF )
while(!ADS7843_SPI_IF);ADS7843_SPI_IF = 0; // Wait until data is shifted out
Dummy = ADS7843_SSPBUF; // Reading SSPBUF clears SPI Buffer
Delay10us(1); // Add 10us for Tacq delay time
ADS7843_SSPBUF = 0x00; // Send dummy value (0x00) in order to get the FIRST 8 bit byte
while(!ADS7843_SPI_IF);ADS7843_SPI_IF = 0; // Wait until data is shifted out
msb = ADS7843_SSPBUF; // Get the FIRST 8 bit byte ( 8 clock edges )
ADS7843_SSPBUF = 0x00; // Send dummy value (0x00) in order to get the SECOND 8 bit byte
while(!ADS7843_SPI_IF);ADS7843_SPI_IF = 0; // Wait until data is shifted out
lsb = ADS7843_SSPBUF; // Get the SECOND 8 bit byte ( 8 clock edges )
ADS7843_CS_IO = 1; // Disable CS
return (msb*0x100) | lsb;
}
}
void Init_ADS7843(void)
{
// Configure PENIRQ pin
Touch_PenIRQ_TRIS = 1; // Touch_PenIRQ is input
Touch_PenIRQ_IO = 0;
// Set up the SPI module on the PIC for communications with the ADS7843 :
ADS7843_CS_IO = 1; // Disable ADS7843 CS pin
ADS7843_CS_TRIS = 0; // Pic CS pin is output
ADS7843_SCK_TRIS = 0; // Set SCK pin as an output
ADS7843_SDI_TRIS = 1; // Make sure SDI pin is an input
ADS7843_SDO_TRIS = 0; // Set SDO pin as an output
ADS7843_SPI_IF = 0; // Clear SPI Flag
ADS7843_SPISTATbits.CKE = 1; // Transmit data on rising edge of clock
ADS7843_SPISTATbits.SMP = 0; // Input sampled at middle of data output time
Delay10us(1);
ADS7843_read(0x90); // Send a read sequence in order to activate PENIRQ (PD1 and PD0 = 0)
}
Low[/COLOR] when a touch has happened.
- PENIRQ stays Up if there is no touch.
Would you please tell me what SPI modes are compatibles with ADS7843 ?
What is the maximum speed ( SCK clock frequency ) accepted by this chip ?
I did not find this information in the datasheet.
I currently using CKE = 0 ( SPI mode 0,0 ) and my SPI speed is 2.5 MHz
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?