Hello Community.
The below is the example code for ADC in #S32k144#, In that "convertAdcChan(12);" this command is used to convert AD12 to potentiometer on EVB. i am trying to convert that to an external Temperature sesnor LM35 instead of onboard Potentiometer. so i am asuming i can use one ADC function pin such as PTC1 , PTC2 use as data pin for LM35 . But how can i interface that with this code. Like the potentiometer pin is PTC14. But i dont see anywhere it being called or defined in this code. But how did Potentiometer got activated.
My understanding is if i replace on board potentiometer with LM35 things should work.
Help required for : how can i interface my LM35 with 3 pins (VCC, DATA, GND) by leveraging this code.
Please let me know if i am wrong and help me out.
#include "S32K144.h" /* include peripheral declarations S32K144 */
#include "clocks_and_modes.h"
#include "ADC.h"
#define PTD15 15 /* RED LED*/
#define PTD16 16 /* GREEN LED*/
#define PTD0 0 /* BLUE LED */
void PORT_init (void) {
PCC->PCCn[PCC_PORTD_INDEX ]|=PCC_PCCn_CGC_MASK; /* Enable clock for PORTD */
PORTD->PCR[PTD0] = 0x00000100; /* Port D0: MUX = GPIO */
PORTD->PCR[PTD15] = 0x00000100; /* Port D15: MUX = GPIO */
PORTD->PCR[PTD16] = 0x00000100; /* Port D16: MUX = GPIO */
PTD->PDDR |= 1<<PTD0; /* Port D0: Data Direction= output */
PTD->PDDR |= 1<<PTD15; /* Port D15: Data Direction= output */
PTD->PDDR |= 1<<PTD16; /* Port D16: Data Direction= output */
}
void WDOG_disable (void){
WDOG->CNT=0xD928C520; /* Unlock watchdog */
WDOG->TOVAL=0x0000FFFF; /* Maximum timeout value */
WDOG->CS = 0x00002100; /* Disable watchdog */
}
int main(void)
{
uint32_t adcResultInMv=0;
WDOG_disable(); /* Disable WDOG*/
SOSC_init_8MHz(); /* Initialize system oscillator for 8 MHz xtal */
SPLL_init_160MHz(); /* Initialize SPLL to 160 MHz with 8 MHz SOSC */
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */
PORT_init(); /* Init port clocks and gpio outputs */
ADC_init(); /* Init ADC resolution 12 bit*/
for(;;) {
convertAdcChan(12); /* Convert Channel AD12 to pot on EVB */
while(adc_complete()==0){} /* Wait for conversion complete flag */
adcResultInMv = read_adc_chx(); /* Get channel's conversion results in mv */
if (adcResultInMv > 3750) { /* If result > 3.75V */
PTD->PSOR |= 1<<PTD0 | 1<<PTD16; /* turn off blue, green LEDs */
PTD->PCOR |= 1<<PTD15; /* turn on red LED */
}
else if (adcResultInMv > 2500) { /* If result > 2.5V */
PTD->PSOR |= 1<<PTD0 | 1<<PTD15; /* turn off blue, red LEDs */
PTD->PCOR |= 1<<PTD16; /* turn on green LED */
}
else if (adcResultInMv >1250) { /* If result > 1.25V */
PTD->PSOR |= 1<<PTD15 | 1<<PTD16; /* turn off red, green LEDs */
PTD->PCOR |= 1<<PTD0; /* turn on blue LED */
}
else {
PTD->PSOR |= 1<<PTD0 | 1<< PTD15 | 1<<PTD16; /* Turn off all LEDs */
}
convertAdcChan(29); /* Convert chan 29, Vrefsh */
while(adc_complete()==0){} /* Wait for conversion complete flag */
adcResultInMv = read_adc_chx(); /* Get channel's conversion results in mv */
}
}
Thanks