Helpful ReplyHot!Temperature Indicator Module (TIM) PIC16F19176

Author
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
2019/03/14 05:21:56 (permalink)
0

Temperature Indicator Module (TIM) PIC16F19176

Hallo,
 
i have some porblems by using the TIM of the PIC16F19176, study the AppNote AN1333 and AN2092, and I think die ADC Value of the Temperature Module shoul rise when the temperature increse and fall whe the temperature is falling, but with my code it will be in the other way.
Some one an Idea ????
   // CDAFVR 2x; FVREN enabled; TSRNG Hi_range; ADFVR 2x; TSEN enabled; 
  FVRCON = 0xBA;
  
  ADC_MW = 0;
        ADPCH = channel_Temp_Sensor;
         __delay_ms(1);
        for(i=0; i<3; i++)
        {
        ADC_Value = ADCC_GetSingleConversion(channel_Temp_Sensor);
        ADC_MW = ADC_MW + ADC_Value;
        }
        ADC_Value = ADC_MW / i;

post edited by MarcelC - 2019/03/15 01:35:29
#1
davekw7x
Entropy++
  • Total Posts : 1692
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Left Coast, USA
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F1976 2019/03/14 10:14:38 (permalink)
+1 (1)
Edit...If anyone caught my response prior to this: Superfluous and spurious information is hereby retracted.  ( I had inadvertently clicked "Submit" before it was ready.  Had wrong info.)
 
Anyhow...
[Edit]
I agree that ADC voltage should go up as temperature goes up.
As coffee critic points out in post #8 below,  for temp sensor connection in this device, ADC voltage goes down as temperature goes up.  For a given current, voltage across diode goes down as temperature goes up.  Sorry I missed it.
 [/Edit]
 
I don't know whether the following will help you, but it might help me understand.  I went through the steps with another chip
  • How are you controlling ambient temperature?
  • Since the Temperature module shows chip temperature, the entire circuit should "soak" at a given temperature before performing a reading.  How long are you giving it at each temperature before measuring?
  • Are you making multiple ADC readings and computing the average at each temperature?  Have you tried letting the conversion take place sleep mode? [Edit] I see that you performing an average.  Sorry.
  • What ambient temperature range is covered by your observations?
  • You are apparently using high range.  What is Vdd?
  • Are you keeping TSEN equal to zero except when taking the measurement?  Self-heating of temperature sensors is always a concern.
 
Regards,
 
Dave
post edited by davekw7x - 2019/03/15 20:28:09

Sometimes I just can't help myself...
#2
coffee critic
Super Member
  • Total Posts : 350
  • Reward points : 0
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F1976 2019/03/14 11:34:22 (permalink)
+2 (2)
Please include the ADC code that is in the MCC folder so that we can review all the ADC settings.  I suspect the issue is that the acquisition delay is still the default 5us not the 200us that is needed for the temp indicator.  What code values are you getting?  They should be between 400 and 600 at 4x mode and 5V Vdd.    

n_*$
#3
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F1976 2019/03/14 23:28:24 (permalink)
0
Hello,
 
first the Code:
 
void ADCC_Initialize(void)
{
    // set the ADCC to the options selected in the User Interface
    // ADLTH 0;
    ADLTHL = 0x00;
    // ADLTH 0;
    ADLTHH = 0x00;
    // ADUTH 0;
    ADUTHL = 0x00;
    // ADUTH 0;
    ADUTHH = 0x00;
    // ADSTPT 0;
    ADSTPTL = 0x00;
    // ADSTPT 0;
    ADSTPTH = 0x00;
    // ADACC 0;
    ADACCU = 0x00;
    // ADRPT 0;
    ADRPT = 0x00;
    // ADPCH ANA0;
    ADPCH = 0x00;
    // ADACQ 160;
    ADACQL = 0xA0;
    // ADACQ 15;
    ADACQH = 0x0F;
    // ADCAP Additional uC disabled;
    ADCAP = 0x00;
    // ADPRE 0;
    ADPREL = 0x00;
    // ADPRE 0;
    ADPREH = 0x00;
    // ADDSEN disabled; ADGPOL digital_low; ADIPEN disabled; ADPPOL Vss;
    ADCON1 = 0x00;
    // ADCRS 0; ADMD Basic_mode; ADACLR disabled; ADPSIS RES;
    ADCON2 = 0x00;
    // ADCALC First derivative of Single measurement; ADTMD disabled; ADSOI ADGO not cleared;
    ADCON3 = 0x00;
    // ADMATH registers not updated;
    ADSTAT = 0x00;
    // ADPREF VDD;
    ADREF = 0x00;
    // ADACT disabled;
    ADACT = 0x00;
    // ADCS FOSC/20;
    ADCLK = 0x09;
    // ADGO stop; ADFM right; ADON enabled; ADCS FOSC/ADCLK; ADCONT disabled;
    ADCON0 = 0x84;
    

}

 
At roomtemperature i get a Value of 1100 after use some cooling spray it rises on 1170......
The Aquesition Time should be 250µS and Vdd is 4.75V.
#4
qhb
Superb Member
  • Total Posts : 9684
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Temperature Indicator Module (TIM) PIC16F1976 2019/03/15 01:17:27 (permalink)
+1 (1)
I can't find any device named "PIC16F1976". Did you mean "PIC16F19176" ?
If the ADC clock is Fosc/20, (and I'm assuming Fosc is 16MHz), then ADCLK = 1.6MHz, so Tad = 625ns
ADACQ = 0x0FA0 = 4000 so ACQ time is 4000 * 625ns = 2.5ms
That's way more than the required 25us minimum.
 
#5
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/15 01:44:19 (permalink)
0
You are right! I chenged the device number.....
Do I understand that correctly, you do not think that the Aquesition time is the problem?
 

Attached Image(s)

#6
qhb
Superb Member
  • Total Posts : 9684
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/15 02:24:20 (permalink)
+1 (1)
ok, so I guessed correctly that you are running at 16MHz.
That is a crucial detail that you left out of your first post.
I then miscalculated Fosc/20, which is really 800 kHz, so Tad = 1.25us.
 
Now the acquisition calculation in MCC looks wrong.
The datasheet clearly states that the ADACQ register contains the number of "ADC clocks" to wait.
So, 4000 x 1.25us = 5ms.
Yet the MCC screen shows that 4000 giving 250us.
That would only be correct if it was counting 16MHz oscillator cycles.
Either MCC is wrong, or the datasheet is wrong.
 
 
#7
coffee critic
Super Member
  • Total Posts : 350
  • Reward points : 0
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/15 08:52:51 (permalink)
+1 (1)
AN2798 is the correct ap note for the 16F19176.  The temp sensor is grounded in this part so the slope is negative.  This part does have the DIA calibration value that might eliminate the need for a production calibration step.

n_*$
#8
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/21 00:23:58 (permalink)
0
Now the TIM read out will partially work but the calculated Temperatur is always + 20°C from the actual temperature. When I use another Device it will be +15°C.
I Think the Temperature accurancy should be +-5°C according to AN2798.
But now is the Question, is there something wrong in my code?
 
    #define ADC_RES 4096
    int i ;
    uint16_t TSHR2;
    uint32_t ADC_AVG, ADC_Value;
    float V_out, Vref, offset, Ta ;
    
    Vref= 2.048; // because FVRA2X = 3XFF
    
// Read out TSHR2
NVMCON1bits.NVMREGS = 0x01;
NVMADRL = 0x16;
NVMADRH = 0x81;
NVMCON1bits.RD = 0x01;
while (NVMCON1bits.RD == 1);
TSHR2 = (NVMDATH<<8)+NVMDATL;

// calculating offset Value
V_out = TSHR2 * Vref ;
V_out = V_out / (ADC_RES -1);
offset = V_out * 270 ;
offset = 405 - offset;
offset = 90 - offset;


while (1)
  {
    // Read AVG ADC Value for the TIM Module
        ADC_AVG = 0;
        for(i=0; i<5; i++)
        {
        ADC_Value = ADCC_GetSingleConversion(channel_Temp_Sensor, 4000);
        ADC_AVG = ADC_AVG + ADC_Value;
        }
        ADC_Value = ADC_AVG / i;
 // Calculate Temperature Ta
        V_out = ADC_Value ;
        V_out = V_out * Vref;
        V_out = V_out / (ADC_RES -1);
        Ta = V_out * 270 ;
        Ta = 405 - Ta ;
        Ta = Ta + offset ;
        
     
    }
 

#9
coffee critic
Super Member
  • Total Posts : 350
  • Reward points : 0
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/21 09:48:04 (permalink)
0
20C error would not have surprised me on the old temp indicator but this one should be much better. 
Did you verify that the value you are reading in TSHR2 matches what you are seeing in the debugger? (printf)
 
Here are some other thing to check,
Verify that sensor is high range (3X) in FVRCON.
Verify that the reference is 2X FVR.
Try oversampling as mentioned in paragraph 2.1 to see if the value changes. There may be a single point error on the first sample (only) sample if the oversampled value is different.  
Measure the FVR with the ADC to calculate the actual FVR value.  This will also require oversampling.  This step will be not needed once we have determined why we are not seeing the DIA FVR values.
Lastly, verify all the math in a spread sheet to make sure that it matches the output of the chip. 
 
 

n_*$
#10
coffee critic
Super Member
  • Total Posts : 350
  • Reward points : 0
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/21 11:42:36 (permalink) ☄ Helpfulby MarcelC 2019/03/25 23:16:16
0
Also check out errata 1.6.  This might also explain some of the error. 

n_*$
#11
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/25 07:28:05 (permalink)
0
coffee critic
Also check out errata 1.6.  This might also explain some of the error. 


Thanks alot!
I have changed to FOSC/64 and now the measurement will work perfect!
#12
coffee critic
Super Member
  • Total Posts : 350
  • Reward points : 0
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/25 10:13:28 (permalink)
0
That is good to know. 
Question: How perfect is perfect? 
Was this using DIA90?
Were you able to get a part with usable FVR values?
Did you need to use oversampling or was a single conversion enough? 

n_*$
#13
MarcelC
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2018/08/31 05:01:52
  • Location: Germany
  • Status: offline
Re: Temperature Indicator Module (TIM) PIC16F19176 2019/03/25 23:11:03 (permalink)
+2 (2)
I Use the sourcecode above (fix value for FVR), and test three devices from -10°C - 60C°
the biggest deviation was 3.86°C at -10°C. (see attached picture)
I also opend a case at microchip support due to the unreadable FVRX* values odf the DIA.
 

Attached Image(s)

#14
Jump to:
© 2019 APG vNext Commercial Version 4.5