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.

LCD displays same ADC value across different channels

Status
Not open for further replies.

sarah.sanchez

Junior Member level 2
Joined
May 16, 2011
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,588
hi,

i am currently working on a project using PIC18F4520 in MikroC. it has to read the LM35s connected to each of the 6 ADC channels (AN0-AN5). also, we wanted to display those values in the LCD. please see code below. but the output in the LCD shows the same value for all of the ADC channels even if the LM35 is exposed to different temperatures.

unsigned short temp_h1, temp_h2, temp_h3, temp_c1, temp_c2, temp_c3;
char hot1[5], hot2[5], hot3[4], cold1[4], cold2[4], cold3[4];

void main() {
ADCON1 = 0x00;
ADCON2 = 0xAA;
TRISA = 0xFF;
TRISE = 0x01;

TRISD = 0x00;
Lcd_Init(&PORTD);
Delay_ms(200);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);

while(1) {
temp_h1 = ADC_Read(0);
temp_h2 = ADC_Read(1);
temp_h3 = ADC_Read(2);
temp_c1 = ADC_Read(3);
temp_c2 = ADC_Read(4);
temp_c3 = ADC_Read(5); //RE0
tempdiff1 = temp_h1 - temp_c1;
tempdiff2 = temp_h2 - temp_c2;
tempdiff3 = temp_h3 - temp_c3;

EEPROM_Write(0x00, temp_h1);
EEPROM_Write(0x02, temp_h2);
EEPROM_Write(0x04, temp_h3);
EEPROM_Write(0x06, temp_c1);
EEPROM_Write(0x08, temp_c2);
EEPROM_Write(0x0A, temp_c3);

ShortToStr(EEPROM_Read(0x00), hot1);
ShortToStr(EEPROM_Read(0x02), hot2);
ShortToStr(EEPROM_Read(0x04), hot3);
ShortToStr(EEPROM_Read(0x06), cold1);
ShortToStr(EEPROM_Read(0x08), cold2);
ShortToStr(EEPROM_Read(0x0A), cold3);

Lcd_Out(1,1,"h1=");
Lcd_Out(1,5,hot1);
Lcd_Out(2,1,"h2=");
Lcd_Out(2,5,hot2);
Lcd_Out(2,1,"h3=");
Lcd_Out(2,4,hot3);
Delay_ms(3000);
Lcd_Out(1,1,"c1=");
Lcd_Out(1,4,cold1);
Lcd_Out(1,9,"c2=");
Lcd_Out(1,12,cold2);
Lcd_Out(2,1,"c3=");
Lcd_Out(2,4,cold3);
}
}
 

Assuming you have the pins configured as analog inputs, what settings are you using for the ADC timing? Without knowing your clock speed and settings it's impossible to see if the timing is correct.
The symptoms suggest that either none of the inputs are being measured or you are not allowing sufficient time for the ADC channel to select and sample before reading the value.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top