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

Source code for ad7705,can't read data form ch1.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kuosda
Guest







Source code for ad7705,can't read data form ch1.
PostPosted: Thu Apr 03, 2003 9:48 pm     Reply with quote

#include <18F452.h>
#FUSES HS,NOOSCSEN,NOBROWNOUT,NOWDT,NOPUT
#USE DELAY(CLOCK=8000000)
#USE RS232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7,BITS=8,PARITY=N)

#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

#define ADC_NORMAL 0x00
#define ADC_SELF 0x40
#define ADC_ZERO_SCALE 0x80
#define ADC_FULL_SCALE 0xc0

#define ADC_GAIN_1 0x00
#define ADC_GAIN_2 0x08
#define ADC_GAIN_4 0x10
#define ADC_GAIN_8 0x18
#define ADC_GAIN_16 0x20
#define ADC_GAIN_32 0x28
#define ADC_GAIN_64 0x30
#define ADC_GAIN_128 0x38

#define ADC_BIPOLAR 0x04
#define ADC_UNIPOLAR 0x00

#define ADC_50 0x04
#define ADC_60 0x05
#define ADC_250 0x06
#define ADC_500 0x07

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;
}

void setup_adc_device(int calmode, int gainsetting, int operation, int rate)
{
write_adc_byte( 0x20 );//Communications Register set to write of clock register
write_adc_byte( 0x0C );//Clock Register info here
write_adc_byte( rate );//Clock Register info here
write_adc_byte( calmode|gainsetting|operation);//Setup Register info here
}

void adc_init()
{
output_low(ADC_RESET);
output_high(ADC_CLK);
output_high(ADC_CS);
output_high(ADC_RESET);
setup_adc_device(ADC_SELF,ADC_GAIN_1,ADC_BIPOLAR,ADC_50);
delay_ms(3000);
}

long int read_adc_value(int1 ch)
{
long int value=0;
while ( !input(ADC_DRDY) );
if(ch)
write_adc_byte(0x38);//read of channel 1
else
write_adc_byte(0x39);//read of channel 0

value=read_adc_word();
while ( input(ADC_DRDY) );
return value;
}

void adc_disable()
{
write_adc_byte( 0x20 );
write_adc_byte( 0x10 );
}

float convert_to_volts(long data){
return ((float)data*2.5/0xffff);
}

main() {

static long AD_CH0=0,AD_CH1=0;

DELAY_MS(80);
printf("POWER ON\n\r");

while(true)
{
adc_init();
AD_CH0 = read_adc_value(0);
AD_CH1 = read_adc_value(1);
printf("CH0:\%04LX CH1:\%04LX \r\n",AD_CH0,AD_CH1);
adc_disable();
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13388
Sherpa Doug
Guest







Re: Source code for ad7705,can't read data form ch1.
PostPosted: Fri Apr 04, 2003 10:06 am     Reply with quote

:= while(true)
:= {
:= adc_init();
:= AD_CH0 = read_adc_value(0);
:= AD_CH1 = read_adc_value(1);
:= printf("CH0:\%04LX CH1:\%04LX \r\n",AD_CH0,AD_CH1);
:= adc_disable();
:= }
:=}

What output do you get from CH0 & CH1?
Do you need a delay between the two read_adc_value statements for the A/D front end to settle?


___________________________
This message was ported from CCS's old forum
Original Post ID: 13404
championx



Joined: 28 Feb 2006
Posts: 151

View user's profile Send private message

PostPosted: Thu May 22, 2014 9:49 am     Reply with quote

im having de exact same problem? does enyone fixed this? i need to use the 2 channels.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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