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.

Helppp..... Problem on ADC

Status
Not open for further replies.

bau

Newbie level 3
Joined
Aug 2, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
I am a newbie on Microcontroller. I have written a ADC program which convert the analog signal and display on the led at PORTB and PORTC. I have try simulate with the Proteus, it work well, but, when i download the program into my PIC18F4520, it doesnt work as desired. Below is my program,

#include <p18f4520.h>
#include <delays.h>
#include <portb.h>
#include <adc.h>

#pragma config OSC = HS
#pragma config PWRT = ON
#pragma config WDT = OFF

int temp;
int Hi;

void PortB_isr (void);
#pragma code high_vector=0x08
void high_interrupt (void)
{
_asm GOTO PortB_isr _endasm
}

#pragma interrupt PortB_isr
void PortB_isr (void)
{
INTCONbits.INT0IF=0;
OpenADC(ADC_FOSC_16 & ADC_RIGHT_JUST & ADC_4_TAD, ADC_CH0 & ADC_INT_OFF
& ADC_VREFPLUS_EXT & ADC_VREFMINUS_EXT,5);
SetChanADC(ADC_CH0);
Delay10TCYx( 100 );
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for ADC conversion
temp = ReadADC(); // Read result and put in temp
CloseADC(); // Disable A/D converter
PORTC=temp;
Hi=temp;
Hi>>=8;
PORTD=Hi;
}

void main (void)
{ TRISA=0x0F;
TRISB=0xFF;
TRISC=0x00;
TRISD=0x00;
PORTC=0;
PORTD=0;
ADCON1=0x09;
T0CONbits.T0CS=0;
CMCON=0x07;
CVRCON=0;

OpenRB0INT ( PORTB_CHANGE_INT_ON &
FALLING_EDGE_INT &
PORTB_PULLUPS_OFF);
INTCONbits.GIE = 1;

while(1){}

}


The cystral that i used is 20MHz.

The output of my LED (connected to the PORTC and PORTD) is 0b1100000000 when the AN0 is connected to ground.

I glad to listen from others.......
 

What specifically does not work ?

Which ADC channel are you using ?

How often are you refreshing the values on the LEDs ?
I will say one or two times per seconds will be ok for you to read the values. A value lower than that will be difficult to read.

My recommendation is always to make thing works step by step, for example make sure the PORTC and PORTD output data works fine. Then go to the next step. And so on.

Please answer the questions and post your schematic to get better help.
 

The first thing it doesnt work is when i supply the 0v(ground) to the AN0 which is the ADC_CH0, the output is not shown as desired which is 0b0000000000.

The channel that i used is ADC_CH0.

i do not trigger the RB0 interrupt so often (less than one time per second) so i dont think there is no enough time for the ADC conversion.

The data pin for PORTC and PORTD and working well. I have try it be adding the below code to test it. But the problem is still the same....

PORTC=0xFF;
PORTD=0xFF;
Delay10KTCYx(255);
Delay10KTCYx(255);
PORTC=0x00;
PORTD=0x00;
Delay10KTCYx(255);
Delay10KTCYx(255);
PORTC=0xFF;
PORTD=0xFF;
Delay10KTCYx(255);
Delay10KTCYx(255);
PORTC=0x00;
PORTD=0x00;


Is it because of some mistake on the ADC settling?
 

Can you tell us which micro you are using?
 

Hello bau

Have a look at **broken link removed** for the settings, which explains how the ADC works, and also provides example code to read analog inputs.
The PIC used in these tutorials is from the same family, and thus the way of reading analog inputs is the same.
 

nandhu015:
i am using the adc.h inside the C18 library to configurate my adc function.

miredox:
Thank you very much. finally i know wat is my problem. i forget to configurate the LVP to off, which cause my adc function unable to operate well.. Once againss.....Thanks.....

Added after 9 minutes:

On more thing to ask.. Why without configurate the LVP = off, my ADC will not function properly? As i know, it is not related to the port A or ADC function. But, why it will happen?

I am looking forward for the explaination. Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top