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.

Analog input doesn't works - 18F4520 LM35

Status
Not open for further replies.

Gardánfalvi András

Newbie level 3
Joined
May 24, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
31
Dear everybody!

I simulated my project to read temperature, and controll 3 fans (depending on the temp). But when I built it some problem occured. I made new ccs project, and checked all the connections, but I still have the problem.
Heres the project.
View attachment 7th.rar

And heres a video about the problem:

Please help! I need to finish it until monday morning!
Thank You!
 

I notice that your temperature reading starts off with 50deg, and goes DOWN when you apply the flame, by about 8-9 deg.

clearly your firmware is messed up. Or you are inverting the lm35 output someplace.
 

LOL, That is awesome. By the way where are you? 50C?

The problem you are having is in your adc conversion code most likely. The LM35 outputs 10mV for each degree of Celsus. So your calculation would be:

(((Supply Voltage / (2^(sample bit resolution count)) * (adc result)) / 0.01)

First you need to calculate the voltage per bit.
Then convert the adc result to a voltage using the voltage per bit value.
And finally calculate the temperature from the voltage.

Be careful not to burn the LM35.

- - - Updated - - -

Okay after looking at your code, I see that you are doing the correct conversion. However your adc setup is wrong. What is your crystals frequency?
 

I notice that your temperature reading starts off with 50deg, and goes DOWN when you apply the flame, by about 8-9 deg.

clearly your firmware is messed up. Or you are inverting the lm35 output someplace.

Yes, and when I disconnect everything from the leg, it is still measures something.

bluelasers -> It is 4MHz. Can the crystal cause such problem??
 

Try attached code. Connect 1.6V to Vref+ pin.
 

Attachments

  • main.c.txt
    3.2 KB · Views: 75

Change this:
Code:
setup_adc(ADC_CLOCK_DIV_16|ADC_TAD_MUL_0);

To this:
Code:
setup_adc(ADC_CLOCK_DIV_8|ADC_TAD_MUL_2);
 

Change this:
Code:
setup_adc(ADC_CLOCK_DIV_16|ADC_TAD_MUL_0);

To this:
Code:
setup_adc(ADC_CLOCK_DIV_8|ADC_TAD_MUL_2);

Nothing changes. :/

milan.rajik -> now it uses the VDD and VSS, I tried extrenal voltage reference but had no good output.
 

Try changing it to this:
Code:
setup_adc(ADC_CLOCK_DIV_8|ADC_TAD_MUL_20);

Also can you make a video where it just prints the adc integer result to the screen?
 

You have to use VSS_VREF in ADC settings. Connect 1.6V to Vref+ pin and configure Vref+ pin as input pin and it will work fine with the code I have provided.
 

You have to use VSS_VREF in ADC settings. Connect 1.6V to Vref+ pin and configure Vref+ pin as input pin and it will work fine with the code I have provided.

He does not need to a 1.6V reference. The LM35 outputs 10mV per degree, which you be a problem if he had a 8 bit ADC. The step would be over 19mV @ 5V reference, but since he has a 10 bit ADC so he has a step of about 4.88mV @ 5V reference. So his step is lower than the step output of the LM35, he does not need to change his reference.
 

If he uses 5V ref then 5V = 1023 raw adc value and LM35 max output is 1.5V. So, max adc value he will get is 306.9. If he uses Vref+ of 1.6V then 1.6V = 1023 adc value = 160 deg C

5V / 1023 = 0.0048875855327468 V

1.6V / 1023 = 0.001564027370479 V


5V = 500 deg C

0.0048875855327468 V = 0.48875855327468 deg C (steps he will get if 5V ref is used)


1.6V = 160 deg C

0.001564027370479 V = 0.1564027370479 deg C (steps he will get if 1.6V ref is used)
 

But if the intervals are 10mV it makes no difference. He would be wasting money on unneeded components.

Requirements are for 10mV which is already covered, because he can read voltages less than half the requirement.

- - - Updated - - -

To test the pic take two 10K resistors and build a voltage divider on another adc input.

To build a voltage divider do the following.
1. Connect one lead of the one 10K resistor and connect it to +5V.
2. Connect the other lead of the first 10k resistor to another adc input.
3. Connect the one lead of the second 10k resistor to the same adc input as the first 10k resistor.
4. Connect the other lead of the second 10k resistor to ground.

Change the code to read the new adc input. If all is well with the PIC you should get about 512 (about 2.5 volts).
 
Last edited:

Try this code.
 

Attachments

  • 7th.rar
    150.4 KB · Views: 79

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top