پاسخ : کتابخانهآای برای چیپ AD7780-AD7730
سلام
من از ad7715-5 برای بازه ولتاژ 0 تا 5 ولت میخوام استفاده کنم و برای این کار از کتابخونه زیر استفاده میکنم. ولی نمیدونم وقتی که اجرا میشه، به ازای زمین، 0 و به ازای 2.5، تقریبا 32700 نشون میده که دسته ولی به ازی ولتاژ 3.3 و 5 ولت، خروجی مقدار 65535 نشون میده که بالاترین مقداره.
موندم مشکل کارم از چیه
من با کامپایلر ccs کار میکنم و از میکر pic16f877a
این فایل برنامه :
#include <AD7715_2.c>
#define LCD_ENABLE_PIN PIN_D0
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_TYPE 2
#include <lcd.c>
void main()
{
lcd_init();
adc_init();
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
write_adc_byte( 0x10 ); //write to setup reg. is next op.,Gain=1
write_adc_byte( 0x68 ); //self-calibration,bipolar,2.4576MHz
delay_ms(3000);
int16 adc_value;
while(TRUE) {
adc_value=read_adc_value();
delay_ms(1000);
printf(lcd_putc,"The value:%lu",adc_value);
printf("%lu \r\n",adc_value);
delay_ms(1000);
lcd_clear();
}
}
اینم فایل کنابخونه ای که استفاده می کنم:
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
//// Driver routines for the AD7715 chip
#define ADC_CS PIN_C0
#define ADC_RESET PIN_C1
#define ADC_DRDY PIN_C2
#define ADC_DI PIN_C4
#define ADC_DO PIN_C5
#define ADC_CLK PIN_C3
void write_adc_byte(BYTE data);
void adc_init()
{
output_low(ADC_RESET);
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 read //operation,gain=1
write_adc_byte( 0x62 ); //Setup Register info here
write_adc_byte( 0x10 ); //write to setup reg. is next op.,Gain=1
write_adc_byte( 0x68 );//self-calibration,bipolar,2.4576MHz
}
void write_adc_byte(BYTE data) {
BYTE 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);
}
long int read_adc_word() {
BYTE i;
long data;
output_low(ADC_CS);
for(i=1;i<=16;++i) {
output_low(ADC_CLK);
output_high(ADC_CLK);
shift_left(&data,2,input(ADC_DO));
}
output_high(ADC_CS);
return data;
}
long int read_adc_value() {
long int value;
while ( input(ADC_DRDY) );
while ( !input(ADC_DRDY) );
while ( input(ADC_DRDY) );
write_adc_byte(0x3a);
value=read_adc_word();
return value;
}
سلام
من از ad7715-5 برای بازه ولتاژ 0 تا 5 ولت میخوام استفاده کنم و برای این کار از کتابخونه زیر استفاده میکنم. ولی نمیدونم وقتی که اجرا میشه، به ازای زمین، 0 و به ازای 2.5، تقریبا 32700 نشون میده که دسته ولی به ازی ولتاژ 3.3 و 5 ولت، خروجی مقدار 65535 نشون میده که بالاترین مقداره.
موندم مشکل کارم از چیه
من با کامپایلر ccs کار میکنم و از میکر pic16f877a
این فایل برنامه :
#include <AD7715_2.c>
#define LCD_ENABLE_PIN PIN_D0
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_TYPE 2
#include <lcd.c>
void main()
{
lcd_init();
adc_init();
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
write_adc_byte( 0x10 ); //write to setup reg. is next op.,Gain=1
write_adc_byte( 0x68 ); //self-calibration,bipolar,2.4576MHz
delay_ms(3000);
int16 adc_value;
while(TRUE) {
adc_value=read_adc_value();
delay_ms(1000);
printf(lcd_putc,"The value:%lu",adc_value);
printf("%lu \r\n",adc_value);
delay_ms(1000);
lcd_clear();
}
}
اینم فایل کنابخونه ای که استفاده می کنم:
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
//// Driver routines for the AD7715 chip
#define ADC_CS PIN_C0
#define ADC_RESET PIN_C1
#define ADC_DRDY PIN_C2
#define ADC_DI PIN_C4
#define ADC_DO PIN_C5
#define ADC_CLK PIN_C3
void write_adc_byte(BYTE data);
void adc_init()
{
output_low(ADC_RESET);
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 read //operation,gain=1
write_adc_byte( 0x62 ); //Setup Register info here
write_adc_byte( 0x10 ); //write to setup reg. is next op.,Gain=1
write_adc_byte( 0x68 );//self-calibration,bipolar,2.4576MHz
}
void write_adc_byte(BYTE data) {
BYTE 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);
}
long int read_adc_word() {
BYTE i;
long data;
output_low(ADC_CS);
for(i=1;i<=16;++i) {
output_low(ADC_CLK);
output_high(ADC_CLK);
shift_left(&data,2,input(ADC_DO));
}
output_high(ADC_CS);
return data;
}
long int read_adc_value() {
long int value;
while ( input(ADC_DRDY) );
while ( !input(ADC_DRDY) );
while ( input(ADC_DRDY) );
write_adc_byte(0x3a);
value=read_adc_word();
return value;
}
دیدگاه