ADC Hardware Trigger

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,279件の閲覧回数
akhilranga
Contributor IV

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

0 件の賞賛
1 解決策
1,268件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

not sure what you meant. If sensor has 3 wires (VCC, DATA, GND) connect DATA to PTC1 and VCC/GND to VDD/GND, see EVB schematic, VDD/GND and PTC1 are on J5 header.

BR, Petr

元の投稿で解決策を見る

0 件の賞賛
6 返答(返信)
1,276件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if you connect DATA pin of sensor to e.g PTC1 then you need to convert external channel 9 on the ADC

PetrS_0-1660653724123.png

So within this code it should be enough to use

convertAdcChan(9); /* Convert Channel AD9, PTC1 on EVB */

BR, Petr

0 件の賞賛
1,271件の閲覧回数
akhilranga
Contributor IV

Hi @PetrS 

Thanks for the help i got it. I was missing that link between ADC channel and port pins. Thanks again for the help.

Now i just wanted to understand one last thing. I am trying to input 5v input to the sesnor. So, how can i do that. I noticed VDD pins but plese let me know how i can initiate that with this code. I am assuming inorder to access the VDD pins as 5v Power supply, i need to enable clocks and initiate the pins. 

P.S : i just statrted exploring this S32k144 . Excuse my naivety. 

Thanks for the help 

0 件の賞賛
1,269件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

not sure what you meant. If sensor has 3 wires (VCC, DATA, GND) connect DATA to PTC1 and VCC/GND to VDD/GND, see EVB schematic, VDD/GND and PTC1 are on J5 header.

BR, Petr

0 件の賞賛
1,264件の閲覧回数
akhilranga
Contributor IV

Hi @PetrS 

Yes. I am planning to do the same . But my question was related to VDD pin. Do i need to interface it the same way i will interface the PTC1

Like, do i need to enable clock or something.

0 件の賞賛
1,230件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

VDD is just power pin, no setting is for that, you need to connect external voltage to VDD to power the MCU.

BR, Petr

0 件の賞賛
1,224件の閲覧回数
akhilranga
Contributor IV

Hi @PetrS .

Thanks for the asssist. Got that thing figured out. 

0 件の賞賛