Select Page

The PIC10F322 is equipped with a temperature indicator module designed to measure the  operating temperature of the silicon die.

Why is it there – What is the use monitoring the die?  It is useful to monitor the temperature of the silicon die of the microcontroller to ensure that it is operating within its limits of thermal rating. In enclosed products, the microcontroller’s internal temperature can be monitored for protection of other components that are part of the system.

So, lets take a look and see how to read it.

/****************************************************************************
* Title                 :   PIC10F322 Temperature Module Example
* Filename              :   10F322_TempMod.c
* Author                :   Jamie Starling
* Origin Date           :   2022/09/21
* Version               :   1.0.0
* Compiler              :    
* Target                :    
* Copyright             :   Jamie Starling
* All Rights Reserved
*
* THIS SOFTWARE IS PROVIDED BY JAMIE STARLING "AS IS" AND ANY EXPRESSED
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL JAMIE STARLING OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************/

/******************************************************************************
* Includes
*******************************************************************************/
#include <xc.h>
#include <stdint.h>

/******************************************************************************
* Device Configuration
*******************************************************************************/
#pragma config FOSC = INTOSC  // Oscillator Selection 
#pragma config BOREN = ON    // Brown-out Reset
#pragma config WDTE = OFF    // Watchdog Timer
#pragma config PWRTE = ON    // Power-up Timer
#pragma config MCLRE = OFF   // MCLR Pin Function Select bit->MCLR pin function is digital input, MCLR internally tied to VDD
#pragma config CP = OFF      // Code Protection 
#pragma config LVP = OFF     // Low-Voltage Programming 
#pragma config LPBOR = ON    // Brown-out Reset Selection bits
#pragma config BORV = LO    // Brown-out Reset Voltage Selection
#pragma config WRT = OFF    // Flash Memory Self-Write Protection

//Used to calculate the delay time - Change depending on processor Speed
#define _XTAL_FREQ 16000000  //16Mhz



/******************************************************************************
* Function Prototypes
*******************************************************************************/
void DeviceSetup(void);
void Setup_EnableTempModule(void);
void Setup_ConfigADCForTempRead(void);
uint8_t ADC_Read(void);



/******************************************************************************
* Functions
*******************************************************************************/

/******************************************************************************
* Function : main()
*//** 
*  Description: MAIN Function 
*
*  
********************************************************************************/
void main(void)
{
    DeviceSetup();    
    
    uint8_t TempMod_Value = 0;
    
    while(1)
    {
        TempMod_Value = ADC_Read();
        __delay_ms(50);        
        
    }
}

/******************************************************************************
* Function : DeviceSetup()
*//** 
*  Description: 
     * Sets Operating Freq to 16Mhz
     * Calls The Temperature Module Setup Function
     * Calls The ADC COnfigurtion / Setup Function
*
*  
********************************************************************************/
void DeviceSetup(void){
    OSCCONbits.IRCF = 0b111;  //Set System Clock to 16Mhz
    Setup_EnableTempModule();
    Setup_ConfigADCForTempRead();
}

/******************************************************************************
* Function : Setup_EnableTempModule()
*//** 
*  Description: 
     * Enabled Temperature Module for High Range - The high range, selected by
     -  setting the TSRNG bit of the FVRCON register, provides a wider output
     -  voltage. This provides more resolution over the temperature range.
*
*  
********************************************************************************/

void Setup_EnableTempModule(void)
{
    FVRCONbits.TSRNG = 1; //Enable High Range
    FVRCONbits.TSEN = 1; //Enable TEMPERATURE INDICATOR MODULE   
}

/******************************************************************************
* Function : Setup_ConfigADCForTempRead()
*//** 
*  Description: 
     * Sets the ADC conversion clock 
     * Sets the ADC channel to Temperature Module
*
*  
********************************************************************************/

void Setup_ConfigADCForTempRead(void)
{
    //Set Analog conversion clock FOSC/32, since we are running 16Mhz,
    //we need to have a conversion time at or greater 1uS
    //FOSC/32 will give us 2uS
    ADCONbits.ADCS = 0b010;    
    //Select the Analog channel - to Temp Mod
    ADCONbits.CHS = 0b110;    
    //Turn on the ADC module
    ADCONbits.ADON = 1;       
}


/******************************************************************************
* Function : ADC_Read()
*//** 
*  Description: 
    *Starts the ADC read and waits until a conversion is complete before returning
    *Returns the ADC value - on the PIC10F322 it is 8bits. 
    **Note we already set the ADC channel to the Temp Mod in the ADC setup function
     -all we have to do is read it. 
*
*  
********************************************************************************/
uint8_t ADC_Read(void)
{

    ADCONbits.GO_nDONE = 1;  //Start the conversion
    
    while (ADCONbits.GO_nDONE == 1){
        NOP();
    }
    
    return ADRES;
}



Let’s talk!

I am always looking for oppunities to put my skills to work.
I am always looking to connect with like minded people.

Want to connect – drop me an email

jamie@jamiestarling.com