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.

[PIC] 7seg (common anode) temperature sensor controlled by LM35 & PIC18F4520

Status
Not open for further replies.

KhaledOsmani

Full Member level 6
Joined
May 4, 2014
Messages
384
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Activity points
3,933
Hello,

I want to make a temperature sensor, that outputs actual Celsius degree on two seven segments with both common anode type.

The project flowchart can be resumed as:
1) ADC input of the temperature (as a voltage) to PORTA.0
2) Math work to convert the digital data into understandable analog (voltage value) and not forgetting numerical multiplication which is specific to LM35DZ. i.e when the temperature is 13 degrees Celsius, and after branching 5VDC to the sensor input terminals, it shows on the DVM 0.13 Volts that means we have to multiply by 100 to get the accurate voltage representing the real temperature.

I have used two 7seg common anode type, and connected the segments pins to PORTB and PORTC respectively for first digit, and second digit via 220Ohm resistor.

Following is a diagram of the circuit:



Following is the BASIC codE:

Code:
Define CLOCK_FREQUENCY = 20
ADCON1 = 0x0e
Dim x As Word

main:
		WaitMs 3000
		Adcin 0, x
		x = x * 5 / 1023
		x = x * 100
conditions:
		If x = 15 Then
			Low PORTB.1
			Low PORTB.0
			Low PORTB.5
			High PORTB.6
			High PORTB.7
			High PORTB.4
			High PORTB.2
			High PORTB.3
			High PORTD.0
			Low PORTD.1
			Low PORTD.2
			Low PORTD.3
			High PORTD.4
			Low PORTD.5
			Low PORTD.6
			High PORTD.7
		Endif
		If x > 15 And x < 16 Then
			Low PORTB.1
			Low PORTB.0
			Low PORTB.5
			High PORTB.6
			High PORTB.7
			High PORTB.4
			High PORTB.2
			High PORTB.3
			High PORTD.0
			Low PORTD.1
			Low PORTD.2
			Low PORTD.3
			High PORTD.4
			Low PORTD.5
			Low PORTD.6
			High PORTD.7
		Endif
		If x > 13 And x < 17 Then
			Low PORTB.1
			Low PORTB.0
			Low PORTB.5
			High PORTB.6
			High PORTB.7
			High PORTB.4
			High PORTB.2
			High PORTB.3
			High PORTD.0
			Low PORTD.1
			Low PORTD.2
			Low PORTD.3
			High PORTD.4
			Low PORTD.5
			Low PORTD.6
			High PORTD.7
		Endif
			
Goto main

End

This was a trial code, since I was sure that the temperature is no more +-10% less/bigger than 15 degrees Celsius.

For power circuits I have used an LM7805 with 0.33uF between input and GND and 0.1uF between output and GND to feed PIC, lm35dz as well as the seven segments display but it went too hot!! so I added another 7805 to feed the lm35dz and seven segments display while the first one stood the for PIC circuit only:

The regulator used for the PIC circuit still goes extremely hot, while the other used for sensor and displays doesn't get hot at all.

What causes the first 7805 to get that hot, and are there any errors with the circuit?

Thanks in advance

added:

I`m using an external 20M oscillator, and I have branched 10pF with parallel of 10uF at both Vdd and Vss of the PIC
 

Hello,


The regulator used for the PIC circuit still goes extremely hot, while the other used for sensor and displays doesn't get hot at all.

What causes the first 7805 to get that hot, and are there any errors with the circuit?

Thanks in advance

1) Not using a heatsink or an incorrect one. What are you using? Show photos or better still, the heatsink specs.
2) too large a current, what is the load current? Measure it.
3) High differential voltage, what is the regulator input voltage? Measure it.
4) How can we know if there are errors if an incomplete schematic is shown?
 
Sorry for any inconveniences.

Following is the circuit full image:



You can see which regulator heats up.

About the AC/DC adapter it is: S-15-12 Aluminum Case Output DC 12V 1.25A LED Switching Power Supply.

As for the heat sinks, I`m not using any.

Thank you
 

Hello

I;ve changed circuit architecture to drive a better GND to 7seg using 10K with an NPN BJT. It worked excellent but suddenly two segments of one of both 7seg displays died. I've tried to directly connect them to a 5V battery source but they still won't shine. All other segments remaining when connected to the same source glow greatly.

My question is, what causes some of/all 7seg LEDs to suddenly shut down? Is it bad manufacturer? Common problems involved with such material or bad previous circuit experience that incidentally broke only these two segments due to over current or something similar??


Thanks
 

Lets suppose your LEDs have a Vf of 1.6V per segment. You have each segment fed through a 220R resistor so the maximum display current, with "8.8." displayed is ((5 - 1.6)/220) * 16 which is about 250mA. The regulator has 12V at it's input and 5V at it's output so it drops 7V across it. That means it dissipates (7V * 0.25A) = 1.75W which is why it gets so hot. Uncooled, the temperature will rise to around 95C.

Incidentally, the current exceeds the maximum total port current for the PIC too.

Show how you have wired the BJT drivers please.

Brian.
 
Dear Brian,

I hope you are in excellent conditions regarding all life situations. It's been a while, and I`m happy to talk to you again.

Here it is your requested image:



Two segments of second display shut down.
Note that when I've removed the 10uF decoupling capacitor between Vdd and Vss the both regulators didn't heat up using same circuit attached in previous comments.

Thank you
 

How large is the 7 segment display? You might be able to pry off the housing on top of the led's, and see the tiny pinpoint led's. Test them one at a time. If you can obtain small enough replacements then you need not toss out the entire display.
 
You have no current limiting resistors in the LED segments so you have almost certainly damaged them. At the moment, when a transistor turns on it places almost the whole supply across the segment so it will draw far too much current and burn out. Look at the specification for the LED and add a resistor in series with each segment connection. The value should be "(5 - Vf)/I" where Vf is the forward voltage of the segment and I is the maximum continuous segment current in Amps, the result is in Ohms. For most displays, the maximum current is only 0.02A or so.

Removing the capacitors from the regulator is a very bad idea! If they are not fitted, the regulator may oscillate and instead of producing 5V out, it could be a waveform with peaks well above 5V which would put the PIC at risk of damage too. Please put them back in before doing anything else. The reason for it running cooler is it probably isn't dropping as much voltage as before, you need to fit a heat sink to dissipate the excess heat, there is no other solution in a linear regulator circuit.

Brian.
 
Hello Brian,

You have no current limiting resistors in the LED segments so you have almost certainly damaged them. At the moment, when a transistor turns on it places almost the whole supply across the segment so it will draw far too much current and burn out. Look at the specification for the LED and add a resistor in series with each segment connection. The value should be "(5 - Vf)/I" where Vf is the forward voltage of the segment and I is the maximum continuous segment current in Amps, the result is in Ohms. For most displays, the maximum current is only 0.02A or so.

Isn't these 7 segment displays are per-manufactured within a dropper resistor that you've explained about?
If not, how come they've survived the 5VDC being connected to them for a long while? And how come only two of them burned out?

From another perspective, if you connect a 5VDC to a red LED, it won't survives for only few seconds; hence these displays (assuming not manufactured with a dropper resistor) held the 5VDC and still holding it on for the moment, except of course of the two damaged segments. The BJTs completes the circuit to GND when a HIGH logic is ordered in the PIC, and hence lights up a certain segment. (I`m using a common anode 7 seg displays, where the 5VDC is always connected at the specific pins).

As for:
Removing the capacitors from the regulator is a very bad idea! If they are not fitted, the regulator may oscillate and instead of producing 5V out, it could be a waveform with peaks well above 5V which would put the PIC at risk of damage too. Please put them back in before doing anything else. The reason for it running cooler is it probably isn't dropping as much voltage as before, you need to fit a heat sink to dissipate the excess heat, there is no other solution in a linear regulator circuit.

I didn't mean I've neglected one of the capacitors of the regulator, I removed the 10uF referring to electrolytic decoupling capacitor connected between both Vdd and Vss of the PIC. I minimized it to 0.1uF and heat was vanished.

Thank you
 

What is the part number of the display modules?

There are types with built in drivers but they normally accept binary or BCD inputs rather than direct segment drive.

Brian.
 
What is the part number of the display modules?

There are types with built in drivers but they normally accept binary or BCD inputs rather than direct segment drive.

Hello Brian, here is its part number:


And:



Here is new circuit for driving segments:



There is another problem including ADC, but first please place comments about rigidness of attached circuit.

Thank you
 

I think it's made by TOYO but it is long obsoleted and no longer available. 2006 is probably the year of manufacture. From it's size I would guess it is a single LED/segment type with a maximum continuous current rating of about 20mA. That would make the optimum series resistor 170 Ohms so 180 Ohms would be a good standard value to use. You should really put the resistor in the collector of the transistor, not the emitter. The reason is that you want the transistor to behave like a perfect switch to ground, leaving only the resistor to limit the current. With the resistor in the emitter, the base current is reduced because the base to emitter voltage is smaller, the emitter voltage will rise above zero when it turns on and make the transistor less conductive.

Certainly, running with no resistor will damage the LED and possibly the transistors as well.

Brian.
 
Thank you dear Brian.

I will remove the 220 from emitter to GND and place a ~180Ohms between segment terminal and emitter then the circuit should have no problem.

From another part there still an ADC error with the LM35:

Regardless of its datasheet info, when fed from the regulator that is mutually feeding the PIC, and when you place a DVM, one side on the sensor output, other side on common GND you see some strange floating values most of the time negative.

When feeding the same sensor from another source i.e dry battery cell, it outputs very logical also stable DC voltage value, proportional to actual celsius temperature.

Here celsius degree is about 15C nowadays, so the output of LM35 takes value at 0.15VDC.

I tried inputting the 0.15VDC to PORTA.0 and executed the following BASIC code:

Code:
Adcin 0,x
x = x * 5 / 1024
x = x * 100

And send the value (here 15) after if/else conditioner to 7 seg displays but no good results ever took place.

As if we want to interpret what happened, i think 0.15VDC is too small to be realized by PORTA.0 so we must design an amplifier circuit with maximum output of 5VDC to be entered instead.

About floating values when fed by same regulator of the PIC supply I have no idea why it outputted non sense negative voltage values.

Would like to hear your comments and finish this project.

Much thanks
 

Happy new year Khaled.

I think your software problem is to do with the type of variable you use for the temperature. If I remember from previous posts, you are using Oshonsoft BASIC. If that is the case, the variable type "Word" is a two byte integer so it can only hold values from 0 to 65535. That means the ADC measurement will ignore fractional parts of the result when you scale it up and the figure will jump in large steps.

If you have the floating point module license you could try making 'x' a 'Single' instead of a 'Word' or you could try to avoid the fraction error by rearranging the formula. I have not tried this but see if it's is better:
Code:
Define CLOCK_FREQUENCY = 20
ADCON1 = 0x0e
Dim x As Long

main:
		WaitMs 3000
		Adcin 0, x
		x = x * 500
                x = x / 1023

The problem before is 0.15V would give a result in the ADC of 30. When you multiply that by (5/1023) you get 0.1466 which as an integer is zero so multiplying by 100 still gives a zero result.

By rearranging the formula, 30 * 500 = 15,000 which divided by 1023 gives you 14 as the result which is much nearer the value you expected.

Brian.
 
Thank you Brian.

Happy new year to you too. May all your days be fulfilled with joy and blessings.

So you were saying that there is no need for a voltage amplifier (non inverting opmap using LM324)?

From another part, i'm afraid that Vlads only permits a 'Word' argument when ADC inputting.
 

By adding a voltage amplifier you can increase the accuracy by using the full range of the ADC input but I don't think this is the problem at the moment. Adding an amplifier with voltage gain of (5/max temperature output) will improve things but at the expense of extra circuits and possibly the need for a negative supply line to get good output at near VSS voltages.

Try the software change I mentioned, leaving the ADC as Word and adding an extra variable of type Long for the calculation result. I'm almost certain the reason for your strange results is the calculation losing accuracy because integer variables cannot handle fractional values. By multiplying by 500 first then dividing by 1023 afterwards it gives the same result but the fractional part is 100 times smaller.

Dim x As Word
Dim y As Long
.
.
y = x * 500
y = y / 1023

Brian.
 
Thanks Brian.

I changed resistor connection from emitter to GND, to, 7seg pin to collector.

Also have changed variable length in BASIC as follows:

Code:
ConfigPin PORTB = Output
ConfigPin PORTBC = Output
ADCON1 = 0x0e
Define CLOCK_FREQUENCY = 20
Dim x as long

main:

   Waitms 3000
   Adcin 0,x
   x = x * 500
   x = x / 1023

Conditions:

   If x > 12 and x < 15 Then
   //show 1 3 on 7seg
   Else 
   //light up all 7seg to see 8.8.
   Endif

Goto main
End

Still I'm seeing "8.8" on 7 seg displays.
What might be the hidden problem behind such scene?

Thank you
 

I think it is working but you are expecting a more accurate result than the ADC can produce.

The display will show 8.8. all the time unless one of your three conditions is met. The range of values you have used overlap each other so unless the value is below 13 or above 17 the third check will always pass. Bear in mind all ADC results will be +/- 1 digit so it is unlikely the first check will pass reliably as it needs exactly 15 to work, the second check will also only pass if the result is 15 exactly, in other words not less than 15 but less than 16. Remember you are dealing with integer values so fractions of degrees are ignored.

A better idea would be to put a 'goto main' after all the 'Endif' so the checks are not always run consecutively.

There is a method to improve accuracy that does not need an amplifier but it does require you to use pin RA3. If you connect two resistors to RA3, 2.7K to VDD and 1.2K to VSS then change the ADCON1 value to 0x1E it will use the voltage on RA3 (should be 1.5V) as the reference for the ADC module. That gives you just over three times the resolution but makes the ADC overload at 1.5V. As that is the maximum an LM35 can produce, at 150C, it should be safe to do.

Because it changes the ADC step size, you need to change the voltage calulation to:
Code:
   Waitms 3000
   Adcin 0,x
   x = x * 150
   x = x / 1023

An alternative method using less code and running faster and with better accuracy is to avoid the converting the ADC value at all and use the 'raw' ADC result in the range comparisons.

Brian.
 
Re: 7seg (common anode) temperature sensor controlled by LM35 &amp; PIC18F4520

Thank you Brian.

I think it is working but you are expecting a more accurate result than the ADC can produce.

The display will show 8.8. all the time unless one of your three conditions is met. The range of values you have used overlap each other so unless the value is below 13 or above 17 the third check will always pass. Bear in mind all ADC results will be +/- 1 digit so it is unlikely the first check will pass reliably as it needs exactly 15 to work, the second check will also only pass if the result is 15 exactly, in other words not less than 15 but less than 16. Remember you are dealing with integer values so fractions of degrees are ignored.

A better idea would be to put a 'goto main' after all the 'Endif' so the checks are not always run consecutively.
Brian.

Is connecting an LCD instead of 7 seg displays would show accurate values?

- - - Updated - - -

Added:

I've connected an LCD to see what results are taking place and found the following:

While the output of the LM35 is showing 0.15VDC (where the actual temperature is 15C) I've seen on LCD logical results after the code:

Code:
//Definitions of LCD variables

ADCON1 = 0x0e
Dim x as Long

main:
WaitMs 2000
Adcin 0,x
x = x * 500
x = x / 1023
LCDOUT "Temp: " , #x
WaitMs 1000
Goto main
End

Temp: 110
Other times Temp: 120

When light up a flame near the sensor the value rushes incrementally as
Temp: 135
Temp: 140

When placed a dry plastic container of ice near the sensor, the value decrements as:
Temp: 105
Temp: 90

From interpretation the results must be decimally divided by 10 so 120 refers to 12C. This is why when connected 7 seg no if condition took place since x value is far times ten from given value.

Wouldn't placing if x > 120 And x < 170 would fix the previous problem?

From another part, why is the value 110, 120 most of the times, and not 150 as it should be? Does that refer to ADC sampling, time acquisition problem?

Thanks
 

No, an LCD would make no difference to the results.

The problem is analog resolution. If you imagine a voltage very slowly and evenly rising from zero, how accurately you could measure it would depend on how many decimal places your meter could read to. When you use an ADC to measure, instead of an infinite number of possibilities, the voltage measurement goes up in steps. The steps correspond to fixed levels at which your analog voltage passes. With the 10-bit ADC in your PIC there are 1023 steps between zero and Vref (5V in your case) so each step is 5/1023 of a volt high. That works out at about 4.88mV per step or nearly half a degree if it was the voltage from your LM35. It can not measure any level between the steps, only the number of steps your analog voltage has exceeded. For example:
0mV = 0
1mV = 0
2mV = 0
3mV = 0
4mV = 0
5mV = 1
6mV = 1
7mV = 1
8mV = 1
9mV = 1
10mV = 2

the 'mV' is the voltage you put on AN0 and the result is the value from the ADC. As you can tell, it can not distinguish between 1mV and 4mV or from 5mV to 9mV, the result is the same over that voltage range. What further complicates things is the integer math, in your original code you multiplied the ADC value by 5 and divided the answer by 1023. As integer math does not allow decimal places, when you multiply those ADC values by 5 you get 0,0,0,0,0,5,5,5,5,5,10 then dividing by 1023 made them all zero. In fact the first increase in result would be at 99.8C where it would jump from zero to 100 so it's no wonder your check for 15 didn't work!

The fix I proposed was to do the multiplication first, that makes the ADC number bigger before you divided it again and hence made the fractional part smaller.

If you do the AN3 trick I mentioned, the step sizes become smaller, they change from 4.88mV per step to 1.47mV per step or in terms of temperature it measures about 3.5 times more accurately.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top