Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The LM35 is a precision temperature sensor. It is guaranteed accurate to C at 25C (At different temperatures it is less accurate! but it is never more than 2C inaccurate and it probably is not this inaccurate anyway it's just the manufacturers maximum limits that may apply). Typically is stays accurate to within C over its temperature range so this is a good general purpose sensor and it's easy to use. It generates a linear output voltage using a centigrade scale - generating 10mV of output voltage for every degree centigrade change and there are several versions for operation over different temperature ranges: LM35 LM35C LM35D
Note: The project code calculates the temperature in Fahrenheit and generates both Centigrade and Fahrenheit outputs to the serial port.
Alternatively you could use an amplifier to scale the LM35 output up which would make the
ADC less sensitive to noise but for this project it is simpler not to do so. Note: The large decoupling capacitor on the supply input of the 12F675. This reduces noise overall and gives a more consistent reading. However using a plug block and ADC is not a very good idea as there is no ground plane and no control over current paths which you would be able control in a pcb. In a commercial system the internal ADC is often not used at all as it is essential to separate the noise introduced to the ADC using separate grounds and shielding - some designs encase the ADC in a custom metal shield and along with a ground plane connecting to the shield gives the best possible result. To overcome noise problems on the ADC the software averages the input readings so you get a better result.
Solderless breadboard
Add the components (at top right to) the temperature recorder - wires and R3,R4,R5 and the LM35 temperature sensor (U4) and the decoupling capacitor C4.
Bottom of Form
Software operation
The most interesting parts of the software are shown above. The variable val is an unsigned int so the maximum value it can store is 65535 The reference in use is 2.5V so for the 10bit ADC each ADC bit is worth 2.5/1023 = 2.44mV If you work out values generated for a maximum temperature of 100C using the scale factor 2.44mV (or 244/100) 100 * 10mV = 1.0V 1.0V/2.44mV = 410
410 * 244 = 100,040 which will not fit into an unsigned int. So this scale factor does not work for all input values By using a little maths it can be made to fit -you need to reduce the top number to fit. e.g. 410 * 122 = 50,020 which does fit. Dividing by 50 gets back to the correct scale factor of 244. So the scale 122/50 works for all input values. This is an example of avoiding the use of floating point variables which take up too much resources. You can still make the system work but you have to be careful when using fixed types and you have to check all input values and outputs to make sure they fit.
Averaging
Averaging would be better done in the PC as it has more resources - the same goes for calculating and displaying the temperature in Fahrenheit but this gives a demonstration of what you can do. Note: The RAM is used up since a bug in MikroC 5.0.0.3 puts strings int RAM - in future versions this will be corrected.
The left most value is the RAW ADC value, the next is the temperature sensor output in degrees centigrade and the next is the temperature sensor output in degrees Fahrenheit. Note: You have to put in the decimal point so the above readings are: 234 C 741 F 23.4C 74.1F