Need help for configure ADC in K10

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Need help for configure ADC in K10

1,560件の閲覧回数
sarath_gs
Contributor II

I am using K10 custom board , using codewarrior  10.4 RTOS MQX 4.0. may get an example code for configure ADC and get the value? 

0 件の賞賛
返信
3 返答(返信)

1,466件の閲覧回数
soledad
NXP Employee
NXP Employee

Hi,

You can use the MQX ADC example code, the ADC example shows usage of the ADC driver sampling analog values from two ADC channels.

You can find this example after install MQX in the following path:

C:\Freescale\Freescale_MQX_4_x\mqx\examples\adc

I hope this helps,

have a nice day!

Regards

Soledad

0 件の賞賛
返信

1,466件の閲覧回数
sarath_gs
Contributor II

Thank you . Please check the below code is good on not.

void ADC_Init(void)
{
/* SIM_SCGC6: ADC0=1 */
SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;

/* PORTB_PCR3: ISF=0,MUX=0 */
PORTB_PCR3 &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07)));
ADC0_CFG1 = ADC_CFG1_ADIV(0x01) |
ADC_CFG1_ADLSMP_MASK |
ADC_CFG1_MODE(0x03) |
ADC_CFG1_ADICLK(0x00);
/* ADC0_CFG2: ADACKEN=0,ADHSC=0,ADLSTS=2 */
ADC0_CFG2 = (uint32_t)((ADC0_CFG2 & (uint32_t)~(uint32_t)(
ADC_CFG2_ADACKEN_MASK |
ADC_CFG2_ADHSC_MASK |
ADC_CFG2_ADLSTS(0x01)
)) | (uint32_t)(
ADC_CFG2_ADLSTS(0x02)
));
/* ADC0_SC2: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ADACT=0,ADTRG=0,ACFE=0,ACFGT=0,ACREN=0,DMAEN=0,REFSEL=0 */
ADC0_SC2 = ADC_SC2_REFSEL(0x00);
/* ADC0_SC3: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,CAL=0,CALF=1,??=0,??=0,ADCO=0,AVGE=0,AVGS=0 */
ADC0_SC3 = (ADC_SC3_CALF_MASK | ADC_SC3_AVGS(0x00));
}
/******************************************************************************
.Purpose : For getting the ADC value from register
.Param : Pointer to buffer to get the value.
.Returns : NULL
.Note :
******************************************************************************/
void Get_ADCValue(uint_32 *iBuffer)
{
uint_32 iCount;
/*Getting the ADC value from register*/
ADC0_RA = ADC_R_D(0);

iCount = ADC0_RA;
*iBuffer = iCount;
}

0 件の賞賛
返信

1,466件の閲覧回数
soledad
NXP Employee
NXP Employee

Hi,

You are not using the MQX drivers, if you are using MQX I suggest you use the MQX drivers, please check the following document:

https://community.nxp.com/docs/DOC-333348 

Regarding the code, I cannot find a particular issue with the code, however it is necessary you test the application.

Regards

Soledad

0 件の賞賛
返信