Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC problem with 18F4553

Status
Not open for further replies.

superbrew

Member
Hello, I am using an 18F4553 to read a 0-5V input on RA0. Right now the input is from a 10K pot. The result is being displayed on a GLCD in bar graph form. This part is working fine. I am also reading temperature from a MAX6675 K type thermocouple converter. This is also being displayed on the GLCD. The problem that I am having is that when the ADC is reading lower values, like less than 500, the MAX6675 stops updating on the display. As soon as I move the ADC pot to the upper part of its range, the MAX6675 starts working again.
Here are the config settings that I am using:
#pragma config FOSC = HSPLL_HS, WDT = OFF, LVP = OFF
TRISA = 0x07;
TRISB = 0x00;
TRISC = 0x44;
TRISD = 0x00;
//ADC Setup
ADCON0 = 0x01;
ADCON1 = 0x0c;
ADCON2 = 0x80;

I am sure that it is some peripheral, but I can't figure it out. Thanks in advance.
 
It seems that the chip is running faster as the ADC value decreases, to the point where the it gets too fast for the MAX6675 to complete a conversion. Is there a good way to achieve a consistent ADC conversion time?
 
It seems that the chip is running faster as the ADC value decreases, to the point where the it gets too fast for the MAX6675 to complete a conversion. Is there a good way to achieve a consistent ADC conversion time?

This doesn't happen. I suspect that the fault is with your code. Do you, by chance, delete the bar graph before drawing the new one so that a low reading results in fewer pixels being plotted and therefore the whole thing running faster? The Max chip can take up to 220mS to complete a conversion.

Try calling the ADC+plotting part twice before reading the MAX chip.

Mike.
 
I am sorry, you are right. The code is running faster as the the ADC value drops. What I meant to ask is how to optimize the ADC to take a more consistent time to take a reading. I have the code reading the 6675 every 4 times through the loop, but then this takes too long as the ADC values get higher. Should I maybe have a variable delay dependent on what the ADC is reading?

EDIT: Never mind, I will just do it on an interrupt.
 
Last edited:
The variable time is due to the plotting code being inconsistent. Instead of rubbing out the old bar can you change it so that it plots the bar part and then erases the rest of it. This will make it use the same amount of time and should make it more consistent.

Mike.
 
I understand what you are saying. I only draw the parts that change, if any. So if no readings are changing, no bars are being redrawn.
Here is the code that I am using to draw the graph:
Code:
//Clear old line
if(oldBOOST > newBOOST)
{
	height = oldBOOST;
	while(height-- > newBOOST)
	{
		hline(BAR2_LOC,BAR2_LOC+BAR_WIDTH+1,
			63-height,0);				
	}
}
//Draw new line
else if(newBOOST >= oldBOOST)
{
	height = newBOOST;
	while(height--)
	{
		hline(BAR2_LOC,BAR2_LOC+BAR_WIDTH+1,
			63-height,1);
	}
}
If there are flaws in my logic(probably), please let me know.
 
Status
Not open for further replies.

Latest threads

Back
Top