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.

PIC16F716 ADC With LM35CZ

Status
Not open for further replies.

Mywk

Newbie level 5
Joined
Apr 2, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
PIC16F716 ADC With LM35CZ (Updated)

Hey Guys, I'm trying to read the temperature out of a LM35CZ, it outputs the amount of Celsius degrees in mV (Example 20Cº = 0.20V).

Here is the schematics, simulation in Proteus seems OK:
**broken link removed**

I'm using the following code, I'm using CCS C:
Code:
#include <16F716.h>
#device adc=8
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=4000000)  

void main(void)
{
 set_tris_b(0);
 
 output_high(PIN_B1); // Power On

   int16 reading; 
float temp;
   setup_adc_ports(PIN_A0);    
   setup_adc(ADC_CLOCK_INTERNAL);  
   set_adc_channel(0); 
   delay_us(20); 

   while(1) 
   {
      reading = read_adc();
	  temp = 5* reading * 100/255;
	  if(temp > 21)
		output_high(PIN_B2);
	  else
		output_low(PIN_B2);
      delay_ms(1000);    
   } 

}

Works in Proteus, however, this is what happens in reality:
If temperature is below 13C the LED is ON, if above, OFF, when it should be more than 21 ON, less OFF, so what could be wrong?

Thanks In Advance!
 
Last edited:

C1 and C2 are far too big. Use something like 22pF. Connect MCLR pin to +5V via a 10k resistor and place a 0.1uF capacitor from MCLR pin to ground.

You need to connect pin 1 of LM35 to +5V.

In the real circuit, did you connect the VDD and VSS of the PIC properly? Did you place decoupling capacitors?

Remove RV1 and connect the output of the LM35 directly to the ADC input. You can place a 0.1uF capacitor from the ADC input pin to ground.

Other questions:

- If one LED goes UP, the other gets less power, so less light, correct? Wouldn't that interfere with ADC readings also? I think i answered myself here when I inserted some extra Capacitors after power source output, correct me if I'm wrong.

- If the PIC only outputs 5V, how can I activate a 5V relay? Wouldn't I have power shortage then?

Thanks In Advance!

For the first question:
No. If the power supply can handle the load of both LEDs lighting simultaneously along with powering the PIC and the LM35, no problem. Say, the power supply can supply 5V 150mA. The red LED will draw around 10mA current, the green around 7mA. The PIC won't draw more than 30mA (guess). The LM35 itself will draw very little. Overall, the current draw should be less than 100mA. This can be handled by the power supply. So, the voltage will stay fixed at 5V. No drop in voltage. Everything works as expected. So, you should check if there is a drop in voltage of the +5V line if you have any doubts. If not, then, no problem. But, adding extra capacitors on the power line is good practice in case there are large current draws.

For the second question:
The PIC won't be able to power the relay unless the relay draws around 10-20mA. It's better that you use a transistor to power the relay. Once again, if the power supply can handle the total current (power) of the circuit with all components running, then, there won't be a power shortage.

Hope this helps.
Tahmid.
 
  • Like
Reactions: Mywk

    Mywk

    Points: 2
    Helpful Answer Positive Rating
Re: PIC16F716 ADC With LM35CZ (Updated)

hello

Here is the schematics, simulation in Proteus seems OK:
Works in Proteus, however, this is what happens in reality:
- If one LED goes UP, the other gets less power, so less light, correct?

C1 and C2 in Proteus schematic are 1000u => i hope not the same in reality must be 22pf up to 33pF
Quartz value ?
If you have interference on the light of led , it seems you have a poor power supply !
How is made the power supply 5V ?

iF you want to add a relay : give technical caracteristique of this relais
Nominal voltage, coil resistance value ?
it's better to add a transistor like 2N2222 to drive a relais , and anti reverse diode accross of the coil of the relais.
 

C1 and C2 are far too big. Use something like 22pF. Connect MCLR pin to +5V via a 10k resistor and place a 0.1uF capacitor from MCLR pin to ground.

That is how it is done, schematics are not really correct, otherwise the PIC would not even be working.

Remove RV1 and connect the output of the LM35 directly to the ADC input. You can place a 0.1uF capacitor from the ADC input pin to ground.

LM35 is directly connected, what do you mean a 0.1uF from ADC input to ground?

Power supply is 12V 300mA, then it goes thro a Diode and then to a 5Vregulator.

The LM35 is connected directly to the 12V and shares the same GROUND as all connections, with a voltmeter it outputs the correct value, right now it outputs 0.23V for 23Cº, but Red led is not ON while in Proteus it is.

I updated the first post diagram to something similar to what I have in my circuit.
 

That is how it is done, schematics are not really correct, otherwise the PIC would not even be working.



LM35 is directly connected, what do you mean a 0.1uF from ADC input to ground?

Power supply is 12V 300mA, then it goes thro a Diode and then to a 5Vregulator.

The LM35 is connected directly to the 12V and shares the same GROUND as all connections, with a voltmeter it outputs the correct value, right now it outputs 0.23V for 23Cº, but Red led is not ON while in Proteus it is.

I updated the first post diagram to something similar to what I have in my circuit.

C3 should be connected between the output of U3 (pin 3) to ground. It should not be in the path of VDD. VDD should be taken from pin 3 of U3.

Also, place a resistor between RB2 and red LED.
 

Re: PIC16F716 ADC With LM35CZ (Updated)

hello

Hey Guys, I'm trying to read the temperature out of a LM35CZ, it outputs the amount of Celsius degrees in mV (Example 20Cº = 0.20V).

in your software, i didn't see a treatment (of 0°C) absolute in Kelvin 273°K

I think also, your calibration is wrong, because range of LM35CZ dosen't start from 0°C but
is from -40°C up to 150°C
so you don't have 200mV for 20°C
try this with result is degre*10

remark
when you are using floating point value, add a point after the value to avoid rounding mistake .
temp=5.0 * (float)reading * 100.0 / 255.0

you have to modify this !

Maybe you can increase resolution by using _Vref and + Vref
with a range of 2,5V for 1024 points.
 

Attachments

  • Lm35CZ_calib.jpg
    Lm35CZ_calib.jpg
    85.2 KB · Views: 68
  • Like
Reactions: Mywk

    Mywk

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top