View previous topic :: View next topic |
Author |
Message |
rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
about ADIS16201 Programmable Dual-Axis Inclinometer / Accele |
Posted: Wed Aug 01, 2007 2:17 pm |
|
|
is there anyone worked about ADIS16201 Programmable Dual-Axis Inclinometer / Accelerometer. i have searched all aplication notes on the net but i cant find anything with CCS PIC C
thanks everybody _________________ live fast, never rest and do your best |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 03, 2007 5:38 pm |
|
|
This device has an SPI interface. The first thing you need to do is to
determine the SPI mode. Look at Figure 3 (on page 5) of the data sheet.
http://www.analog.com/UploadedFiles/Data_Sheets/ADIS16201.pdf
It shows the idle state of SCLK is a high level. It also shows that the
rising edge of SCLK is used to sample the input data (DIN). With this
information, you can look at the chart on this link, and easily pick out
the SPI mode that the chip uses. It's mode 3.
http://www.totalphase.com/support/articles/article03/#modes
The next thing is to determine the maximum allowable frequency for
SCLK. This information is also shown on page 5 of the data sheet,
at the top of the Timing Specifications chart. The parameter is called
"fSCLK". It lists the max frequency as 2.5 MHz.
You didn't list the PIC that you're using or the oscillator frequency.
Let's assume it's a 16F877 running at 20 MHz. Look in the 16F877 data
sheet in the SPI section, on the Master mode. It says that the SCLK
is derived from the PIC's oscillator frequency, and can be divided by
either 4, 16, or 64. You can also find this information in the 16F877.H
file, in the SPI section. It gives the constants that can be used with the
setup_spi() function:
Code: |
#define SPI_CLK_DIV_4 0
#define SPI_CLK_DIV_16 1
#define SPI_CLK_DIV_64 2
|
It's clear that you can't use a divisor of 4, because that gives a 5 MHz
SCLK. It's too high. The max allowed is 2.5 MHz. So you've got to
use a divisor of 16. This will give you 20 MHz/16 = 1.25 MHz for SCLK.
Now you're almost ready to write the setup_spi() statement. It's much
easier to set the SPI mode if you use ckielstra's mode constants:
Code: |
#define SPI_MODE_0_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_0_1 (SPI_L_TO_H)
#define SPI_MODE_1_0 (SPI_H_TO_L)
#define SPI_MODE_1_1 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
|
Note that SPI mode 3 is represented in binary form above ("1_1").
After all that work, here is what you get:
Code: |
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_16 );
|
Now you can write the rest of the driver.
You can set the Chip Select signal low or high by using the CCS functions,
output_low() and output_high().
You can write 8-bits to the chip with spi_write(XX), and read from the
chip with value = spi_read(0). The 0 parameter must be present, to
generate an SCLK during the read operation. |
|
|
rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
|
Posted: Sat Aug 04, 2007 8:00 am |
|
|
thanks a lot pcm_programmer
i wrote this codes
Code: |
#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#include <lcd.c>
int16 value1, value2;
void main(){
init_lcd();
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4 );
for(;;){
value1=spi_read(0x0C); //for x axis tilt
value2=spi_read(0x0E); //for y axis tilt
lcd_gotoxy(1,1);
printf(lcd_putc, "x=%lu y=%lu ",value1,value2);
}
}
|
but im not sure that it is enough to read the tilt datas from deviece.
is there any mistakes on my code.
i read 0x0E and 0x0C hexadecimals on datasheet and they are adresses but i thing with these codes i ll wrote only 0x0E and 0x0C hexadecimals codes to the deviece. _________________ live fast, never rest and do your best |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 04, 2007 10:10 am |
|
|
You have to read the ADIS16201 and write a real driver. The data sheet
shows the correct sequence of using the Chip Select, and spi write, and
spi read commands. You must follow the data sheet exactly. |
|
|
rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
|
Posted: Tue Nov 27, 2007 7:21 pm |
|
|
PCM programmer wrote: | You have to read the ADIS16201 and write a real driver. The data sheet
shows the correct sequence of using the Chip Select, and spi write, and
spi read commands. You must follow the data sheet exactly. |
hi again PCM programmer;
i have read both datasheets adis16201 and pic16f877 carefully and try to write these codes.
i ll be very happy if u take a look on my codes. i cant try this codes on the board because still i cant find any adis16201 on manufacturers
Code: |
#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#include <lcd.c>
int16 value2;
void main(){
init_lcd();
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4 ); //spi mode 3 selected, spi clock is 1 mhz
for(;;){
output_low(pin_b0);
spi_write(0x0C0D); //according to datasheet to read x axis tilt value i must use 0x0C and 0x0D adressess
//but i m not sure that "spi_write(0x0C0D);" code is correct syntax??
output_high(pin_b0); //cs pin is high to stop writing sequence
delay_us(2); //cs pin is holded high for 2 microsecond
output_low(pin_b0); //to start reading sequence cs pin is low again
value2=spi_read(0); //for x axis tilt value
lcd_gotoxy(1,1);
printf(lcd_putc, " x=%lu ",value2);
}
}
|
Thank u for spending your time to me _________________ live fast, never rest and do your best |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 27, 2007 7:43 pm |
|
|
Quote: | spi_write(0x0C0D); |
The standard spi_write() function only sends one byte.
You're trying to send two bytes. You need to use two
spi_write() statements, one for 0x0C, and another one
to send the 0x0D. |
|
|
rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
|
Posted: Tue Nov 27, 2007 7:54 pm |
|
|
Quote: | The standard spi_write() function only sends one byte.
You're trying to send two bytes. You need to use two
spi_write() statements, one for 0x0C, and another one
to send the 0x0D. |
what about time delay between of two spi_write() commands.
is this delay brakes the spi clock syncronization. Code: |
.
.
output_low(pin_b0);
spi_write(0x0C);
spi_write(0x0D);
output_high(pin_b0);
delay_us(2);
.
. |
_________________ live fast, never rest and do your best |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 27, 2007 8:16 pm |
|
|
Why do you need it ? Each byte receives 8 clocks. The clock signal
goes to the idle state for a short time when it's between bytes. |
|
|
|