CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC10F322 - Internal Temperature Indicator
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
viki2000



Joined: 08 May 2013
Posts: 233

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 12:54 am     Reply with quote

Memory free for temperature? 10%, worst case 15%.
Unfortunately on production site there is no chance to calibrate using external communication with a PC or another device. There is no option to write or read the firmware. The PICs will be used as they come with my programmed code done by Microchip. The end product is a tiny board which is tested at the end only for functionality.
Microchip said they do not calibrate for me prior programming. 50K is too small quantity.
The temperature detection is not “a must”, but a “good to have” feature.

I asked Microchip about +/-19% FVR tolerance.
The answer:
Quote:
If you are looking for a device with a Fixed Voltage Reference the 10F322 device is obviously a device you do not want to use. Instead I would recommend having a look at some of the following devices. All devices listed below should be 8 pin devices.
PIC12F1571
PIC12F1501
PIC12F1572
PIC16F18313
PIC12F1822
PIC12F1840

But I need SOT-23-6.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 05, 2015 5:11 am     Reply with quote

hmmm given say 50 words of code space I don't think it is possible to use the temp sensor. If say 10 words are used for the 'real' temp. function( read the sensor, if (cold,Ok,hot), flash LED ?), that only leaves 40 words for the 'auto calibration' routine.
As you've already invested a LOT of time into this, you might as well see if you can cut the 'auto calibrate' code as Mr. T. suggests. Show us that and perhaps we can reduce or modify it to fit. Obviously only use unsigned integers, NO division, etc. As you only need a 'rough' result (too cold, too hot) the math would be small and simple ie: ... if adc_result<90 flag=too_cold, if adc_result>192 flag=too_hot).

I'd cut the 'real' temp function first to see how much code is needed. Don't worry about the 'calibration' function, just the read adc, cold/ok/hot ?, flash LED and see what code space that takes up. Hopefully not much, less is better giving you more for the 2nd part, the 'auto calibrate' function.

Bottom line, you'll need a LOT of clever 'tricks' to do it.

Jay
viki2000



Joined: 08 May 2013
Posts: 233

View user's profile Send private message

PostPosted: Fri Aug 07, 2015 12:27 am     Reply with quote

Me:
Quote:
“Page 174 of the datasheet, parameter AD06 VREF – Reference Voltage with Note 3 and Note 5.
Note 3 refers to FVR as reference input and Note 5 specify it as 2.048V or 4.096V.
But on page 84, chapter 15.1.3 is mentioned “The FVR is only available as an input channel and not a VREF+ input to the ADC.”
http://ww1.microchip.com/downloads/en/DeviceDoc/40001585C.pdf
Is it not that a contradiction?
Which one is true?”

Microchip:
Quote:
“Our apps team has confirmed that Note 5 on page 174 is indeed an error. It has been marked for correction.
In regards to Note 3, it is intended to be a generic statement and is found is most if not all our data sheets. If you don’t have the ability to select a positive voltage reference other than Vdd, than Vdd is your selection. It could be worded better.”
viki2000



Joined: 08 May 2013
Posts: 233

View user's profile Send private message

PostPosted: Tue Aug 11, 2015 3:48 am     Reply with quote

Since almost 2 weeks I have on my desk the setup with PIC10F322 communicating with PIC18F4550 attached to the small display showing ADCti, ADCfvr and temperature without calibration. The VDD is 4.9xxx not very stable for the second and/or third decimal point.
The ADCfvr is jumping up/down 1 digit 52/53.
The ADCfti is jumping up/down 1 digit 139/140.
The calculated temperature jumps between 27-39°C.
By calculation, and also practical, I noticed a jump of 1 digit error of ADCfvr leads to 8°C error and 1 digit error of ADCti leads to 4°C error.
It does not matter the value or if it is calibrated, important is the range of imprecision.

If we trust the datasheet and consider the FVR tolerance +/-19%, then we are in trouble when the VDD is not constant and we want to determine the VDD value. The error is too big to be usable.
It is enough to take 1 example of VDD=5V and supposing we do not know that is 5V, so we want to find how much is it by measuring it using FVR as described in AN1072
http://ww1.microchip.com/downloads/en/AppNotes/01072A.pdf
ADCfvr=1.024*((2^n)-1)/VDD=1.024*255/5=52.224, so we can say ADCfvr must show 52 or 53 as my system shows.
With FVR +/-19%, we get instead of 1.024 two values 0.82944 and 1.21856.
Then the ADCfvr may be ADCfvr1=0.82944 *255/5=42,30 or ADCfvr2=1.21856*255/5=62.14, so we can take ADfvr1=42 up to ADCfvr2=62.
If we calculate back the VDD, supposing you do not know it is 5V, then you get VDD1=1.024*255/42=6.21V and VDD2=1.024*255/62=4.21V
With this big error range of 4.21-6.21V finding the VDD when is not stable or known we arrive to such big errors in measuring the temperature, only due to FVR tolerance, that makes it totally unusable.
For stabilized VDD=5V , mode 4 and 27°C we should get for ADCti the value 139 – calculated.
Assuming the ADCti is stable 139 with zero tolerance, because the VDD is in reality 5VDC even if was measured with error 4.2-6.2V, then for the calculated temperature we get for VDD1 and VDD2 between -76°C up to +96°C. Just use ADCti=139 and ADCfvr1=42 and ADCfvr=62 in the formula from previous page assuming we have VDD=5V and 27°C in reality. That is 172°C range.
That leads clear to the fact that even with calibration we cannot use temperature indicator on PIC10F322 with unknown VDD and AN1333 makes no sense at all for this PIC as long as FVR tolerance is +/-19%.
The temperature indicator inside PIC10F322 must be used at known VDD without FVR.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 11, 2015 4:54 am     Reply with quote

You've put a lot of time and effort into your project and reporting your observations here should help others doing similar work! As you've found out an unknown or unstable VDD makes using the internal temp. sensor, well, useless. It requires a very stable VDD and that means a 'strong' power supply.One capable for 10X the normal current draw using a precision Vref as the regulator. Normal '7805' types are at best +-5%, NOT suitable for the task.As well a batch of 10 units will not be even close to the same VDD!
I do applaud your effort of this !!

Jay
joergn



Joined: 15 Jul 2010
Posts: 15
Location: Hamburg Germany

View user's profile Send private message Visit poster's website

PostPosted: Fri Sep 09, 2016 3:46 am     Reply with quote

I am considering to use the 16F1765 internal TEMP_INDICATOR also and find this discussion quite late...

The main function I do with my pic project is to measure the LED junction temp with my new patented principle - so I have done lots of work related to measure the temp with power diodes, quite precisely. On my main project I resolve into the mV range doing some more samples summing into a 16bit var.

To obtain the final resolution of temp reading and probably also accuracy with this internal PIC diode, a single ADC conversions is simply not fine enough, you may need some statistics, doing an average of 16 or 32 samples.

There are also some tricks possible to increase the ADC resolution by giving statistic noise on the ADC reference. If there is no such noise in the system present the resolution can not be increased by the averaging.

I also avoid float math and if possible I devide by power of 2 : >> ;-)

VDD I regard as to be not that important, since it must be simply high enough, like it is written inside the datasheet. More important is the internal current regulator of the temp indicator itself, which I can not find any tolerance on it. This is what determines the quality ;-) So you measure differential from VDD just over the diodes, if VDD is put as Vref+ to the ADC. This is the best possible ADC setup, because you do not depend on VDD Very Happy
viki2000



Joined: 08 May 2013
Posts: 233

View user's profile Send private message

PostPosted: Fri Sep 09, 2016 4:07 am     Reply with quote

At that time, I opened a similar discussion on Microchip Forum only to get more input from different experts.
http://www.microchip.com/forums/m881560.aspx
I tried the code with CCS and XC8 compilers.
As conclusion from different sides, also based on my measurements: don’t lose your time with the internal temperature indicator – it is not accurate, don’t rely on it unless you have no other option, but then you must calibrate each chip and even then you have tolerances for measurement. So use it if you can live with those tolerances.
If you find any other method to improve the temperature measurement using the internal temperature indicator, then it would be nice if you can share your findings.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 09, 2016 4:55 am     Reply with quote

I've never understood why anyone would put an internal temp indicator inside a micro. From a design view, it can only measure the internal temp which will widely vary depending upon processor speed and what it's doing. IE : more I/O or operations will raise the temp. It's NOT designed or useful as a 'local room air' temperature indicator or similar process controller.
I think some big mfr wanted it in THEIR product and Microchip thought it might be a nice peripheral to offer to the general public.
If anyone has actually used it, please post 'how and why'. tnx.

Jay
joergn



Joined: 15 Jul 2010
Posts: 15
Location: Hamburg Germany

View user's profile Send private message Visit poster's website

PostPosted: Fri Sep 09, 2016 5:54 am     Reply with quote

temtronic wrote:
I've never understood why anyone would put an internal temp indicator inside a micro.
Jay


You want to monitor the PCB temp to shut down or regulate back the power you move over the board. The shut down region may is your point of calibration, which is in a production if it is hot not very nice.

If in case you have a LED bulb, which has very often a potted compartment, the internal temp is quite equal distributed thus you can regulate back the temp by an internal sensor of the control IC.

The other motivation is saving a port pin, which you want to use for some more important task. Not everybody has the space for many pins.

For this tasks you don't need a very precise temp, should be very cheap like for automotive.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 09, 2016 5:21 pm     Reply with quote

Thanks for the explanation ! The 'cheap like auto' ALSO means not precise or accurate so you NEED to calibrate every unit or accept a WIDE range as being 'valid'.
I can also see that the physical layout of the PCB and it's orientation in the real world will affect the int. temp sensor. Somethings NOT usually considered until rev 3 or 4 and months have gone by....BTDT !
I'm 'old school' and always have a free pin or two. One for a diagnostic LED / serial to PC / other use. Also in the 'old school' department is accurate, repeatable measurements. It's often cheaper to add a component (like an LM34 type device in this case) than spend days doing R&D to get the internal temp sensor working satisfactorly. Having to adjust code, resample a sensor 16 times or more, to be sure the reading is OK really does cost $$.

Jay
joergn



Joined: 15 Jul 2010
Posts: 15
Location: Hamburg Germany

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 12, 2016 3:45 am     Reply with quote

temtronic wrote:
Thanks for the explanation ! The 'cheap like auto' ALSO means not precise or accurate so you NEED to calibrate every unit or accept a WIDE range as being 'valid'.

Jay


That's not a problem over a serial interface, which I use and so
I had to kick out the ext PCB temp sensor.

Even if you have an external sensor on the PCB it can not be mounted
on the same position like a power FET or other device you may want
to temp monitor.

I don't have a problem if you are in doubt that there is any sense
for the internal feature. But I am in doubt that if there is a feature in a chip made available, that it can not be used for any body.

I will check this feature on my device, which has 10bit ADC just to see if I can use it or not.

I must wonder how much time people spent in groups and then say their R&D time is so costly they can not spent efforts on their projects saving possible BOM costs, just by software ?
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 12, 2016 5:29 am     Reply with quote

With R&D costing $100/hr I can easily justify spending 20 cents for an MCP9700 that is easy to code, known to work and far more accurate 'out of the box' versus the hours (or days) to get that internal temp sensor working. From what I've read on the Web, a LOT of time has been wasted getting marginal performance out of the internal sensor. It's one of those 'sounds good' but when you go to use it, it just isn't worth the time and effort.
As a 'school project' or something to do on a rainy day, yes, I can see experimenting with it but I just can't see using it, especially if the software to get it to run 'nice' is big, too big for a small PIC!
It reminds me of the TPMS in cars, nice technology but not required.
Jay
joergn



Joined: 15 Jul 2010
Posts: 15
Location: Hamburg Germany

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 12, 2016 10:49 am     Reply with quote

Code:

void pcbtemp(void)
{
    disable_interrupts(INT_TIMER3);
    setup_vref(TEMPERATURE_INDICATOR_ENABLED|TEMPERATURE_RANGE_HIGH);
        set_adc_channel(TEMPERATURE_INDICATOR);
        dummy = 1;
        dummy = 2;
        dummy = 3;
        dummy = 4;
        dummy = 1;
        dummy = 2;
        dummy = 3;
        dummy = 4;
        read_adc(ADC_START_ONLY);
        while (bit_test(*ADCON0, 1));
        dummy= read_adc(ADC_READ_ONLY);
                read_adc(ADC_START_ONLY);
        while (bit_test(*ADCON0, 1));
        dummy=read_adc(ADC_READ_ONLY);

        setup_vref(VREF_OFF);
   
            if(dummy < 700 && dummy > 10)
            {   
                pcbbuf+=dummy;
                if(pcbc>15)
                {pcbc=0;
                debugval3=pcbbuf;
                pcbbuf=0;
                }
                pcbc++;
            }
        enable_interrupts(INT_TIMER3);
}



I have just tested this on my 16F1765 device and streamed
out the debugval3 over the serial.

The device does the first ADC conversion totally bad and with the
second conversion there are still a number of bad conversions
included. Therefore a primitive filter to get rid of bad conversions.
Single conversions are jumping too much for being usable in a later
formula. So a buffer of 16 samples. PCB temp is not to be
considered to change fast.

Did a quick test by placing a finger on the MCU and also a push with freezing spray - looks not too bad to give a try for further eval.

MCP9700 I use normally also as standard, but on this board no pin left for it. The serial or debugger is much more important to identify possible problems like bad ADC readings.

I have a 2% 5V regulator and using this as ADC ref at the moment.

school, old school ......... I am always learning and interesting to investigate modules my self. What I read from "experts" in the web is today in most cases to doubt. Today the internet is overloaded with junk.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 12, 2016 11:15 am     Reply with quote

I don't use the 16F1765 but am curous if there's a 'bug in the die' that causes the bad readings. Is it only the internal temp sensor or seen on other ADC inputs or perhaps the method(sequence of code) used to acquire the reading ?
I also read any analog 16 times and average the results,though I've never seen really 'bad' ADC results.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 12, 2016 11:42 am     Reply with quote

Quote:
read_adc(ADC_START_ONLY);
while (bit_test(*ADCON0, 1));
dummy= read_adc(ADC_READ_ONLY);

I have a question. Why do you write code like that ? I mean, it's totally
unnecessary, it generates huge amounts of code that is just basically
churning.

Let's look at what the compiler generates for your ADC read code.
Below, I have the three lines of your code, followed by the single line
of how I would write it.

First you start the conversion. Then you have the middle line which polls
the ADC \Done bit. But that's totally unnecessary, because your 3rd line
generates code to do the same thing, and much more compactly.

But if you compare your 3 lines with my 1 line, my code does the whole
thing much more efficiently. It does it all with one line of source.
Code:

.................... read_adc(ADC_START_ONLY); 
000F:  MOVLB  01
0010:  BSF    ADCON0.GO  // Set the GO bit to start the ADC conversion

.................... while (bit_test(*ADCON0, 1)); 
0011:  CLRF   @7A
0012:  MOVF   ADCON0,W  // Read the ADCON0 register
0013:  MOVWF  FSR0L
0014:  MOVF   @7A,W
0015:  MOVWF  FSR0H
0016:  MOVF   INDF0,W
0017:  MOVLB  00
0018:  MOVWF  @@22
0019:  BTFSS  22.1 // Is ADCON0.1 (\Done) = 0 ?
001A:  GOTO   01D  // If so, jump to next section   
001B:  MOVLB  01
001C:  GOTO   011  // If not, go to the top and read ADCON0 again

.................... dummy= read_adc(ADC_READ_ONLY); 
001D:  MOVLB  01
001E:  BTFSC  ADCON0.GO  // Is \Done bit = 0 ?
001F:  GOTO   01E       // If not, stay in loop until it is.
0020:  MOVF   ADRESH,W   // If so, read ADRESH to get the result
0021:  MOVLB  00
0022:  MOVWF  dummy
.................... 
.................... dummy = read_adc();   // This is my code
0023:  MOVLB  01
0024:  BSF    ADCON0.GO   // Set the GO bit to start ADC conversion
0025:  BTFSC  ADCON0.GO   // Poll the \Done bit.  Jump if it's = 0.
0026:  GOTO   025
0027:  MOVF   ADRESH,W    // Read ADRESH to get the result
0028:  MOVLB  00
0029:  MOVWF  dummy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group