How to calculate core temperature ?

I set ADC1CON =BIT1+BIT7+ BIT8 + BIT10 ; // (gain =4, chanel = internal temp sensor)

In interrupt read ADC value :

ulADC1Result = ADC0DAT; // Read ADC0 result

ulADC1Result = ADC1DAT; // Read ADC1 result

And calculate temp

temp=((float) ulADC1Result * ((Vref/gain)/0xFFFFFF)); //its must be voltage of sensor;Vref=1.2;

temp = (temp-0.096)/0.00028 ;// subtract voltage at 0 C and divide at a temperature coefficient;

But value does not correspond to the expected.(-166.7)

Please tell me where to look for a mistake?

Firstly, I recommend that you leave the gain setting at 1 for this measurement.

So ADC1CON should be configured as:

ADC1CON = BIT7+ BIT8 + BIT10 ;

Also, when converting the ADC result to a voltage, you need to take into account that the ADC output is 2's complement - see this thread for further details:

http://ez.analog.com/message/15605#15605

Temp should be set as follows:

Temp = (2*(Vref/gain)/0xFFFFFF) * ADC1DAT (Note, ADC1CON bit 11=0)

Now that you have a valid voltage level, you will be able to generate a temperature value as follows:

temp = (temp-0.096)/0.00028