Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/28/06 10:16
Modified:
  08/28/06 10:17

Read: times


 
#123183 - ADC0838 does not output correctly
Here is my situation, i'll start off with my hardware connection. I am using ADC0838 and AT89C51ED2 MCU. Keil uVision as compiler. My problem is that : I keep getting the final output value as zero and i could not figure out why.



-Vcc of ADC is connected to +5V
-Vref of ADC is connected to +5V

-CH01 is connected to a analogue signal of 0.6V (measured)

-CS is connected to P1.0
-DI is connected to P1.1
-CLK is connected to P1.2
-DO is connected to P1.3

AGND, DGND, and COM is grounded.

Below is the fraction of my code.




.
.

sbit CS = P1^0;
sbit DI = P1^1;
sbit CLK = P1^2;
sbit DO = P1^3;
.
.

int make_measurement(int channel)
/* makes measurement on specified channel*/
{
int control_word, value;

CS = 1;
CS = 0; /* reset the A/D */

control_word = make_control_word(channel);
send_control(control_word);
value = get_val();
CS = 1; /* turn off A/D */

return(value);
}




int make_control_word(int channel) //create the control word to select the input channel

{
int word, lsb;
word = 0x18; /* 1 1000 */
lsb = channel & 0x01;
word = word | (lsb <<2); /* 1 1 lsb 0 0 */
word = word | (channel >>1); /* 1 1 lsb msb middle */
return(word); //return 5 bits control word
}






void send_control(int val) //output the control word bit by bit to the DI pin

{
char n;
int tmp;

for(n = 4 ; n >= 0; n--)
{
tmp = (val >> n) & 0x01; /* isolate the bit */
if ((tmp && 0x01) !=0) /* test LSB */
{
DI = 1; //clock a '1' bit
}
else
{
DI = 0; //clock a '0' bit
}

CLK = 1; // Pulse the clock
Delay(50);
CLK = 0;
}
}






int get_val(void) //Retrieve the value of DO bit by bit.

{
int tmp, value=0x00, n;
/* DO is now out of high impedance state */
CLK = 1; // initial extra pulse before the first bit can be obtained according to datasheet
Delay(50);
CLK = 0;

for(n=7; n>=0; n--)
{
if( DO != 0) tmp = 1; //Check if current DO=1
else tmp =0; // or DO= 0
tmp = (tmp >> 7 )& 0x01; //fill the 7 bits to the left with zeros
value = value | (tmp << n); // update the string with each n until a 8 bits data is obtained
CLK = 1;
Delay(50);
CLK = 0;

}

return(value);
}





void Delay (int milisec) //delay fucntion in ms
{
int i;
i = milisec * 922; // 922 counts per 1 ms
for (i = 1; i <= milisec; i++);


}





void main(void){

adc_data = make_measurement(0); //make measurement of channel 0 (CH0)
LCD_Print(adc_data); // Output the value on LCD screen. Yes the LCD_Print() function works correctly.

}




Please help me point out if there's any mistake i have made. Thank you!

List of 6 messages in thread
TopicAuthorDate
ADC0838 does not output correctly            01/01/70 00:00      
   here?            01/01/70 00:00      
      Hmm..i dont understand why            01/01/70 00:00      
         \'&\' in an if statement            01/01/70 00:00      
            The line is not inside an \\\'if\\\' statement            01/01/70 00:00      
         difference            01/01/70 00:00      

Back to Subject List