|
|
View previous topic :: View next topic |
Author |
Message |
bloureiro
Joined: 26 Feb 2007 Posts: 6
|
AD7714 Driver Help!! |
Posted: Wed Mar 07, 2007 6:26 am |
|
|
Hi
I'm trying make the driver for AD7714, I've two problems.
The driver is working the basic.
The i can read the channels but i try read the channel 2 the adc send-me the value of channel 1.
The another problem is when I try read some channel I need use self-calibration first and then read the value.
the self-calibration put the program slow.
Code: |
//*************************************************************
// Driver routines for the AD7714 chip, by ToHu
// write_adc_byte()
// adc_init()
// read_adc_word()
// read_adc_value()
//*************************************************************
//connection pins to the PIC
#define ADC_DRDY PIN_B1
#define ADC_DO PIN_B2
#define ADC_DI PIN_B3
#define ADC_RESET PIN_B4
#define ADC_CS PIN_B5
#define ADC_CLK PIN_B6
void write_adc_byte(int data)
{
int i;
output_low(ADC_CS);
for(i=1;i<=8;++i)
{
output_low(ADC_CLK);
output_bit(ADC_DI, shift_left(&data,1,0));
output_high(ADC_CLK);
}
output_high(ADC_CS);
}
adc_init()
{
output_low(ADC_RESET);
output_high(ADC_CLK);
output_high(ADC_CS); //Set low to AD7714 chip select low pin
output_high(ADC_RESET); //Set high to AD7714 reset low pin
delay_ms(2000);
write_adc_byte(0x27); //to com.register, chanel & filter Hi antes 24----27 datacheat
write_adc_byte(0xC0); //to filter hi register 0xCF gasta menos do sinal analogico 4F data cheat
write_adc_byte(0x37); //to com.register, chanel & filter low antes 30 37 data cheat
write_adc_byte(0x13); //to filter low register 00 antes-------------------------------A0 data cheat
write_adc_byte(0x17); //to com register, chanel & mod register 17 data cheat
write_adc_byte(0x20); //to mod register, self test---------------------------20
}
int32 read_adc_word()
{
int i;
int32 data;
output_low(ADC_CS);
for(i=1;i<=24;++i)
{
output_low(ADC_CLK);
output_high(ADC_CLK);
shift_left(&data,3,input(ADC_DO));
}
output_high(ADC_CS);
return data;
}
int32 read_adc_value(int canal)
{
int32 value;
//while ( input(ADC_DRDY) );
//while ( !input(ADC_DRDY) );
while ( input(ADC_DRDY) ); // Loop until data is ready
switch(canal)
{
case 1:
write_adc_byte(0x10); //to com register, chanel & mod register
write_adc_byte(0x20); //to mod register, self test
write_adc_byte(0x58);//communications register set to read AIN1
break;
case 2:
write_adc_byte(0x11); //to com register, chanel & mod register
write_adc_byte(0x20); //to mod register, self test
write_adc_byte(0x59);//communications register set to read AIN2
break;
case 3:
write_adc_byte(0x12); //to com register, chanel & mod register
write_adc_byte(0x20); //to mod register, self test
write_adc_byte(0x5A);break;
case 4:
write_adc_byte(0x13); //to com register, chanel & mod register
write_adc_byte(0x20); //to mod register, self test
write_adc_byte(0x5B);break;
case 5:
write_adc_byte(0x16); //to com register, chanel & mod register
write_adc_byte(0x20); //to mod register, self test
write_adc_byte(0x5E);break;
}
value=read_adc_word();
return value;
}
float convert_to_volts(int32 temp){
return (float)temp*0.000000149;
}
|
Thanks |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Mar 07, 2007 8:57 am |
|
|
Quote: |
The i can read the channels but i try read the channel 2 the adc send-me the value of channel 1.
|
The AD is performing according to the code.
In the switch statement, you are consulting the Ch2 but addressing Ch1
(0x11 should be 0x12)
Code: |
case 2:
write_adc_byte(0x11); //to com register, chanel & mod register
|
You should load the communication register outside of the switch statement
with the value 0x0F/0x6F and then polling waiting that RDY become true, then you
can read each input channel inside the switch()
Humberto |
|
|
|
|
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
|