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.

[SOLVED] PIC Design, State of Madness, Mayhem, Trauma

Status
Not open for further replies.
Syntax error. t

there is no such command

- - - Updated - - -

@bluelasers
you still sure aboud ADCON2 = 0XBE
????
 

Yes the ADCON = 0xBE should be correct. My question is how do you know it is being set.

DEFINE ADC_BITS 10 is from the manual. Define is a command. ADCIN uses it. (ADC_BITS that is.)
 

THERE IS NOT SUCH COMMAND


Yes, there exists a DEFINE syntax, i.e DEFINE LCD_BITS, but there is no "ADC_BITS"
 

Okay, that was another compiler. I guess.

Try adding this:
Define ADC_SAMPLEUS = 50
 

This would probably increase the data acquisition time? is that a correct action to make bluelasers?

- - - Updated - - -

if left to default the acquisition time would be less, means a faster reading
 

It should, I would have thought that ADCON2 would have done that. As you are driving the register directly.

Another problem that I just noticed is. Do you set the TRIS and ANSEL bit for the analog inputs? If not you need to do that first.

- - - Updated - - -

Less is better. But there is a minimum and below that it will not work. Your hardware setup can also affect it. Currently I am just trying to get it to work. Then we will reduce the acquisition time to speed things up.
 

You can remove the delays before Adcin instructions, they wont help at all.

The delay you need is built in to the Adcin instruction and you set it at the beginning of the program with "Define ADC_SAMPLEUS = x" where x is the number of microseconds the ADC will wait between selecting the channel and taking the measurement from it. Try adding this near the beginning of your program:
Define ADC_SAMPLEUS = 50

If you still find the readings interact with each other, try increasing the number up to a maximum of 255. Even at 255 it should be faster than before if you remove the other delays.

Let me know if that fixes it.

Brian.
 
what about the ADCON2, do I set the ADCON2 = 0XBE ????

- - - Updated - - -

@bluelasers

for the analog inputs, the adcin presupposes that the port is used as analog
and I have this added:

ConfigPin PORTA = Input
ADCON1 = 0
ADCON2 = 0xbe
 

Modified:

Adcon1 = 0x0c

- - - Updated - - -

Vref+
Vref-
???????

Must be plugged in to Vss and Vdd?
 

The bits are shown in "Register 19 - 2" in the data sheet which refers to ADCON1.
When bit 4 = 0 the upper ADC reference is VDD, when it is 1 the reference is taken from pin AN3
When bit 5 = 0 the lower ADC reference is VSS, when it is 1 the reference is taken from pin AN2.

So to use VDD and VSS make sure bits 4 and 5 are both zero. Set the other bits according to whether the input pins are analog or digital.

I would be inclined to leave ADCON2 alone and use "Define ADC_CLOCK =" in the program instead. I have not checked but it could be that the compiler over-rides any value you give ADCON2 with the defined value each time you use the Adcin instruction.

Brian.
 

I made :
Define ADC_SAMPLEUS = 100


still one input affects the other

- - - Updated - - -

still need to make changes on the software? or the problem now is summarized to hardware?

- - - Updated - - -

linking to the code I have posted,

the Light and moisture readings are very logical, and varied accordingly with real external environment.
There remains two problems:

Readings from the LM35DZ (tried to disconnect the 1k resistor)
affection from one reading on the other.

- - - Updated - - -

the actual current temperature here is: 25 C

the output of the LM35DZ, based on the code I have posted, and based that I`m connecting a 0.1uF between Vss and Vdd of this sensor (As well as all other sensors) is:

38C 39C 41C 42C 44C 45C 47C 48C 53C 51C 52C 55C 57C 58C 59C 60C 61C 62C 63C 64C 65C
 

I think the only sure way to tell is to use a DVM connected directly between VSS and the PIC pin where the LM35 connects to. Measure the voltage on the DVM and see if it really is changing. If it is, you need to look toward an electrical solution, if it isn't the problem is still in the software.

You should bear in mind that the output of the LM35 is very small and only changes by 10mV/1C, with an ADC resolution of ~5mV you would only expect to measure to 0.5C accuracy at most and you lose some of that in the calculations. If you want better accuracy you have to amplify the LM35 output so the change is much bigger, for example a x10 amplifier will improve the accuracy by 10 times. As you are dealing with a fairly small range of temperatures that might be a good option.

Alternatively, you could consider replacing the LM35 with an MCP9701A which is pin compatible (assuming TO-92 package) but is optimized for use with 10-bit ADC by producing 19.5mV/C output which is four ADC steps per degree C. It allows you to take more accurate readings and also simplifies the calculations but you do have to remove a fixed offset in it's output of ~400mV. I use them extensively and find them very accurate and reliable.

Another alternative, if possible is to use a lower than VDD regulated voltage on AN3 and change bit 4 of ADCON1 so it uses it as the upper reference. At the moment you have 5V VDD which means that to use the full range of the LM35 it would have to work at up to 500C ! (don't try it :shock:) If you make the upper ADC reference say 1.024V, for which you can buy precision regulators, it would still measure to beyond 100C but be 5 times more accurate because the ADC steps would be 5 times smaller. The drawback to this method is that the smaller steps make it more prone to picking up noise and interference.

Brian.
 

What is the form of the analog amplifier you were talking about?

What about solving issue of interfacing values?

I will see when the presentation date is and set a constant value for temperature accorded to that day

This is the only realistic solution

You need a Ph.D to accomodate temp sensors :(
 

All you need is an op-amp, preferably one that will work without needing additional power supplies. Wire it as a non-inverting amplifier. Connect the input to the LM35 and the output to the ADC pin. You can easily use a variable resistor to set the gain and as a bonus you can use it to calibrate the output. What you want to achieve is the biggest range of ADC voltage possible (ideally 0V to 5V) when the LM35 is producing the lowest and highest output voltages you are likely to encounter. For example the temperature range 0C to 100C produces 0V to 1V from the LM35, if you amplify with a voltage gain of 5, the ADC values will go from zero to 1023 (the maximumum) giving a temperature resolution of 100/1023 = ~0.09C instead of ~0.48C.

Brian.
 

Code:
		If i < 10 Then
		
		Adcin 0, tempdig
		
		WaitMs 1000
		
		k = tempdig
		tempan = k * 5 / 1023
		kk = tempan
		kkk = kk * 100
		kkk = kkk / 2
		kkk = kkk - 20
		i = i + 1
		accuratetemp = accuratetemp + kkk
		Goto acctemp
		Else
		Endif
		
		accuratetemp = accuratetemp / 10
		accuratetempp = accuratetemp - 30

This code is interesting. Shouldn't it be:
Code:
		If i < 10 Then
		
		Adcin 0, tempdig
		
		WaitMs 1000
		
		k = tempdig
		tempan = k * 5 / 1023
		kk = tempan
		kkk = kk * 100
		i = i + 1
		accuratetemp = accuratetemp + kkk
		Goto acctemp
		Else
		Endif
		
		accuratetemp = accuratetemp / 10
 

So you just had cancelled the subtraction of 30?


Same thing the output is not bounded nor logical it can fluctuates from 38 to 65 than randomly shuts to 15

- - - Updated - - -

@betwixt

I had connected a multimeter to see the voltage across each sensor output.

The ldr and soil moisture have very logical values

But the temperature sensor that must outputs 0.25 (because the weather here now is of 25C ) is outputting only 0.03 !!!!

Amazing voltage drop

So this signal must be amplified

- - - Updated - - -

Please post a pic of the op-amp you adviced or tell me its technical name

- - - Updated - - -

Please include its diagram connection

- - - Updated - - -

UA741CN

Would that do the job?

- - - Updated - - -

This is its internals

I connect +Vcc to PIC +5V
-Vcc to PIC ground

the OUTPUT to the analog pin

and pins 2&3 for?

- - - Updated - - -

This is its internals

I connect +Vcc to PIC +5V
-Vcc to PIC ground

the OUTPUT to the analog pin

and pins 2&3 for?

- - - Updated - - -

The output of the LM35DZ, is the input to the UA741CN

means I connect its to the pin # 3

than take a wire from pin # 6 to the RA0 of the PIC

Correct?

- - - Updated - - -

as for pin # 2

I connect to it two resistors, as shown in the above Non-Inverting Amplifier picture.

the gain is concerned about the values of the resistors.

well, the output of the LM35DZ, to be correct, and according to the current weather states, must be equal to 0.25 (25C) for example, but it only outputs 0.03V, due to the voltage dip you had cleared before.

so the gain must be x10

So Av = 1 + (R1/R2) = 10

R1/R2 = 9

R1 = ? R2 = ?

Is there any logic error in what i had posted?
 

Attachments

  • opamp.jpg
    opamp.jpg
    7.9 KB · Views: 64
  • non-inverting.jpg
    non-inverting.jpg
    5.7 KB · Views: 61

I also removed:
Code:
kkk = kkk / 2
		kkk = kkk - 20

Something is wrong. 0.03V is really low. Did you include the resistor? If not then the sensor may be dead.
 

Yes, a 1k resistor is still there

- - - Updated - - -

So...?

the 0.03V must be amplified to 0.3V

By the way, what is the maximum voltage the MCU could afford as an input?
 

Several points there...

Something is wrong if the LM35 is producing 0.03V, if it can't produce 10mV per degree it will never give you a temperature reading. Assuming it isn't faulty and it is connected correctly, there must be something shorting it's output. My first thought is the PIC pin is in digital mode and driving low instead of being in analog input mode. Try temporarily disconnecting the LM35 voltage at the PIC pin and check the voltage again.

The 741 is NOT suitable for this application, it is a very old and poor performance device anyway but it has two limitiations that prevent it being used in your project. Firstly, it needs at least 9V supply before it starts to work properly and secondly, it's output voltage range does not include ground or ths supply line. So even if you connected it's supply pin before the 7805 regulator (which would allow it to power up properly) it would never let you measure low temperatures because it would always send a small voltage to the ADC, even if you froze the LM35.

The best solution is to use a rail-to-rail op-amp which can produce output voltage right down to zero and choose one that can run on the existing 5V supply. There are many types on the market that can do this. Alternatively, you can still use the 741 if you give it a negative supply voltage as well as the positive one. For example it you gave it -10V and +10V it would see 20V and be happy to operate. The output voltage you need would than be within it's capability. It is a more complicated solution than using a different op-amp.

The PIC analog input must never go negative with respect to VSS and must never go more positive than VDD or it will be electrically damaged. The minimum ADC voltage it can measure is set by -Vref and maximum by +Vref which can be VSS and VDD or the voltages you supply on AN2 and AN3 depending on configuration.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top