Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] SPI reading another ADC channel

Status
Not open for further replies.

karbiuch

Junior Member level 1
Joined
Feb 10, 2016
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
208
Hi!

I wrote simply program to read data from Ad7739 (24bit adc) to atmega. My program works, but has one bug. Program is able to read data only from one channel. I cant read voltages from another channels. I think I do not understand datasheet becouse the SPI code works. It's probably a problem with correct sending channels addresses.
HTML:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7739.pdf

code looks like this, it gets correctly data from channel 0. But this code doesnt work for chanel 4. Where is problem? Do I put bad byte adress?

Code:
	PORTB|=_BV(ADCVCS);


	spi_hw_adcV_data_send(ADCCHANEL0);									
        //mode register //#define ADCCHANEL0	0x38
	PORTB|=_BV(ADCVCS);

	spi_hw_adcV_data_send(0x4A);									//- 
        //single conversion; dump mode, 24bit mode
	PORTB|=_BV(ADCVCS);

	while(SPIPIN & _BV(ADCRDYVPIN));

	spi_hw_adcV_data_send(READADC0);								 
        //data register; ch0 //#define READADC0	0x48
	PORTB|=_BV(ADCCS);
	SPIPORT&= ~_BV(ADCVCS);
	SPDR=0x00;
	while((SPSR & _BV(SPIF)) == 0);
	SPSR |= _BV(SPIF);
	cData=SPDR;
	SPIPORT|=_BV(ADCVCS);
	vstatus = cData; //reading status

	SPIPORT&= ~_BV(ADCVCS);
	SPDR=0x00;
	while((SPSR & _BV(SPIF)) == 0);
	SPSR |= _BV(SPIF);
	cData=SPDR;
	AdcVFrame[2]=cData;							//first byte 1/3
	SPIPORT|=_BV(ADCCS);
	PORTB|=_BV(ADCVCS);
	
	SPIPORT&= ~_BV(ADCVCS);
	SPDR=0x00;
	while((SPSR & _BV(SPIF)) == 0);
	SPSR |= _BV(SPIF);
	cData=SPDR;
	SPIPORT|=_BV(ADCCS);
	PORTB|=_BV(ADCVCS);
	AdcVFrame[1]=cData;							//second byte 2/3

	SPIPORT&= ~_BV(ADCVCS);
	SPDR=0x00;
	while((SPSR & _BV(SPIF)) == 0);
	SPSR |= _BV(SPIF);
	cData=SPDR
	SPIPORT|=_BV(ADCCS);
	PORTB|=_BV(ADCVCS);
	AdcVFrame[0]=cData;							//last byte 3/3

	if(vstatus& _BV(OVR))
	{ //error reading
		if(vstatus& _BV(SIGN))
		{
			AdcVFrame[1] = 0x00;
			AdcVFrame[0] = 0x00;
                        AdcVFrame[2] = 0x00;
		}
		else
		{
			AdcVFrame[1] = 0xff;
			AdcVFrame[0] = 0xff;
                        AdcVFrame[2] = 0xff;
		}
	}
	uartput(AdcVFrame[2]) ; //byte3
	uartput(AdcVFrame[1]) ; //byte2
	uartput(AdcVFrame[0]) ; //byte1

But this code doesnt work for chanel 4. Where is problem? I put bad adress of channel 4?
Could anyone tell my what values should have "communication register, mode register, comunnication register" to read correct from example chanel 4?
Sometimes I have in data only 0xFFFFFF. Do I make mistake on reading vstatus data?

Page 22
HTML:
 http://www.analog.com/media/en/technical-documentation/data-sheets/AD7739.pdf
#define ADCCHANEL0 0x38
#define ADCCHANEL4 0x3c
#define READADC0 0x48
#define READADC4 0x4c
 
Last edited:

Hi,

I didn't read the datasheet.
But "24 bit" usually means "delta sigma" technology.
When you switch the input channel of a delta sigma ADC, then it takes reltiveky long time until valid data is present at the output.
This is caused by the delta sigma modulator and the digital filters...

Did you read the datasheet how to know if the output data is valid or not ... after a new channel is selected.

If you need fast channel switching, then look for ADC with simultaneous channel sampling, or use a SAR ADC.

Klaus
 

I think, I know that. To verify information i must check status register. I do it on vstatus variable.
My problem is problem to read correct voltage value from another channel. On each channel i have voltage divider, So I know the voltage value for each channel. My code works only for one channel 0. For example channel 4 doest work properly. If I can read correcly voltage value for channel 0, I think the SPI code work fine.Apparently I write wrong address of other channels.

"1 Sign This bit reflects the voltage polarity at the analog input. It is
0 for a positive voltage and 1 for a negative voltage"

"0 OVR This bit reflects either the overrange or the underrange on the analog input. The bit is set to 1 when the analog input voltage goes over or under the nominal voltage range (see the Extended Voltage Range of the Analog Input section)."
 

I think i know how to valid data. I check variable vstatus. For each channel I have a unique voltage divider. I think my problem is write correct adress for other channels (1-7). Channel 0 is working becouse i write data adress from datasheet. It seems to me that I made mistakes in the interpretation of datasheet.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top