PDA

View Full Version : Adc


Pleiku
05-08-01, 02:21 PM
I'm using NMIX/T-0020 board and having problem convert from A to D.
After compile and download to the board and execute it, the program always stop at the second while loop.
Could someone help me please?
Thanks,
HT
***
#include <stdio.h>
#define ADCTL *(unsigned char*)(1030)
#define ADR1 *(unsigned char*)(1031)

main()
{
int adc;
float voltage;
while(1)
{
ADCTL=0x10;
while((ADCTL&0x80)==0){};
adc=ADR1;
voltage=(5.0/255.0)*adc;
printf("ADC output is %d. Voltage is %d. \n\r",adc,voltage);
}
}

RMDumse
05-08-01, 03:59 PM
I'm not up on pointers in C, but I wonder if the structure of the loop is right. The conversion time on the A/D's is very fast compared to the print statement at the end of the program. Why not comment out the second while loop? You will not get the data printed faster than new data is available. Then you can see if the A/D is working like you like, and if so, then focus on debugging the while loop structure in C to get what you want?

I'd suggest you try this and let me know the results. From there we can tell if the problem is 1) hardware, 2) BUFFALO, 3) C.

nmitech
05-08-01, 04:24 PM
#define ADCTL *(unsigned char*)(1030)
#define ADR1 *(unsigned char*)(1031)

Your compiler may consider the address above as the decimal instead of HEX.


nmitech
----------