CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

QT300
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

QT300
PostPosted: Fri Aug 20, 2004 12:32 pm     Reply with quote

I need connect a QT300 SPI sensor to 16f819 , but I am not sure my connection is right, would you please help to find out how to connected them together.

datasheet for them are:
http://www.qprox.com/downloads/datasheets/qt300_102.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/39598d.pdf

I connected now

16f819 QT300
Pin 7 RB1/SDI/SDA Pin 7 SDO
Pin 8 RB2/SDO/CCP1 Pin 6 REQ/1W
Pin 10 RB4/SCK/SCL Pin 2 SCK
Pin 11 RB5/SS Pin 1

Pin 3 and Pin 5 of QT300 connected to sensor.
IS my connection right?
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Fri Aug 20, 2004 1:29 pm     Reply with quote

Ok I find out on application sheet
Guest








PostPosted: Fri Aug 20, 2004 2:27 pm     Reply with quote

As I posted
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 20, 2004 2:55 pm     Reply with quote

I think you want someone to write a driver for you.
Quantum has a forum:
http://www.qprox.com/forum/list.php?f=1
You should post a message on that forum, and
ask for C source code for a driver for the QT300.

They have an Evaluation board, the EA3, which has
a PIC 16LF73 on it. It runs the QT300 chip. Here
is the Evaluation board manual with a full schematic.
http://www.qprox.com/downloads/manuals/e3a_101.pdf
Ask them for the source code for the PIC on that
evaluation board.

Their forum will be your best resource.
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Fri Aug 20, 2004 4:35 pm     Reply with quote

I have a sample and have tested it with a small routine.
The main point with this chip is that the spi clock frequency must be below about 40kHz, so timer 2 division was required.
Also, a 10k pullup resistor is needed on DRDY.
The output is logarithmic and decreases with increase in capacitance.

The data sheet is a bit short of information.
I found this post helpful:
http://www.qprox.com/forum/read.php?f=1&i=701&t=699#reply_701

My test routine
Code:

#include <16f876.h>
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP

#define REQ PIN_C0
#define DRDY PIN_C1  // 10k pullup required

void main(void)
{
   int32 temp32;
   int8 hibyte,lobyte;

   // Need spi clock with clock pulse width of >12uS or 24uS total period with
   // space. ie. below about 40kHz. Can't get this with Fosc division, so have
   // to use timer 2 option.
   // T2 is usually used for tick counter 1mS (1kHz) and spi clock is this
   // divided by 2 ie. 500Hz.

   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_T2);

   // System 1ms tick.
   // The cycle time will be (1/clock)*4*t2div*(period+1)
   // In this program clock=16,000,000 and period=249
   // (1/16000000)*4*16*250=1000 us or 1kHz)
   setup_timer_2(T2_DIV_BY_16,249,1);
   // Edited to give a more reliable powerup
   output_bit(REQ,1);
   output_float(DRDY);
   delay_ms(1000);

   // Chip starts acquiring data on it's own at power up.
   // Looks like it doesn't pull DRDY low when finished.
   // Do dummy reads to get it to go back to sleep (says
   // so in data sheet).
   
   hibyte = spi_read(0);
   delay_us(50);           // >12uS
   lobyte = spi_read(0);
   output_float(DRDY);
   delay_ms(1);
 
   while(1)
   {
      output_bit(REQ,0);
      delay_us(50);           // >30uS
      output_bit(REQ,1);
      while(input(DRDY));
      hibyte = spi_read(0);
      delay_us(15);           // >12uS
      lobyte = spi_read(0);
      output_float(DRDY);
      temp32 = ((int32) hibyte << 8) + (int32) lobyte;
      printf("%3u %3u %8lu\n\r",hibyte,lobyte,temp32);
      delay_ms(100);

   }
}


Last edited by Kenny on Sun Sep 05, 2004 9:42 pm; edited 2 times in total
Guest








PostPosted: Mon Aug 23, 2004 9:23 am     Reply with quote

Thank you kenny and PCM:
Is that you connected like this way as your program shown:

DRDY C1 //10k pull up
REQ C0
sck sck
sdi sdo

I used 16f819 so I connected

DRDY RB5
REQ RB6
sck sck
sdi sdo
and changed the program accordingly, but I could not get nothing. It looks that the program is loop somewhere in
while(input(DRDY));

would you provide me some more advice about it
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 23, 2004 10:23 am     Reply with quote

Did you put the pullup on the DRDY line? Did you change the DRDY #define?
Guest








PostPosted: Mon Aug 23, 2004 10:31 am     Reply with quote

Yes I did.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 23, 2004 11:34 am     Reply with quote

Post you test program to make sure that you haven't overlooked something.
Guest








PostPosted: Mon Aug 23, 2004 12:22 pm     Reply with quote

Thank you Mark, here is the program:

Code:

#if defined(__PCM__)
#include <16F819.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, parity=N, xmit=PIN_B7, rcv=PIN_B6)  // Jumpers: 8 to 11, 7 to 12

//#include <lcd420_1.c>
//#include <math.h>
void LCDSetGeometry();
void LCDReset();
void LCDinit();
void LCDSetCursorPos(int8 x, int8 y);

#define REQ PIN_A6
#define DRDY PIN_B5

void main()
{
//  setup_comparator(NC_NC_NC_NC);
  int16 Capa;  //capacitor data on  sensors;
  int8 hibyte,lowbyte;
 // set_comparator(NC_NC_NC_NC);
  Capa=0;
  LCDinit();
  setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_T2);
  setup_timer_2(T2_DIV_BY_16,249,1);

  output_high(REQ);
  output_float(DRDY);
  delay_ms(1);

while(1)
{
  // LCDOnOff(1);LCDTab();
  LCDSetCursorPos(1, 0);  //1 col 0 row
  puts("Capacity Read\n");

  //read QT300
  output_low(REQ);
  delay_us(35);
  output_high(REQ);
  while(input(DRDY));
  hibyte=spi_read(0);
  delay_us(15);
  lowbyte=spi_read(0);
  output_float(DRDY);
  Capa=((int32)hibyte<<8)+(int32)lowbyte;
 
  LCDSetCursorPos(1, 1);
  printf("C=%lu", Capa);
  delay_ms(100);
}

}

void LCDSetGeometry()
{
   putc(15);
   delay_ms(10);
   putc(16);
      delay_ms(10);
   putc(0x80);
      delay_ms(10);
   putc(0xc0);
      delay_ms(10);
   putc(0x80);
      delay_ms(10);
   putc(0x80);
      delay_ms(10);
}

void LCDReset()
{
   putc(14);
   delay_ms(1000);

}
void LCDinit()
{
   // Set LCD Geometry
   LCDSetGeometry();
   // LCDReset
   LCDReset();
}

void LCDSetCursorPos(int8 x, int8 y)
{
   putc(17);
   putc(y);
   putc(x);
   delay_ms(100);
}


when I did not marked off while(input(DRDY)); on the LCD only CApacity Read shown, if I marked off while(input(DRDY)); C=65535 shown on LCD also.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 23, 2004 12:46 pm     Reply with quote

You said that
Quote:

DRDY RB5
REQ RB6


Did you mean that REQ was on RA6?
Guest








PostPosted: Mon Aug 23, 2004 1:16 pm     Reply with quote

Yes, I found that Iused it as RS232 so, I changed it to Pin_A6
Guest








PostPosted: Mon Aug 23, 2004 2:10 pm     Reply with quote

I changed and test a litlle bit the program to see if it was the
Code:
 while(input(DRDR)

put the program into a endless loop, appearantly it is. so it means that the DRQY is not ready at all the time.

I also pullup REQ, pulldownSCK and SDO with a 10k resistor.
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Mon Aug 23, 2004 10:28 pm     Reply with quote

I saw your post on the Quantum forum. Perhaps by using the cloning adaptor you have placed the chip into spi master mode. If so, return it to the default spi slave mode. I don't have these tools so can't comment on their use.

Edited on 26th August 2004:
For the archives, here is the link to the C source referred to by PCM Programmer. It was given in reply to Young's request on the Quantum forum. The code uses bit-banging for the spi and may be useful to anyone wanting to use this chip with a pic that doesn't have the MSSP module.

Quote:
To get the C code for the SPI
log on to our ftp server at ftp://81.2.82.89

username:anonymous
password:[your email address]

make sure you connect using 'port' connection not 'pasv'. The file you need is in the folder Design_files/LCD_spi.zip

Unquote.

Nice to see that they also use CCS :-)


Last edited by Kenny on Sun Sep 05, 2004 9:33 pm; edited 2 times in total
Guest








PostPosted: Tue Aug 24, 2004 7:29 am     Reply with quote

Hi Kenny:
How do you decide master chip (16f819) timer2 to setup SPI speed, MSB/LSB spacing, span width and accquisition speed? I think it might be here that I made something wrong.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group