2

I want to run AD7705 by ATMEGA8 microcontroller and I used the following C.code: `

DDRB = 0x6e;     //PinB.1(DRDY')=output , PinB.2(SS')=output , PinB.3(MOSI) = output , PinB.4(MISO)=input , PinB.5(SCK)=output , PinB.6(Reset') = output
PORTB = 0x91;//outputs=0 & inputs= pullup

if (EXTRF == 1) {PORTB.6=0;delay_ms(1);}//Reset the ADC with Reseting the micro

SPCR = 0x70;//SPI Enabled, MSB Data Order, Master, Sampling by Rising Edge, SCKF=fosc/4

SPSR = 0x00;

//Serially reset the Chip 
for (j = 0; j < 5; j++)
{
    SPDR = 0xff;
    delay_ms(10);
}
while(!(SPSR & (1<<SPIF)));//wait for transfer

SPDR = 0b00100000;//Send to Comm Reg: Next Write Clk =0x20
while(!(SPSR & (1<<SPIF)));//wait for transfer

SPDR = 0b00000100;//Send to ClkReg: Clock Bits and Update rate =0x04 ->CLKDIV=0,CLK=1,Filter Selection=00(output update rate = 50Hz)
while(!(SPSR & (1<<SPIF)));//Wait for transfer 

SPDR = 0b00010000;//Send to Comm Reg: Next Write Setup reg =0x10 
while(!(SPSR & (1<<SPIF)));//Wait for transfer

// set setup register: Self Calibration Mode,gain=1,
// unipolar operation,buffer enabled,
// filter synchronization in set state =0x06
SPDR = 0b01000110;
while(!(SPSR & (1<<SPIF)));//Wait for transfer

SPDR = 0b00001000;//Send to Comm: next read Comm reg =0x08 
while(!(SPSR & (1<<SPIF)));//Wait for transfer        

SPDR = 0b00111000;//Send to Comm: next read Data reg =0x38 MS-Byte
while(!(SPSR & (1<<SPIF)));//Wait for transfer

read = SPDR;

SPDR = 0b00111000;//send to Comm: next read Data reg =0x38 LS-Byte
while(!(SPSR & (1<<SPIF)));//Wait for transfer

read <<= 8//shift to MS-Byte of int read
read = read|SPDR;// make 16 bit data
read2 = read;    
read2 = (read2*2.5)/65535;
ftoa(read2,6,str);
lcd_gotoxy(0,1);
lcd_puts("V=");
lcd_gotoxy(2,1);
lcd_puts(str);

my problem is that in output I always get constant number(2.00 or 2.22)! I don't know what should I change to get correct output. as reference voltage I put 2.5 V and to power up the AD7705 I put 3 V. gain=1,update rate=50 Hz, channel 1, Uni polar, clock=2.4576 MHz AD7705 with ATMEGA8A

Mike
  • 4,041
  • 6
  • 20
  • 37
  • 4
    `read=read*255` is expected to shift the value to the most significant byte? Seems wrong; I was expecting `read=read*256` or `read <<= 8`. – Ruud Helderman Aug 27 '18 at 11:11
  • Get rid of the floating point, it isn't needed. – Lundin Aug 27 '18 at 11:12
  • In [this code sample](https://www.avrfreaks.net/forum/interfacing-ad7705-atmega8#comment-287631), the reset is transmitted 5 times, followed by a delay. On bare metal, this may well be relevant. – Ruud Helderman Aug 27 '18 at 15:20
  • is read int or float? – Mike Aug 28 '18 at 07:17
  • read is integer.thanks for your comment! so I should use itoa instead of ftoa but now I have following error in codevision compiler:"function argument #2 of type 'int' is incompatible with required parameter of type 'unsigned char *" – Fatemeh Sabaghian Aug 28 '18 at 08:13
  • `itoa(read, str)`, right? – Ruud Helderman Aug 28 '18 at 08:47
  • if read2 is an int, you couldn't something like that:read2=(read2*2.5)/65535; – Mike Aug 28 '18 at 10:02
  • yes, I wanted to do like that but then instead of that I defined 'read2' as float and edited the code as above. – Fatemeh Sabaghian Aug 28 '18 at 10:04
  • by the way, I still have the problem about getting a constant number (2.500000) in out put !! I wonder what should I change!! – Fatemeh Sabaghian Aug 28 '18 at 10:10
  • Could be a timing issue. Before reading from data register, shouldn't you poll /DRDY to give the AD7705 the time it needs to do its job? I compared your code with the reference flow chart in the AD7705's data sheets, and it looks like you are cutting some corners. This may mean that you are reading data that has not settled down yet. – Ruud Helderman Aug 28 '18 at 15:57

0 Answers0