News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Reading the PIC18F27Q83 Device Information Area

Started by kcsl, Jul 15, 2025, 12:01 PM

Previous topic - Next topic

kcsl

I want to use the 18F27Q83's internal temperature sensor, but to do the conversion you need to read a couple of values out of the Device Information Area. This area seems to be mapped into address space $2C0000 to $2C003F and Ptr16 says the address is out of range - I knew it wouldn't be that easy.

Does anybody have a bit of code that can read values out of this area please ?

Regards,
Joe
There's no room for optimism in software or hardware engineering.

RGV250

Hi,
Looking at the datasheet you select the ADC channel by ADPCH (page 933) and then read as an analog input. I think you need %xx111100 for the temperature indicator.

Regards,
Bob

kcsl

Quote from: RGV250 on Jul 15, 2025, 01:23 PMHi,
Looking at the datasheet you select the ADC channel by ADPCH (page 933) and then read as an analog input. I think you need %xx111100 for the temperature indicator.

Regards,
Bob

Hi Bob,
Yes, I can read the ADC no problem, but to turn that ADC value into a temperature you need to read some additional factory programmed trim values from the DIA.
Section 42.2 gives the calculation.

Regards,
Joe

There's no room for optimism in software or hardware engineering.

RGV250

Hi Joe,
Google this, "reading DIA registers 18F27Q83"
It goes on to say they are not directly accessible and need to be read as EEPROM. More than my brain cell can cope with at the moment.

Bob

RGV250

Found this.
Quote// Assuming a C-like syntax and a suitable EEPROM library

// Define DIA addresses (refer to datasheet for specific addresses)
#define DIA_TEMP_INDICATOR  0x000 // Example address
#define DIA_UNIQUE_ID       0x010 // Example address

// Function to read from DIA
unsigned char read_DIA(unsigned int address) {
  // Set up EEPROM for read
  EECON1bits.EEPGD = 0; // Access data EEPROM
  EECON1bits.CFGS = 0;  // Access data EEPROM
  EECON1bits.RD = 0;    // Clear the read bit

  FSR0 = address;      // Load the DIA address into FSR0
  EECON1bits.RD = 1;     // Initiate the read operation
  while(EECON1bits.RD == 1); // Wait for read to complete
  return EEDATA;       // Return the read data
}

// Example usage:
unsigned char temperature = read_DIA(DIA_TEMP_INDICATOR);
unsigned char unique_id[8];
for(int i=0; i<8; i++){
    unique_id = read_DIA(DIA_UNIQUE_ID + i);
}

Bob

kcsl

Quote from: RGV250 on Jul 15, 2025, 01:55 PMFound this.
Quote// Assuming a C-like syntax and a suitable EEPROM library

// Define DIA addresses (refer to datasheet for specific addresses)
#define DIA_TEMP_INDICATOR  0x000 // Example address
#define DIA_UNIQUE_ID       0x010 // Example address

// Function to read from DIA
unsigned char read_DIA(unsigned int address) {
  // Set up EEPROM for read
  EECON1bits.EEPGD = 0; // Access data EEPROM
  EECON1bits.CFGS = 0;  // Access data EEPROM
  EECON1bits.RD = 0;    // Clear the read bit

  FSR0 = address;      // Load the DIA address into FSR0
  EECON1bits.RD = 1;     // Initiate the read operation
  while(EECON1bits.RD == 1); // Wait for read to complete
  return EEDATA;       // Return the read data
}

// Example usage:
unsigned char temperature = read_DIA(DIA_TEMP_INDICATOR);
unsigned char unique_id[8];
for(int i=0; i<8; i++){
    unique_id = read_DIA(DIA_UNIQUE_ID + i);
}

Bob

When I searched Google, I got this:

The Device Information Area (DIA) of the PIC18F27Q83 microcontroller stores factory-calibrated data, fixed voltage reference measurements, and a unique identifier. To access this information, you'll need to use the DIA addresses specified in the device's datasheet. The DIA is not directly readable via normal memory access methods; it requires specific instructions or functions provided by the Microchip development tools.

Regards,
Joe
There's no room for optimism in software or hardware engineering.

RGV250

Hi Joe,
Did you use the phrase I put between the quotes for your search, I got different results until I changed it to that.

Bob

top204

#7
If the DIA part of Flash memory, is just a piece of flash at a higher address, then the cPtr24 command should read it, because the address' are 24-bits in size. For example:

$define cTSLR1_Address $2C0024           ' Gain
$define cTSLR2_Address $2C0026           ' Temperature indicator ADC reading at 90°C (low range setting)
$define cTSLR3_Address $2C0028           ' Offset (low range setting)
'
' Create global variables
'
    Dim ADC_wGain   As Word
    Dim ADC_w90Deg  As Word
    Dim ADC_wOffset As Word    

'-----------------------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    ADC_wGain   = cPtr24(cTSLR1_Address) 
    ADC_w90Deg  = cPtr24(cTSLR2_Address)
    ADC_wOffset = cPtr24(cTSLR3_Address)

But is is unknown what orientation they are in, within flash. So the high and low bytes may need to be re-arranged.