Hey guys.
Just seem to be running into some coding errors while trying to display values of a Triple Axis accelerometer (ADXL330).
I am using the AT89C51AC3 Micro.
The problem I am having is that I can't seem to cycle through each 'channel' to perform an ADC. (i need one for each axis, X, Y and Z). It works fine with just one channel in operation, but as soon as I try to have it cycle through several it throws a wobbly and gives me all kinds of strange results..
At the moment I am simply trying to print the values on the LCD screen (LCD screen is working no problem).
Code:
in Main:
{
P1=0x00; //This is the ADC port
ADCF = 0x07; //Configure Ports: ADC0, ADC1 and ADC2
ADCON = 0x20; //Enable ADC
while (TRUE)
{
char s [33];
unsigned int Result = Sample_ADC(AD0);
unsigned int Result2 = Sample_ADC(AD1);
unsigned int Result3 = Sample_ADC(AD2);
sprintf(s,"x:%d y:%d z:%d " , Result, Result2, Result3); //x: y:
}
Where:
unsigned int Sample_ADC(channel)
{
unsigned int Sample;
//Start a Conversion:
ADCON &= 0xF8; //Clear Field
ADCON |= channel; //Channel
ADCON |= 0x08; //Start Conversion
while ((ADCON & 0x10) != 0x10)
/* Do Nothing */;
ADCON &= 0xEF; //Clear conversion flag
Sample = (ADDH<<2)+(ADDL); //Read value from ADDH and ADDL registers.
return Sample;
}
Anyone got any ideas? I guess you would need a pretty good knowledge of this chip...
Just seem to be running into some coding errors while trying to display values of a Triple Axis accelerometer (ADXL330).
I am using the AT89C51AC3 Micro.
The problem I am having is that I can't seem to cycle through each 'channel' to perform an ADC. (i need one for each axis, X, Y and Z). It works fine with just one channel in operation, but as soon as I try to have it cycle through several it throws a wobbly and gives me all kinds of strange results..
At the moment I am simply trying to print the values on the LCD screen (LCD screen is working no problem).
Code:
in Main:
{
P1=0x00; //This is the ADC port
ADCF = 0x07; //Configure Ports: ADC0, ADC1 and ADC2
ADCON = 0x20; //Enable ADC
while (TRUE)
{
char s [33];
unsigned int Result = Sample_ADC(AD0);
unsigned int Result2 = Sample_ADC(AD1);
unsigned int Result3 = Sample_ADC(AD2);
sprintf(s,"x:%d y:%d z:%d " , Result, Result2, Result3); //x: y:
}
Where:
unsigned int Sample_ADC(channel)
{
unsigned int Sample;
//Start a Conversion:
ADCON &= 0xF8; //Clear Field
ADCON |= channel; //Channel
ADCON |= 0x08; //Start Conversion
while ((ADCON & 0x10) != 0x10)
/* Do Nothing */;
ADCON &= 0xEF; //Clear conversion flag
Sample = (ADDH<<2)+(ADDL); //Read value from ADDH and ADDL registers.
return Sample;
}
Anyone got any ideas? I guess you would need a pretty good knowledge of this chip...