|
|
View previous topic :: View next topic |
Author |
Message |
ac34856
Joined: 14 Dec 2009 Posts: 33 Location: Wales
|
AD7715 CCS driver annoying problem |
Posted: Mon Jan 25, 2010 9:58 am |
|
|
I've been testing the AD7715 which is the last thing I need to complete
a piece of code. This uses the driver supplied by CCS but so far I can
only get the program to output 0x00ff from the ADC.
If anyone has any ideas it would be much appreciated ... so I can get
this finished. Other bits work fine.
All of the signals appear to be correct and present - and the reference
voltage is 2.5V with a pot providing 0 to 2V input. The MCLK input is
1MHz.
As data is read out I am assuming it may be something to do with
the commands to setup the device. I put in a #define CLK_DEL to stretch out the clock and other SPI signals so this can be ignored as its set to
zero.
Compiler is 4.088
Code: |
//*********************************************************//
// Skeleton program for reading AD7715 using S/W SPI //
//*********************************************************//
#include <18F4620.h>
#device PASS_STRINGS=IN_RAM
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP
#use DELAY(CLOCK=20000000) // , OSC=10000000)
#use RS232(BAUD=115200, PARITY=N, XMIT=PIN_C0, BITS=8, ERRORS, RESTART_WDT, STREAM=COM1)
//#use SPI(MASTER, DO=PIN_C5, DI=PIN_C4, CLK=PIN_C3,
// MSB_FIRST, MODE=0, BITS=16, STREAM=SPI_0)
#define LED PIN_D0
#define ADC_CS PIN_B0
#define ADC_RESET PIN_B1
#define ADC_DRDY PIN_B2
#define ADC_CLK PIN_B3
#define ADC_DI PIN_B4
#define ADC_DO PIN_B5
#define CLK_DEL 0 // Number of delay cycles of clock
void adc_init(void);
void write_adc_byte(BYTE);
int16 read_adc_value(void);
int16 read_adc_word(void) ;
int main(void)
{
int16 data = 0;
int16 adval = 0;
int16 count;
fprintf(COM1, "\r\n ** PROGRAM STARTING ** ");
adc_init();
fprintf(COM1, "\r\n ADC Reset (SPI Running !)");
// write_adc_byte(0x3a); // This is normally to access data
while(1)
{ output_toggle(LED);
adval = read_adc_value();
fprintf(COM1, "\r\n %Ld - Version 1.11 ADC Test : %04x", count++, adval);
}
}
void adc_init(void)
{
output_low(ADC_RESET);
delay_ms(500);
output_high(ADC_CLK);
output_high(ADC_CS);
// Set low to AD7715 chip select low pin
output_high(ADC_RESET);
// Set high to AD7715 reset low pin
delay_ms(3000);
write_adc_byte( 0x12 ); // Communications Register
write_adc_byte( 0x62 ); // Setup Register info here
}
void write_adc_byte(BYTE data) {
BYTE i;
output_low(ADC_CS);
delay_us(20);
for(i=1;i<=8;++i)
{ output_low(ADC_CLK);
delay_us(CLK_DEL);
output_bit(ADC_DI, shift_left(&data,1,0));
output_high(ADC_CLK);
delay_us(CLK_DEL);
} output_high(ADC_CS);
}
int16 read_adc_word(void)
{
BYTE i;
long data;
output_low(ADC_CS);
delay_us(CLK_DEL);
for(i=1;i<=16;++i)
{
output_low(ADC_CLK);
delay_us(CLK_DEL);
output_high(ADC_CLK);
delay_us(CLK_DEL);
shift_left(&data, 2, input(ADC_DO));
delay_us(CLK_DEL);
}
delay_us(CLK_DEL);
output_high(ADC_CS);
return(data);
}
int16 read_adc_value()
{
int16 value;
while ( input(ADC_DRDY) );
while ( !input(ADC_DRDY) );
while ( input(ADC_DRDY) );
write_adc_byte(0x3a);
value = read_adc_word();
return(value);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 25, 2010 11:26 am |
|
|
Quote: | int16 adval = 0;
fprintf(COM1, "\r\n %Ld - Version 1.11 ADC Test : %04x", count++, adval); |
To display an 'int16', you need to use "%lx" in the format string.
(That's a lower case L). |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jan 25, 2010 12:03 pm |
|
|
Seems like you're setting a gain of 32 (in communication register) and MCLK of 2.45 MHz (in setup register). |
|
|
ac34856
Joined: 14 Dec 2009 Posts: 33 Location: Wales
|
|
Posted: Tue Jan 26, 2010 3:45 am |
|
|
Thanks for both comments. It turned out to be something more fundamental and as usual human error - the IC I bought was a 3.3V version, so now I've got the right one its fixed.
As ever always read the small print - |
|
|
|
|
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
|