PDA

View Full Version : ADC not reading zero


tommyjt24
11-09-04, 07:49 AM
Hey everyone, Just wanted some thoughts on why my ADC doesnt read zero with nothing pluged onto the An pins??? I'm using the H6 so I know it can read 0-Vref, Even with a pin pluged in and a variable resister(a pot) the voltage I get doesnt ever go below what i calculate out as 2.4v. So I have lost a whole range below 2.4v. I have the pot hooked up to 3.3v pin on the board, J2 and have it hooked into the pot and then 100k resister to ground. the voltage on my meter reads from vref to 0 so I do not know why the An pins do not. Bellow is my code for setting up the ADC. then I just have a timer and when timer goes off I check my voltage. I check the voltage by polling for new data.

void initADCA(void)
{

*ADACR1 = 0x0202;//001(start)1(sync) set llmtie bit 9
//0000 interupts end of scan, zero crossing, low limit, high limit
//0000 differential inputs
//0000 once sequential, 010, loop sequential
*ADACR2 = 0x003D;//0000 0000 0000 [0DIV]
*ADAZCC = 0x0000;//[1:0] ZCE0 zero crossing enable
*ADALST1= 0x0000;//0000 0000 0000 0000 enables AN0
*ADALST2= 0x0000;//0000 0000 0000 0000

*ADADIS = 0x00F8;//[15:14] 00 normal mode, 01 test mode vref/2
//[7:0] enable 0, disable 1

*ADALLMT0= (2891<<3);//low limit of when we need to charge approx 5.5V
// *ADAOFS0 =0x0000;//offset to correct value 2891
*ITCN_GPR14 |= 0x0060; //set up interupt vector


}

nmitech
11-09-04, 10:00 AM
why my ADC doesnt read zero with nothing pluged onto the An pins???
Any time an ADC input pin is floating, you will expect random data readings.

For your program reference, below is the ADC example program provided on http://petegray.newmicros.com web site. Note, The Analog registers of the IsoPod and the NMIN-0803-H3/H6 are identical. So you should be able to import it to your program without any modification requires.


/*+++

ADC example program for the IsoPod (see http://www.newmicros.com)

Displays ADC reading, in decimal, taken from ANA0. Tested with
Sharp GP2D12 Infrared sensor.

Peter F Gray (petegray@ieee.org)
28Jan03

---*/

#include "scdefs.h"

/* SCI definitions */
#define SCI0BR 0x0F00
#define SCI0CR 0x0F01
#define SCI0SR 0x0F02
#define SCI0DR 0x0F03

/* ADC definitions */
#define ADCR1 0x0E80
#define ADSDIS 0x0E85
#define ADSTAT 0x0E86
#define ADRSLT0 0x0E89

/* general purpose I/O routines */
outsci (a,b)
int *a;
unsigned char *b;
{
int status;
while (*b) {
do status = *SCI0SR; while ((status&0xC000)!=0xC000);
*a = *b;
*b++;
}
do status = *SCI0SR; while ((status&0xC000)!=0xC000);
}

outscichar (a,b)
int *a;
unsigned char *b;
{
int status;
do status = *SCI0SR; while ((status&0xC000)!=0xC000);
*a = *b;
do status = *SCI0SR; while ((status&0xC000)!=0xC000);
}

void outdec (chan, val)
unsigned int *chan;
unsigned int val;
{
unsigned int u,t;
unsigned char c;
t = 10000;
do {
u = 0;
while (val>=t) { val -= t; u++; }
c = '0' + u;
outscichar (chan,&c);
t /= 10;
} while (t>0);
}

main ()
{
int stat, result, ave, count;

*SCI0BR = 260; /* set up SCI */
*SCI0CR = 12; /* 9600, N81 */
*ADSDIS = 254; /* enable channel zero */

outsci (SCI0DR,"\15\nSCI Module Ready. ADC Enabled, reading ANA0.\15\n");

count = ave = 0;
while (1) { /* loop forever */
*ADCR1 = 0x2000; /* start conversion */
do stat = *ADSTAT; while ((stat&1)!=1); /* wait until complete */
result = *ADRSLT0 >> 3; /* low 3 bits not used */
ave += result >> 5; /* /32 and sum */
count++;
if (count==32) {
outdec (SCI0DR,ave); outsci (SCI0DR," ave");
count = ave = 0;
}
outsci (SCI0DR,"\15");
}
}

tommyjt24
11-09-04, 02:31 PM
OK thanks got it working now. I must have cleared a bit that gets set.