Hi All,
I am interfacing ADS7825 to AT90USB1286 in Parallel mode please see below circuit diagram. But i can't read the correct data.
Can any one tried this successfully any sample code to read the data.
i have few questions, before giving the questions let me put my work details here.
1. I connected two nos of 2.2uF/35V Tantalum Capacitors one on 6th pin to ground and another is on 7th pin to ground.
2. I made CONTC=0 i.e. manual mode.
3. I am using AT90USB1286 MIcro controller to read the data.
4. I connected AGND1, AGND2 and DGND to same ground(please see below circuit diagram).
5. I am giving 0 to 1.5V to ADC Channel 1 (i.e. AIN0 )for testing purpose only. But actually i will give +/-10v to all four channels
of ADC.
6. I measured 2.502V at Vref to ground.
MY CODE is:
/**
** crystal frequency is 11.0592Mhz
** microcontroller is AT90USB1286
** programming tool Atmel studio 6.2
**/
#include <avr/io.h>
#include <math.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <string.h>
#include <inttypes.h>
#define F_CPU 11059200UL
#define cnstt 0
#define slope 3276.7
#define LCD_DPRT PORTA // LCD DATA PORT
#define LCD_DDDR DDRA // LCD DATA DDR
#define LCD_DPIN PINA // LCD DATA PIN
#define KEY_PRT PORTE // LCD DATA PORT
#define KEY_DDR DDRE // LCD DATA DDR
#define KEY_PIN PINE // LCD DATA PIN
#define LCD_RSOFF PORTD&=~(1<<PD5)
#define LCD_RSON PORTD|=(1<<PD5)
#define LCD_RWOFF PORTD&=~(1<<PD6)
#define LCD_RWON PORTD|=(1<<PD6)
#define LCD_EOFF PORTD&=~(1<<PD7)
#define LCD_EON PORTD|=(1<<PD7)
#define A_zeroOFF PORTD &=~(1<<PD0) // channel selection of adc A0 is low
#define A_zeroON PORTD |=(1<<PD0) // channel selection of adc A0 is high
#define A_oneOFF PORTD &=~(1<<PD1) // channel selection of adc A1 is low
#define A_oneON PORTD |=(1<<PD1) // channel selection of adc A1 is high
#define RC_OFF PORTD &=~(1<<PD2)
#define RC_ON PORTD |=(1<<PD2)
#define BYTE_MSB PORTD &=~(1<<PD4)
#define BYTE_LSB PORTD |=(1<<PD4)
//unsigned int readinput;
signed int msbbits,lsbbits;
signed int i,count,cnt;
double in;
char itmp[20];
void lcd_chone();
void lcd_chtwo();
void lcd_chthree();
void lcd_chfour();
void adcinit_readdata();
void lcd_init();
void lcd_print(char * str);
void lcdCommand(unsigned char cmnd);
void lcdData(unsigned char data);
void lcd_gotoxy(unsigned char x, unsigned char y);
//********************************************* Main function starts from here *******************************************//
int main (void)
{
unsigned char upperNibble, keyCode,i;
unsigned int readinput;
DDRB=0xFF;
DDRD=0xF7;
DDRE=0x00;
msbbits=0;
lsbbits=0;
cnt=0;
count=0;
in=0.0;
readinput=0;
lcd_init();
_delay_ms(50);
lcdCommand(0x01)
while(1)
{
lcd_chone();adcinit_readdata();
//lcd_chtwo();adcinit_readdata();
//lcd_chthree();adcinit_readdata();
//lcd_chfour();adcinit_readdata();
}
}
//******************************* functions of ADC Channels 1,2,3,4 respectively**************************************//
void lcd_chone()
{
CH1_LOW;
//lcd_gotoxy(1,1);
//lcd_print(" CH1 MEASURE");
A_zeroOFF;
_delay_us(1);
A_oneOFF;
}
void lcd_chtwo()
{
CH2_LOW;
lcd_gotoxy(1,1);
lcd_print(" CH2 MEASURE");
A_zeroON;
_delay_us(1);
A_oneOFF;
}
void lcd_chthree()
{
CH3_LOW;
lcd_gotoxy(1,1);
lcd_print(" CH3 MEASURE");
A_zeroOFF;
_delay_us(1);
A_oneON;
}
void lcd_chfour()
{
CH4_LOW;
lcd_gotoxy(1,1);
lcd_print(" CH4 MEASURE");
A_zeroON;
_delay_us(1);
A_oneON;
}
//********************************************* LCD functions **************************************//
void lcdCommand(unsigned char cmnd)
{
LCD_DPRT = cmnd;
LCD_RSOFF;
LCD_RWOFF;
LCD_EON;
_delay_us(1);
LCD_EOFF;
_delay_us(100);
}
void lcdData(unsigned char data)
{
LCD_DPRT = data;
LCD_RSON;
LCD_RWOFF;
LCD_EON;
_delay_us(1);
LCD_EOFF;
_delay_us(100);
}
void lcd_init()
{
LCD_DDDR = 0xFF;
//LCD_CDDR = 0xFF;
LCD_EOFF;
_delay_us(2000);
lcdCommand(0x38);
lcdCommand(0x0E);
lcdCommand(0x01);
_delay_us(2000);
lcdCommand(0x06);
}
void lcd_gotoxy(unsigned char x, unsigned char y)
{
unsigned char firstCharAdr[]={0x80,0xC0,0x94,0xD4};
lcdCommand(firstCharAdr[y-1]+x-1);
_delay_us(100);
}
void lcd_print(char * str)
{
unsigned char i=0;
while(str[i]!=0)
{
lcdData(str[i]);
i++;
}
}
//***************************** 16-bit DATA transferring from ADC to MC Through Parallel Mode *****************************//
void adcinit_readdata()
{
RC_OFF; // RC LOW
_delay_us(5); // delay up to 5 Micro seconds
RC_ON; // RC ON
if(PIND & 0b00001000) // if BUSY Pin goes high then the data is ready to accumulate
{
BYTE_MSB; // BYTE=1
msbbits=PINE; // store the data available on PORTE into msbbits. Here, most MSB bits are available
BYTE_LSB; // Byte=0
lsbbits=PINE; // store the data available on PORTE into lsbbits. Here, Least LSB bits are available
count=msbbits<<8; // right shift the data 8 times
count=count+lsbbits; // now add count=count+lsbbits to get actual 16bit signed 2's complement digital value
in=(count-cnstt)/slope;
lcd_gotoxy(1,1);
ltoa(count, itmp, 10);
lcd_print(itmp);
lcd_gotoxy(1,2);
dtostrf(in,10,5,itmp);lcd_print(itmp);lcd_print("V ");
msbbits=0;
lsbbits=0;
count=0;
in=0.0;
}
else
_delay_us(10);
}
Therefore my problems are:
1. I am unable read the data from ADC.
2. Are the connections between AT90USB1286 to ADS7825 right?
3. Are there any mistakes in my code?
4. If I change the delay between RC_OFF to RC_ON from 5micro seconds to 25micro seconds and above
(see Case 2 below) i am getting strange data.
Case 1: Case 2:
RC_OFF; // RC LOW RC_OFF; // RC LOW
_delay_us(5); // delay up to 5 Micro seconds _delay_us(25); // delay up to 5 Micro seconds
RC_ON; // RC ON RC_ON; // RC ON
for example, I f i give 1V as i/p signal to AIN0 of ADS7825 it should be give digital count 3276 for +/-10V range.
But it doesn't give that value. it is giving a random value and that too value is changing continuously.
5. If i give the delay about 5 micro seconds (see Case 1), i am not getting any data.
please tell any one where i did mistake.
thank you in advance.
excuse me for bad english,