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.

18f4620 read temperature from LM35

Status
Not open for further replies.

fairiesrcrazies

New Member
Ok so I have a problem with my code and I'm not sure whether its the A/D converter or the way I have configured the UART. What it is supposed to do is read the temperature from RA1 and send it out the UART. But the problem is when I look at the values on PUTTY it just looks like a bunch of random numbers ranging from 400 to 500 and it also behaves the same way when I apply heat to the sensor

Any help would be appreciated:p

I think i have uploaded the code as a txt file but not sure as I'm a newbie:confused::confused:

Thanks
 
ADCON0 = 0b00000111 ; ..... This can't be done.. you can't set the Channel select and GO/DONE bits in the same command... The ADC needs a little time

ADCON0 = 0b00000101;

some small delay
ADCON0 = 0b00000111; .. then you can read the go/done bit

while ((ADCON0 & 2) != 0);

You can set an acquisition time, using the ADCON2 register instead of having the delay...
 
Last edited:
I tried what you asked but that didnt work...but what I did notice was that I'm getting results but I have left the input hanging with no input...I have a jpg showing the results Im getting...

Does this mean my pic is fried????????????

View attachment 63678
 
Not necessarily... Is there any way you could wire up a simple pot to the RA1 input?.... Also run it through the simulator... Make sure the ADC result is in the right format... justified I mean..

You can just make sure the maths are working as expected (Without casting, floating point calculations do appear odd sometimes).
 
I could only test RA0 with the pot as I'm only testing the program with a picdem 2 board....it seems to working fine..what I'm going to do next is to try and simulate it and see what im getting..
 
I have simulated in ISIS using an LM35 onto RA1.... Out put is spot on.... your mathematics are good.... must be the sensor (or the port)

The picdem 2 board has a TC74 temperature sensor, not an LM35!... Is yours an external sensor?
 
One thing to look at is not all LM35 have the same pin out I had this happen and it was because my LM35 output was not the same as with the data sheet i got off the net.
 
Last edited:
Im using an external sensor (LM35) and I have checked the output with a multimeter and I'm getting the right results..... roughly around 200mV at room temp

I'm puzzled..........I myself think its the pic is broke:(:(

I didnt realize there was a sensor on the board looks like its a digital output..
 
Last edited:
I didnt realize there was a sensor on the board looks like its a digital output..
I2C interface... I don't mind this as I use I2C quite a lot..

Take the pic18 out of the socket and measure the voltage on the pin.... There may be something else on that pin... look for jumpers.
 
Last edited:
I think you mean PORTD...ok so im recieveing 5V on PORTD...a voltage on RA0(pot connect to RA0)...getting 5V on RA4 which is connected to a switch and 1.5V on RB0????

I taught you tested the code and it works so that would mean the PIC is at fault?????
 
No.. I haven't got a picdem2 board... I tried it in ISIS..

Look at it like this... LM35 connected to 5v...0v... RA1.. correct..... RA1 should read LM35 output.... correct.... LCD RS line connected to RA1 aswell.... voltage from LM35 being applied to two devices.. LCD RS connection will add / drain voltage from signal.
 
It's the lcd all you have to do is look at the data sheet Ian posted and you'll see what happing you may have jumper that can be cut lots of there boards do.
 
I do understand what you mean...but the LCD is connected to PORTD not PORTA..But I have just spotted RA1 is connected to the battery so that cant be used as an A/D converter....

The problems will probably disappear when I make a PCB....
 
but the LCD is connected to PORTD not PORTA..

Not according to the schematics... RA1 = E, RA2 = R/W and RA3 =RS... PORTD is the 4 bit data bus...

Have you the picdem2 or the picdem2 plus... only subtle differences, but slightly different.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top