LPC546xx Internal temperature sensor to ADC channel0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC546xx Internal temperature sensor to ADC channel0

Jump to solution
1,782 Views
NagamalleswaraRao
Contributor II

I tried to configure the internal temperature sensor in LPC54608 by referring to the chapters in user manual UM10912 in ADC controller and ADC internal temperature sensor. Here I have used 180MHz system clock and reduced to 60MHz using clock division in ADC CTRL. And used Synchronous mode. 

And referred errata sheet also to configure ADC where I kept all channels in digital mode first and then I made the required channel 0 as analog . I powered ADC after all configuration of registers in ADC as it is mentioned in Errata sheet. Still the temperature sensor not given any response. Used SEQA_CTRL register to access sequence-A. Steps followed to read temperature sensor reading from chapter 45.

Can anyone please let me know how do I configure temperature sensor properly and get the conversion through ADC and read digital result.?

0 Kudos
1 Solution
1,742 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to table 57 in data sheet of LPC546xx, which can be downloaded from the link:

https://www.nxp.com.cn/docs/en/data-sheet/LPC546XX.pdf

assume the voltage is x, y is the temperature. The formula is y=k*x+b

the k is -2.04mV/C, b 584mV at 0 degree..

Hope it can help you

BR

XiangJun Rong

 

xiangjun_rong_0-1663204418538.png

 

View solution in original post

5 Replies
1,774 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As you know that the temperature sensor is connected to channel 0 of ADC for LPC546xx, so you have to select ADC channel 0. Secondly, there is an Input Select register in ADC converter, you have to set the reg as 3 so that you can select temperature sensor. For detailed inf, pls refer to section 44.6.2 Input Select register in UM10912.pdf

I have used the lpc_adc_interrupt as an example and changed it as following so that you can sample temperature sensor, pls have a try.

Hope it can help you

BR

XiangJun Rong

xiangjun_rong_0-1663055440756.png

 

 

 

 

 

0 Kudos
1,764 Views
NagamalleswaraRao
Contributor II

I have followed all the steps as you mentioned. Still didn't get any response. 

Here I'm attaching my code so that you may find any mistake.

//Clock has taken from PLL settings(driver already written) and my CPU clock is 180MHz.

In errata sheet it is mentioned that keep all ports in digital mode and then asked to use analog when needed.

Function to keep digital mode and disable clock for ADC:

void disable_all_adc()
{

IOCON->PIO[0][10]|=(1<<8);
IOCON->PIO[0][11]|=(1<<8);
IOCON->PIO[0][12]|=(1<<8);
IOCON->PIO[0][15]|=(1<<8);
IOCON->PIO[0][16]|=(1<<8);
IOCON->PIO[0][31]|=(1<<8);
IOCON->PIO[1][0]|=(1<<8);
IOCON->PIO[2][0]|=(1<<8);
IOCON->PIO[2][1]|=(1<<8);
IOCON->PIO[3][21]|=(1<<8);
IOCON->PIO[3][22]|=(1<<8);
IOCON->PIO[0][23]|=(1<<8);
SYSCON->PDRUNCFG[0]|=(1<<9)|(1<<10)|(1<<19)|(1<<23);
}

Function to initiate ADC:

void adc_init(void)
{
SYSCON->AHBCLKCTRL[0]|=(1<<13);                                         //IOCON power up
disable_all_adc();                                                                            //disable function calling

SYSCON->PDRUNCFG[0]&=~(1<<9)|(1<<10)|(1<<19)|(1<<23);     //powering up ADC and related pins
SYSCON->PDRUNCFG[1]&=~(1<<3);                                              
delay(20000);                                                                                   //To generate atleast 20uS delay
SYSCON->AHBCLKCTRL[0]|=(1<<27);                                        //Enabling clock
SYSCON->PRESETCTRL[0]&=~(1<<27);                                    //Clearing reset
ADC0->SEQ_CTRL[0]|=(1<<31);                                                 //Enabling sequence A


                 
ADC0->CTRL|=0x02;                                                      //Clock division by 3: 60MHz returns
ADC0->CTRL&=~(1<<8);                                              //Synchronous mode selected.
ADC0->CTRL|=(1<<9)|(1<<10);                                    //12 bit resolution
ADC0->CTRL|=(1<<12)|(1<<13)|(1<<14);                     //TSAMP 9.5ADC clock cycles



ADC0->SEQ_CTRL[0]&=~(1<<31);                               //Disabling sequence
ADC0->SEQ_CTRL[0]|=(1<<0)|(1<<31);                      //Channel 0 selection and enabling ADC-A seq
ADC0->SEQ_CTRL[0]&=~(1<<27);                              //Disabling burst mode

SYSCON->PDRUNCFG[0]&=~(1<<6);                       //powering up internal temperature senor
ADC0->INSEL=0x03;                                                 // Selecting temperature sensor to ADC0



IOCON->PIO[0][11]&=~((1<<8)|(1<<3)|(1<<2)|(1<<1)|(1<<0)); //IOCON Inactive mode,inverting disabled
IOCON->PIO[0][11]&=~((1<<5)|(1<<4));                                    //Analog mode
}

That's how initialization done.

In main function :

int main()
{
clock_init();                   //Driver code.(It's working fine)

adc_init();                     //Calling adc initialization

while(1)
{

ADC0->SEQ_CTRL[0] |= (1<<26);                                        // start conversion
if(scan<=samples)                                                                  //Scan and samples(200) are variables
{
while(((ADC0->SEQ_GDAT[0])&(1U<<31))!=1);

result+= (ADC0->DAT[0]>>4)&0xFFF;
}
scan++;

if(scan==samples)
{
out = (float) ((result *3.3)/4095);
scan=1;
}

}
}

Tags (1)
0 Kudos
1,754 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Can you download SDK package and use the SDK adc example to test the temperature sensor? If the SDK example is okay, then refer to it to develop code based on register instead of driver.

https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-s...

Hope it can help you

BR

XiangJun Rong

 

Tags (1)
0 Kudos
1,748 Views
NagamalleswaraRao
Contributor II

Hi,

I got the reading. Can you give me the formula for calculating the temperature with the resultant converted hexadecimal value for LPC54608, 12 bit ADC.

0 Kudos
1,743 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to table 57 in data sheet of LPC546xx, which can be downloaded from the link:

https://www.nxp.com.cn/docs/en/data-sheet/LPC546XX.pdf

assume the voltage is x, y is the temperature. The formula is y=k*x+b

the k is -2.04mV/C, b 584mV at 0 degree..

Hope it can help you

BR

XiangJun Rong

 

xiangjun_rong_0-1663204418538.png