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 support@ccsinfo.com

INTERNAL_TEMPERATURE_INDICATOR PIC16FLF1824

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
maxikys



Joined: 25 Jul 2013
Posts: 17

View user's profile Send private message AIM Address

INTERNAL_TEMPERATURE_INDICATOR PIC16FLF1824
PostPosted: Tue Jan 21, 2014 3:34 am     Reply with quote

I develop DEVICE "real time clock", the clock will be used for (-30 ... +40). To adjust the frequency of quartz want to use a software adjustment. In 1824 has an internal temperature sensor.
"Reading" I get ADC value of 445, according to AN1333 is 240 degrees Smile
in room 23 degrees. Battery powered device, 3 volts. needs saving mode.
HELP!

Code:

#include <16lF1824.H>
#device adc=10
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(xmit=PIN_C1,RCV=PIN_C2,BAUD=9600)

//==========================================
void main()
{
int16 result;

printf("Start:\n\r");

SETUP_VREF(VREF_ON | VREF_ADC_2v048 | TEMPERATURE_INDICATOR_ENABLED | TEMPERATURE_RANGE_HIGH);

setup_adc_ports(NO_ANALOGS,VSS_FVR);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(TEMPERATURE_INDICATOR);
delay_us(200);

while(1)
  {
   result = read_adc();
   printf("%lu \n\r", result);
   delay_ms(500);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 3:42 am     Reply with quote

What is your supply voltage?.
Can't start any calculation involving the temperature sensor without this.

As a general comment, the temperature sensor is meant to be used with the ADC using Vdd as it's reference. This is because the temperature sensor itself uses Vdd, and if you use a different reference you introduce another error. The formula for ADC counts assumes this is the reference being used. Probably why your value is much higher than expected....

I see you do say you are using 3v.
It gets really complex with a battery device.

What you have to do, is connect the ADC using Vref as Vdd, and the internal Vref as an input.
Then read the ADC value from this.
You can then calculate your supply voltage as it changes.

The Temperature reference, actually produces a voltage _below_ the supply rail. So you then read the counts this is giving, and with the now 'known' supply voltage, you can calculate the voltage drop the temperature reference is generating. Divide this by Vt*4 (which ideally you calibrate for each device, since it changes quite a bit between chips), and you have your temperature.

As I said before though this gives the PIC die temperature, not the external temperature, so will not directly allow you to calibrate the crystal, since it will change according to what the PIC has been doing.....
temtronic



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

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 6:43 am     Reply with quote

comments:
If 'the clock will be used for (-30 ... +40)' means -30*C to +40*C temperature range then you'll have to do extensive tests at those temperatures! Xtals and batteries do NOT like those temperatures and will give poor performance, especially batteries.You must read the datasheets of all devices(PIC,xtal, battery,caps,etc.) to see even IF they can be used.If they can,look at the specs! xtals and cap values will vary a LOT from 'nominal',batteries typically will have 1/3 to 1/4 their life and reduced voltage.

As to xtal 'stability' consider using the PIC 'primary osc' for the 'RTC clock'. There's a software RTC program in the code library that does work,easy to alter for your PIC.
For power, just use a bigger battery.While you don't say what power you need/duration I know you can get over 5 years out of 4 AA batteries.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 9:07 am     Reply with quote

I think perhaps the trying to use sledgehammer to crack a nut analogy applies here.

You will never get really good long term stability out of any oscillator, without a lot of work. If you try to temperature compensate the tuning fork type crystal, the inaccuracy of the temperature measurement you have will lead to cumulative errors, and with the other error sources you won't be compensating for (every other component....), will have spent a long time to get not that much better results.
There are crystals designed to give much better accuracies, or you could use a TCXO module. Look at the Maxim DS32KHz.

As Temtronic says, you can get accuracy that will be acceptable for a few hours, by simply using the internal RC oscillator, and temperature compensating this. Then if you need really good long term accuracy, attach something like a MSF receiver, and power this up for a few seconds every day, and use this to keep the time set accurately. Far better for really long term stability, but we come back to needing to know what sort of accuracies you hope to achieve.
Remember that if battery powering the PIC, for lowest consumption you will be putting the chip to sleep a lot of the time. During these intervals you won't be reading temperatures or correcting anything. The more time the chip spends awake doing corrections, the more the consumption rises.

Duplicate and emphasise his comment about batteries.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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