I am trying to test C functionality on FRDM-K22F board. I am not getting results as expected.

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

I am trying to test C functionality on FRDM-K22F board. I am not getting results as expected.

1,195 Views
snehalpatil
Contributor II

I am not getting correct ADC count. I am trying to give input to ADC0_DP0 and ADC0_DM0 in differential mode.for this I kept settings as:

 

init_adc(void)

 

adc16_converter_config_t userConvConfig;


/* Un-gate port clock*/


//Enable Port E clock


/* Set current pin as analog pin:ADC.*/  //MK02FN128VFM10 pin settings.this needs to be uncommented.


/* PORT_HAL_SetMuxMode(PORTE, 16, kPortPinDisabled); //PTE16

 

// Execute the auto-calibration.


lowPowerEnable = false;

 

clkDividerMode = kAdc16ClkDividerOf4//check clock settings then decide


longSampleTimeEnable = false;

 

//userConvConfig.resolution = kAdc16ResolutionBitOfDiffModeAs13;


clkSrc = kAdc16ClkSrcOfBusClk;

 

asyncClkEnable = false;

 

highSpeedEnable = false;

 

longSampleCycleMode = kAdc16LongSampleCycleOf24;

 

hwTriggerEnable = false;

 

refVoltSrc = kAdc16RefVoltSrcOfVref;//kAdc16RefVoltSrcOfValt;//


continuousConvEnable = true;

 

resolution = kAdc16ResolutionBitOf16;//kAdc16ResolutionBitOf16;


FSL_FEATURE_ADC16_HAS_DMA

 

dmaEnable = false;


/* FSL_FEATURE_ADC16_HAS_DMA */


#if (FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16)

 

// userConvConfig.resolution = kAdc16ResolutionBitOfDiffModeAs16;//kAdc16ResolutionBitOf16;


#endif


bushing_voltage(void)

 

adc16_chn_config_t chnConfig;

 

uint16_t i=0;

 

// Configure the conversion channel


// differential and interrupt mode disable.


chnIdx     = kAdc16Chn0d;

 

#if FSL_FEATURE_ADC16_HAS_DIFF_MODE

 

diffConvEnable = true;

 

#endif


convCompletedIntEnable  = false;

 

// Software trigger the conversion.


// Wait for the conversion to be done.


kAdcChnConvCompleteFlag);

 

if (conv_done == true)

 

// Fetch the conversion value.


uint16_t)ADC16_DRV_GetConvValueRAW(ADC16_INSTANCE, ADC16_CHN_GROUP);

 

//   int_adc_val = (int16_t) ADC16_DRV_GetConvValueSigned(ADC16_INSTANCE, ADC16_CHN_GROUP);

}

 

I tried this giving DC power supply: 1.for Vref and 2nd DC power supply for differential channels;

Vref = 3 V

Differential input = 2.5V

But I am not getting correct results.

Please verify whether I am on correct path in above code (ADC settings and channel configuration) and connections given below

Connection pins:

VrefH=3V to pin 16 on J2 connector

VrefL is internally connected to gnd as FRDM-K22F schematic.

Pin 1 of J24 to ADC0_DP0 and 3 to ADC0_DM0

Connected DC power supply -ve terminal to GND pin 12 of J25.

Request to help as soon as possible.

Labels (1)
0 Kudos
6 Replies

808 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Snehal,

I have to say that the sampling time is totally different from the the conversion time. As you know that the sampling time is based on your application requirement, in general, if you want to sample an analog signal with equal interval, we suggest you use a hardware Timer to trigger ADC, in the case, the hardware timer can determine the interval. For the triggering source, pls refer to section 12.2.6 System Options Register 7 (SIM_SOPT7) in the Reference Manual of K22, for example PDB/PIT/FTM/CMP/RTC all can trigger ADC, the sampling time is controlled by the PDB/PIT/FTM/CMP/RTC.

The conversion time is determined by only ADC itself, for example, the ADC clock frequency, the ADC modes, as you said that section 32.4.4.5 "Sample time and total conversion time" focuses on the conversion time computation.

Note that the sampling time must be greater than the ADC conversion time. Software ADC triggering can not control the ADC interval accurately.

Hope it can help you.

BR

Xiangjun Rong

ADC1 trigger select

Selects the ADC1 trigger source when alternative triggers are functional in stop and VLPS modes.

0000 PDB external trigger pin input (PDB0_EXTRG)

0001 High speed comparator 0 output

0010 High speed comparator 1 output

0011 Reserved

0100 PIT trigger 0

0101 PIT trigger 1

0110 PIT trigger 2

0111 PIT trigger 3

1000 FTM0 trigger

1001 FTM1 trigger

1010 FTM2 trigger

1011 Reserved

1100 RTC alarm

1101 RTC seconds

1110 Low-power timer (LPTMR) trigger

1111 Reserved

0 Kudos

808 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Snehal,

How do you know that the sample is incorrect? For differential mode and 16 bits mode,assume that the digital raw sample is x.

if the MSB of the sample is 0, it is positive, the ADC analog differential voltage equals to (Vref/32767)*x

If the MSB of sample is 1, it is negative value, the ADC analog differential  voltage equals to -(Vref/32767)*(~x). "~x" means that you invert bits of x and add 1. for example assume the x=0xC7D2, "~x" will be 0x382D plus 1, in other words, it is 0x382E. the differential voltage will be -(3.0V/32767)*0x382D=-1.316V, assume the Vref is 3.0V.

If it does not solve your problem, pls attach your code and tell us the analog differential  voltage and the digital sample so that we can check it.

BR

Xiangjun Rong

0 Kudos

808 Views
snehalpatil
Contributor II

Hey thanks for replying.

ADC code is working.

Actually mentioned in query DC power supply for Vref and ADC input was used, so we tried calculating ADC input voltage from ADC count using same formula as you have mentioned (Vref/32767)*x. But for negative value we didn’t calculate the way you did (highlighted in yellow).

We were not getting correct results due to 2 reasons

1. Formula was wrong. We used this formula (Vref/32767)x and not -(Vref/32767)(~x).

2. Grounding of DC power supply and eval board were not proper.

I have some doubts:

1. If sample is negative should we always take 2’s complement of sample value while finding ADC input voltage? Is this done to get original sample value?

2. We are trying to use sample averaging functionality. In this we had doubt that once hardware averaging is enabled how should we read the averaged sample value? Should we check for ADACT bit in SC2 register before using function ADC16_DRV_GetConvValueSigned()?

Request to reply as early as possible.

Regards,

Snehal.

0 Kudos

808 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Snehal,

Q1.    If sample is negative should we always take 2’s complement of sample value while finding ADC input voltage? Is this done to get original sample value?

>>>>>>>I think if you declare a variable with the short int, it is okay. The short int is explained as the 16 bits positive/negative value.

for example

short int sample;

sample=ADC0_Rn;

Q2.    We are trying to use sample averaging functionality. In this we had doubt that once hardware averaging is enabled how should we read the averaged sample value? Should we check for ADACT bit in SC2 register before using function ADC16_DRV_GetConvValueSigned()?

>>>>>>>>I think it is okay to just poll the COCO, I copy the part here:

When the hardware average function is enabled, or SC3[AVGE]=1, COCO is set

upon completion of the selected number of conversions (determined by AVGS). COCO in SC1A is also set

at the completion of a calibration sequence. COCO is cleared when the respective SC1n register is written

or when the respective Rn register is read.

BR

Xiangjun rong

0 Kudos

808 Views
snehalpatil
Contributor II

Hi,

There is conversion time formula in K22F reference manual :

Conversion time= SFCAddder + AvgNum* (BCTLSTAdderHSCAdder)

We are using bus clock as 36Mhz.

ADC clock: 9 Mhz.

Hardware average enabled. sample collect value is 32

Long sample time enabled. Default value of extra 20 adc cycle is used.

Asynchronous clock not enabled. low power not enabled.

Could you plz tell me how to calculate sampling rate in FRDM-K22F?

Regards,

Snehal.

0 Kudos

808 Views
snehalpatil
Contributor II

Yes thank you ☺☺

Regards,

Snehal.

0 Kudos