ADC Code output Test on real time?

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

ADC Code output Test on real time?

800 Views
Turtledove
Contributor I

I am running example s32k148 on my s32 ide for arm. Please tell me how to check its output in real time expression and where to configure pins. I am new here in coding and on board.  Please guide me by mentioning steps.

ADC.c

/*
 * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
 * Copyright (c) 2016 - 2018, NXP.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY NXP "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 NXP 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.
 */
 
#include "ADC.h"
 
void ADC_init(void)
{
/*!
* ADC0 Clocking:
* ===================================================
*/
  PCC->PCCn[PCC_ADC0_INDEX] &=~ PCC_PCCn_CGC_MASK;  /* Disable clock to change PCS */
  PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_PCS(1);     /* PCS=1: Select SOSCDIV2 */
  PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_CGC_MASK;   /* Enable bus clock in ADC */
 
/*!
* ADC0 Initialization:
* ===================================================
*/
  ADC0->SC1[0] |= ADC_SC1_ADCH_MASK; /* ADCH=1F: Module is disabled for conversions */
                                    /* AIEN=0: Interrupts are disabled */
  ADC0->CFG1 |= ADC_CFG1_ADIV_MASK
     |ADC_CFG1_MODE(1); /* ADICLK=0: Input clk=ALTCLK1=SOSCDIV2 */
                                  /* ADIV=0: Prescaler=1 */
                                  /* MODE=1: 12-bit conversion */
 
  ADC0->CFG2 = ADC_CFG2_SMPLTS(12); /* SMPLTS=12(default): sample time is 13 ADC clks */
  ADC0->SC2 = 0x00000000;          /* ADTRG=0: SW trigger */
                                  /* ACFE,ACFGT,ACREN=0: Compare func disabled */
                                  /* DMAEN=0: DMA disabled */
                                    /* REFSEL=0: Voltage reference pins= VREFH, VREEFL */
  ADC0->SC3 = 0x00000000;        /* CAL=0: Do not start calibration sequence */
                                    /* ADCO=0: One conversion performed */
                                    /* AVGE,AVGS=0: HW average function disabled */
}
void ADC_init_HWTrigger(char Channel)  {
 
  PCC->PCCn[PCC_ADC0_INDEX] &=~ PCC_PCCn_CGC_MASK;  /* Disable clock to change PCS */
  PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_PCS(1);     /* PCS=1: Select SOSCDIV2 */
  PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_CGC_MASK;   /* Enable bus clock in ADC */
 
  ADC0->SC1[0] |= ADC_SC1_ADCH_MASK
              |ADC_SC1_AIEN_MASK;         /* ADCH=1F: Module is disabled for conversions*/
                                  /* AIEN=0: Interrupts are disabled */
  ADC0->CFG1 |= ADC_CFG1_ADIV_MASK
            |ADC_CFG1_MODE(1);/* ADICLK=0: Input clk=ALTCLK1=SOSCDIV2 */
                                  /* ADIV=0: Prescaler=1 */
                                  /* MODE=1: 12-bit conversion */
  ADC0->CFG2 = 0x00000000C;       /* SMPLTS=12(default): sample time is 13 ADC clks */
  ADC0->SC2 = ADC_SC2_ADTRG_MASK;         /* ADTRG=1: HW trigger */
                                  /* ACFE,ACFGT,ACREN=0: Compare func disabled */
                                  /* DMAEN=0: DMA disabled */
                                  /* REFSEL=0: Voltage reference pins= VREFH, VREEFL */
  ADC0->SC1[0] = ADC_SC1_ADCH(Channel)
      |ADC_SC1_AIEN_MASK;         /* ADCH=1F: Module is disabled for conversions*/
                                    /* AIEN=0: Interrupts are disabled */
  ADC0->SC3 = 0x00000000;         /* CAL=0: Do not start calibration sequence */
                                  /* ADCO=0: One conversion performed */
                                  /* AVGE,AVGS=0: HW average function disabled */
}
 
void convertAdcChan(uint16_t adcChan)
{
/*!
* For SW trigger mode, SC1[0] is used
* ===================================================
*/
  ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;       /* Clear prior ADCH bits */
  ADC0->SC1[0] = ADC_SC1_ADCH(adcChan);   /* Initiate Conversion */
}
 
uint8_t adc_complete(void)
{
  return ((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT); /* Wait for completion */
}
 
uint32_t read_adc_chx(void)
{
  uint16_t adc_result=0;
  adc_result=ADC0->R[0];      /* For SW trigger mode, R[0] is used */
  return  (uint32_t) ((5000*adc_result)/0xFFF); /* Convert result to mv for 0-5V range */
}
 
 
ADC.h
 

#ifndef ADC_H_
#define ADC_H_
#include "device_registers.h" /* include peripheral declarations S32K144 */

void convertAdcChan(uint16_t);
void ADC_init(void);
void ADC_init_HWTrigger(char Channel);
uint8_t adc_complete(void);
uint32_t read_adc_chx(void);

#endif /* ADC_H_ */

0 Kudos
Reply
1 Reply

727 Views
_Leo_
NXP TechSupport
NXP TechSupport

Thank you for your interest in our products and for contributing to our community.

Please refer to the following knowledge base post:

S32M24x/S32K1 – FTM/TRGMUX/PDB/ADC – [RTD300] -> https://community.nxp.com/t5/S32M-Knowledge-Base/S32M24x-S32K1-FTM-TRGMUX-PDB-ADC-RTD300/ta-p/222903...

We hope this resolves your issue.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2205050%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EADC%20Code%20output%20Test%20on%20real%20time%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2205050%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20running%20example%20s32k148%20on%20my%20s32%20ide%20for%20arm.%20Please%20tell%20me%20how%20to%20check%20its%20output%20in%20real%20time%20expression%20and%20where%20to%20configure%20pins.%20I%20am%20new%20here%20in%20coding%20and%20on%20board.%26nbsp%3B%20Please%20guide%20me%20by%20mentioning%20steps.%3C%2FP%3E%3CP%3E%3CSTRONG%3EADC.c%3C%2FSTRONG%3E%3C%2FP%3E%3CDIV%3E%2F*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20Copyright%20(c)%202014%20-%202016%2C%20Freescale%20Semiconductor%2C%20Inc.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20Copyright%20(c)%202016%20-%202018%2C%20NXP.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20All%20rights%20reserved.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20Redistribution%20and%20use%20in%20source%20and%20binary%20forms%2C%20with%20or%20without%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20modification%2C%20are%20permitted%20provided%20that%20the%20following%20conditions%20are%20met%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%201.%20Redistributions%20of%20source%20code%20must%20retain%20the%20above%20copyright%20notice%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%26nbsp%3B%20%26nbsp%3B%20this%20list%20of%20conditions%20and%20the%20following%20disclaimer.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%202.%20Redistributions%20in%20binary%20form%20must%20reproduce%20the%20above%20copyright%20notice%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%26nbsp%3B%20%26nbsp%3B%20this%20list%20of%20conditions%20and%20the%20following%20disclaimer%20in%20the%20documentation%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%26nbsp%3B%20%26nbsp%3B%20and%2For%20other%20materials%20provided%20with%20the%20distribution.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%203.%20Neither%20the%20name%20of%20the%20copyright%20holder%20nor%20the%20names%20of%20its%20contributors%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%26nbsp%3B%20%26nbsp%3B%20may%20be%20used%20to%20endorse%20or%20promote%20products%20derived%20from%20this%20software%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%26nbsp%3B%20%26nbsp%3B%20without%20specific%20prior%20written%20permission.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20THIS%20SOFTWARE%20IS%20PROVIDED%20BY%20NXP%20%22AS%20IS%22%20AND%20ANY%20EXPRESSED%20OR%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20IMPLIED%20WARRANTIES%2C%20INCLUDING%2C%20BUT%20NOT%20LIMITED%20TO%2C%20THE%20IMPLIED%20WARRANTIES%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20OF%20MERCHANTABILITY%20AND%20FITNESS%20FOR%20A%20PARTICULAR%20PURPOSE%20ARE%20DISCLAIMED.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20IN%20NO%20EVENT%20SHALL%20NXP%20OR%20ITS%20CONTRIBUTORS%20BE%20LIABLE%20FOR%20ANY%20DIRECT%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20INDIRECT%2C%20INCIDENTAL%2C%20SPECIAL%2C%20EXEMPLARY%2C%20OR%20CONSEQUENTIAL%20DAMAGES%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20(INCLUDING%2C%20BUT%20NOT%20LIMITED%20TO%2C%20PROCUREMENT%20OF%20SUBSTITUTE%20GOODS%20OR%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20SERVICES%3B%20LOSS%20OF%20USE%2C%20DATA%2C%20OR%20PROFITS%3B%20OR%20BUSINESS%20INTERRUPTION)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20HOWEVER%20CAUSED%20AND%20ON%20ANY%20THEORY%20OF%20LIABILITY%2C%20WHETHER%20IN%20CONTRACT%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20STRICT%20LIABILITY%2C%20OR%20TORT%20(INCLUDING%20NEGLIGENCE%20OR%20OTHERWISE)%20ARISING%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20IN%20ANY%20WAY%20OUT%20OF%20THE%20USE%20OF%20THIS%20SOFTWARE%2C%20EVEN%20IF%20ADVISED%20OF%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%20THE%20POSSIBILITY%20OF%20SUCH%20DAMAGE.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%23include%20%22ADC.h%22%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Evoid%20ADC_init(void)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20ADC0%20Clocking%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%26amp%3B%3D~%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%2F*%20Disable%20clock%20to%20change%20PCS%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%7C%3D%20PCC_PCCn_PCS(1)%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20PCS%3D1%3A%20Select%20SOSCDIV2%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%7C%3D%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%26nbsp%3B%2F*%20Enable%20bus%20clock%20in%20ADC%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20ADC0%20Initialization%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC1%5B0%5D%20%7C%3D%20ADC_SC1_ADCH_MASK%3B%20%2F*%20ADCH%3D1F%3A%20Module%20is%20disabled%20for%20conversions%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20AIEN%3D0%3A%20Interrupts%20are%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BCFG1%20%7C%3D%20ADC_CFG1_ADIV_MASK%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7CADC_CFG1_MODE(1)%3B%20%2F*%20ADICLK%3D0%3A%20Input%20clk%3DALTCLK1%3DSOSCDIV2%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ADIV%3D0%3A%20Prescaler%3D1%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20MODE%3D1%3A%2012-bit%20conversion%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BCFG2%20%3D%20ADC_CFG2_SMPLTS(12)%3B%20%2F*%20SMPLTS%3D12(default)%3A%20sample%20time%20is%2013%20ADC%20clks%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC2%20%3D%200x00000000%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ADTRG%3D0%3A%20SW%20trigger%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ACFE%2CACFGT%2CACREN%3D0%3A%20Compare%20func%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20DMAEN%3D0%3A%20DMA%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20REFSEL%3D0%3A%20Voltage%20reference%20pins%3D%20VREFH%2C%20VREEFL%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC3%20%3D%200x00000000%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20CAL%3D0%3A%20Do%20not%20start%20calibration%20sequence%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ADCO%3D0%3A%20One%20conversion%20performed%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20AVGE%2CAVGS%3D0%3A%20HW%20average%20function%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3Evoid%20ADC_init_HWTrigger(char%20Channel)%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%26amp%3B%3D~%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%2F*%20Disable%20clock%20to%20change%20PCS%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%7C%3D%20PCC_PCCn_PCS(1)%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20PCS%3D1%3A%20Select%20SOSCDIV2%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20PCC-%26gt%3BPCCn%5BPCC_ADC0_INDEX%5D%20%7C%3D%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%26nbsp%3B%2F*%20Enable%20bus%20clock%20in%20ADC%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC1%5B0%5D%20%7C%3D%20ADC_SC1_ADCH_MASK%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7CADC_SC1_AIEN_MASK%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20ADCH%3D1F%3A%20Module%20is%20disabled%20for%20conversions*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20AIEN%3D0%3A%20Interrupts%20are%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BCFG1%20%7C%3D%20ADC_CFG1_ADIV_MASK%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7CADC_CFG1_MODE(1)%3B%2F*%20ADICLK%3D0%3A%20Input%20clk%3DALTCLK1%3DSOSCDIV2%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ADIV%3D0%3A%20Prescaler%3D1%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20MODE%3D1%3A%2012-bit%20conversion%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BCFG2%20%3D%200x00000000C%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20SMPLTS%3D12(default)%3A%20sample%20time%20is%2013%20ADC%20clks%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC2%20%3D%20ADC_SC2_ADTRG_MASK%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20ADTRG%3D1%3A%20HW%20trigger%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ACFE%2CACFGT%2CACREN%3D0%3A%20Compare%20func%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20DMAEN%3D0%3A%20DMA%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20REFSEL%3D0%3A%20Voltage%20reference%20pins%3D%20VREFH%2C%20VREEFL%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC1%5B0%5D%20%3D%20ADC_SC1_ADCH(Channel)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7CADC_SC1_AIEN_MASK%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20ADCH%3D1F%3A%20Module%20is%20disabled%20for%20conversions*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20AIEN%3D0%3A%20Interrupts%20are%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC3%20%3D%200x00000000%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20CAL%3D0%3A%20Do%20not%20start%20calibration%20sequence%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20ADCO%3D0%3A%20One%20conversion%20performed%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20AVGE%2CAVGS%3D0%3A%20HW%20average%20function%20disabled%20*%2F%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Evoid%20convertAdcChan(uint16_t%20adcChan)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20For%20SW%20trigger%20mode%2C%20SC1%5B0%5D%20is%20used%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC1%5B0%5D%26amp%3B%3D~ADC_SC1_ADCH_MASK%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Clear%20prior%20ADCH%20bits%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20ADC0-%26gt%3BSC1%5B0%5D%20%3D%20ADC_SC1_ADCH(adcChan)%3B%26nbsp%3B%20%26nbsp%3B%2F*%20Initiate%20Conversion%20*%2F%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Euint8_t%20adc_complete(void)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20return%20((ADC0-%26gt%3BSC1%5B0%5D%20%26amp%3B%20ADC_SC1_COCO_MASK)%26gt%3B%26gt%3BADC_SC1_COCO_SHIFT)%3B%20%2F*%20Wait%20for%20completion%20*%2F%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Euint32_t%20read_adc_chx(void)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20uint16_t%20adc_result%3D0%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20adc_result%3DADC0-%26gt%3BR%5B0%5D%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20For%20SW%20trigger%20mode%2C%20R%5B0%5D%20is%20used%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20return%26nbsp%3B%20(uint32_t)%20((5000*adc_result)%2F0xFFF)%3B%20%2F*%20Convert%20result%20to%20mv%20for%200-5V%20range%20*%2F%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EADC.h%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CP%3E%23ifndef%20ADC_H_%3CBR%20%2F%3E%23define%20ADC_H_%3CBR%20%2F%3E%23include%20%22device_registers.h%22%20%2F*%20include%20peripheral%20declarations%20S32K144%20*%2F%3C%2FP%3E%3CP%3Evoid%20convertAdcChan(uint16_t)%3B%3CBR%20%2F%3Evoid%20ADC_init(void)%3B%3CBR%20%2F%3Evoid%20ADC_init_HWTrigger(char%20Channel)%3B%3CBR%20%2F%3Euint8_t%20adc_complete(void)%3B%3CBR%20%2F%3Euint32_t%20read_adc_chx(void)%3B%3C%2FP%3E%3CP%3E%23endif%20%2F*%20ADC_H_%20*%2F%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E