yviswanathbe
Full Member level 4
regarding c code
Hi Friends,
I am using TI ADS8344 16 bit ADC in my application.
Everything is working fine.But when comes to Result i will be getting 3 bytes from the ADC, i need to use some extract and reassemble technique to get the actual result.
I have done using "bdata" and its working too.but i feel the code which i have written is bigger and complicated.
I am attaching my code, some body can help me with some logic.
//Accessing DataByte2 and DataByte3 in Bit addressable memory location
char bdata msb_databyte2;
char bdata msb_databyte3;
//Extracting DataByte2 to individual bits
sbit msbbyte2_7 = msb_databyte2^7;
sbit msbbyte2_6 = msb_databyte2^6;
sbit msbbyte2_5 = msb_databyte2^5;
sbit msbbyte2_4 = msb_databyte2^4;
sbit msbbyte2_3 = msb_databyte2^3;
sbit msbbyte2_2 = msb_databyte2^2;
sbit msbbyte2_1 = msb_databyte2^1;
sbit msbbyte2_0 = msb_databyte2^0;
void Adc_Convert (UC adc_Ch)
{
UC c1=0;
NSSMD0 = 0;
delay_ms(10);
ADC_Write(adc_Ch);
adc1stbyte=ADC_Read ();
adc2ndbyte=ADC_Read ();
adc3rdbyte=ADC_Read();
NSSMD0 = 1;
delay_ms(10);
temp=(adc1stbyte << 1);
msb_databyte2=adc2ndbyte;
adc_highbyte=(temp | msbbyte2_7);
temp=extract_combine();
msb_databyte3=adc3rdbyte;
adc_lowbyte= temp| msbbyte3;
}
UC extract_combine(void)
{
int i=0,j=128;
bits[7]=msbbyte2_6;
bits[6]=msbbyte2_5;
bits[5]=msbbyte2_4;
bits[4]=msbbyte2_3;
bits[3]=msbbyte2_2;
bits[2]=msbbyte2_1;
bits[1]=msbbyte2_0;
temp1=bits[7]*128+bits[6]*64+bits[5]*32+bits[4]*16+bits[3]*8+bits[2]*4+bits[1]*2;
return temp1;
}
Thanks and Regards,
Viswanath
Hi Friends,
I am using TI ADS8344 16 bit ADC in my application.
Everything is working fine.But when comes to Result i will be getting 3 bytes from the ADC, i need to use some extract and reassemble technique to get the actual result.
I have done using "bdata" and its working too.but i feel the code which i have written is bigger and complicated.
I am attaching my code, some body can help me with some logic.
//Accessing DataByte2 and DataByte3 in Bit addressable memory location
char bdata msb_databyte2;
char bdata msb_databyte3;
//Extracting DataByte2 to individual bits
sbit msbbyte2_7 = msb_databyte2^7;
sbit msbbyte2_6 = msb_databyte2^6;
sbit msbbyte2_5 = msb_databyte2^5;
sbit msbbyte2_4 = msb_databyte2^4;
sbit msbbyte2_3 = msb_databyte2^3;
sbit msbbyte2_2 = msb_databyte2^2;
sbit msbbyte2_1 = msb_databyte2^1;
sbit msbbyte2_0 = msb_databyte2^0;
void Adc_Convert (UC adc_Ch)
{
UC c1=0;
NSSMD0 = 0;
delay_ms(10);
ADC_Write(adc_Ch);
adc1stbyte=ADC_Read ();
adc2ndbyte=ADC_Read ();
adc3rdbyte=ADC_Read();
NSSMD0 = 1;
delay_ms(10);
temp=(adc1stbyte << 1);
msb_databyte2=adc2ndbyte;
adc_highbyte=(temp | msbbyte2_7);
temp=extract_combine();
msb_databyte3=adc3rdbyte;
adc_lowbyte= temp| msbbyte3;
}
UC extract_combine(void)
{
int i=0,j=128;
bits[7]=msbbyte2_6;
bits[6]=msbbyte2_5;
bits[5]=msbbyte2_4;
bits[4]=msbbyte2_3;
bits[3]=msbbyte2_2;
bits[2]=msbbyte2_1;
bits[1]=msbbyte2_0;
temp1=bits[7]*128+bits[6]*64+bits[5]*32+bits[4]*16+bits[3]*8+bits[2]*4+bits[1]*2;
return temp1;
}
Thanks and Regards,
Viswanath