Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC problem (PIC18F2550) - not changing

Status
Not open for further replies.

deperkin

Member level 2
Joined
Apr 12, 2009
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,776
Hiya all!

I am interfacing a sensor (that has been manually tried and tested), with a dual digipot (DS1868).

I have tested the code and digipot(s) extensively and i get the resistances to change correctly.

My problem however is i cannot get my simple ADC code to work.

I have a very simple code:

#include <18F2550.H>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#device *=16
#device adc = 10 // 8-bit resolution for Analog-Digital Conversion
#use delay(clock = 4000000) //20MHz clock used for timing
//--------------------------DEFINES---------------------------------------------
#define zero 0
#define bias 1

//--------------------------GLOBALS---------------------------------------------
unsigned long a2dval;
//-------------------------INCLUDES---------------------------------------------
#include "PINOUT.c" // general pinout
#include "DS1868.c" // driver used for digital potentiometer
//------------------------------------------------------------------------------



void initialize()
{
SET_TRIS_A(0xFF); // PINS A0-A7 are inputs
setup_adc_ports(AN0_TO_AN1|VSS_VREF); // Set pins for Analog-Digital(A2D) Conversions
setup_adc(ADC_CLOCK_DIV_4);// Set A2D clock
set_adc_channel(0); // Set inital A2D pin (A0)
delay_ms(100);
read_adc(ADC_START_ONLY);
delay_ms(100);
init_pots (); //initialize

}

void main() {

int value,ival,jval;
initialize();
while(1)
{
ival=150;
while(ival<255)
{
jval = 150;
value = ival;
delay_us(20);
set_pot (zero, value);
delay_ms (200);
a2dval = read_adc(ADC_READ_ONLY); //read sensor
delay_ms (100);
while(jval<255)
{
value = jval;
set_pot (bias, value);
delay_ms (200);
output_high (PIN_B3);
delay_ms(200);
output_low(PIN_B3);
delay_ms(200);
fprintf(COMP,"%u,%u,%lu\n\r",ival,jval,a2dval);
++jval;
}
++ival;
}
}

}

This is pretty simple code, but I am getting a constant value of 32768 on the computer for my ADC reading.

I have tried to change from float to int to long and combinations... but still a constant value.

I have tried changing to 8-bit resolution... still no help.

I have tried not using VREF and using VDD instead, along with removing this reference... no change.

ALSO, i have tried removing the sensor input and putting in a POT, and still same constant number.

This is the only pin (other then the SPI and LED) that is being used on the PIC.


ANY thoughts why my ADC is not working????


Thanks!
 

Did you enable and start the ADC? I can't find this in your code. Either to start continous conversion or to do a single conversion? How do you detect the ADC is finished the conversion?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top