raosige
Newbie level 4
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:
Therefore my problems are:
1. I am able read the correct data from ADC but i am getting strange data.
2. Are the connections between AT90USB1286 to ADS7825 right?
3. Are there any mistakes in my code?
for example, I f i give 1V as i/p signal to AIN0 of ADS7825 it is giving digital count 3276(approx) for +/-10V range.
But whenever i change the input signal from 1v to 1.080 or 1.112 e.t.c. it is giving -9.8788V(with equivalent digital count) and some times it is giving an exact input voltage(i.e.when i change the input signal amplitude).
i can't understand what is happening.
please tell any one where did i mistake.
thank you in advance.
excuse me for bad english
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:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 /** ** 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]; char i_tmp[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(); } } //******************************* functions of ADC Channels 1,2,3,4 respectively**************************************// void lcd_chone() { CH1_LOW; A_zeroOFF; _NOP(); _NOP(); _NOP(); _delay_us(1); A_oneOFF; _NOP(); _NOP(); _NOP(); } //********************************************* 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(10); // delay up to 5 Micro seconds RC_ON; // RC ON _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); if(PIND & 0b00001000) // if BUSY Pin goes high then the data is ready to accumulate { BYTE_MSB; // BYTE=1 _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); msbbits=PINE; // store the data available on PORTE into msbbits. Here, most MSB bits are available BYTE_LSB; // Byte=0 _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); 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, i_tmp, 10); lcd_print(i_tmp); 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 able read the correct data from ADC but i am getting strange data.
2. Are the connections between AT90USB1286 to ADS7825 right?
3. Are there any mistakes in my code?
for example, I f i give 1V as i/p signal to AIN0 of ADS7825 it is giving digital count 3276(approx) for +/-10V range.
But whenever i change the input signal from 1v to 1.080 or 1.112 e.t.c. it is giving -9.8788V(with equivalent digital count) and some times it is giving an exact input voltage(i.e.when i change the input signal amplitude).
i can't understand what is happening.
please tell any one where did i mistake.
thank you in advance.
excuse me for bad english
Last edited by a moderator: