I enable ADC1_DP1 & ADC2_DP0. I get the ADC key value by my code successfully. But I don't know how to enable multi-ADC pins, such as ADC1_DP1,ADC1_DP3,ADC1_SE18,ADC1_SE23. How do I get each single ADC pin value? Here is my code. Thanks a lot.
void api_ADC_Init(void)
{
SIM_SCGC3 |= SIM_SCGC3_ADC1_MASK;
ADC1_SC3 |= 0x80;//ADC1 self-calibration
while(ADC1_SC3&0x80)
_time_delay(100);
ADC1_CFG1 = ADC_CFG1_ADICLK(0) | ADC_CFG1_ADIV(1) | ADC_CFG1_MODE(2);
ADC1_SC2 = 0x00;
ADC1_SC1A = 0x41;//ADC1_DP1
SIM_SCGC6 |= SIM_SCGC6_ADC2_MASK;
ADC2_SC3 |= 0x80;//ADC2 self-calibration
while(ADC2_SC3&0x80)
_time_delay(100);
ADC2_CFG1 = ADC_CFG1_ADICLK(0) | ADC_CFG1_ADIV(1) | ADC_CFG1_MODE(2);
ADC2_SC2 = 0x00;
ADC2_SC1A = 0x40;//ADC2_DP0
}
SystemStatus api_GetADCValue(api_ADCChannel_t B_ADCChennel, WORD *Wp_ADCValue)
{
SelectADCConvertChannel((api_ADCChannel_t) B_ADCChennel);
cl_ForceDelay_us(15);
if ((B_ADCChennel == api_ADC_CH1)&&(ADC1_SC1A&ADC_SC1_COCO_MASK ))
{
*Wp_ADCValue = ADC1_RA;
ADC1_SC1A = 0x41;//initiate a new conversion
return OK;
}
if ((B_ADCChennel == api_ADC_CH2)&&(ADC2_SC1A&ADC_SC2_COCO_MASK ))
{
*Wp_ADCValue = ADC2_RA;
ADC2_SC1A = 0x40;//initiate a new conversion
return OK;
}
cl_ForceDelay_us(1);
return NO_DATA;
}
It need to modify ADC Status and Control Registers 1 (ADCx_SC1n) [ADCH] bits to select the input ADC channel.
There is another way, which using DMA to help ADC do a scan work (multi channels can be sampled and conversion), more detailed info, please check below link:
http://cache.freescale.com/files/32bit/doc/app_note/AN4590.pdf
Wish it help.
best regards,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Generally, it trigger the ADC conversion, then check the status, read the ADC register when it finish conversion.
I use processor expert to generate ADC code, it seems not make sense.
The PE setting for ADC are:
Discontinuous Mode ===>yes
Static sample groups ===>Enabled
After generating code, it only have three function:
Init - LDD_TDeviceData* ADC_InputPS_Init(LDD_TUserData *UserDataPtr);
CreateSampleGroup - LDD_TError ADC_InputPS_CreateSampleGroup(LDD_TDeviceData *DeviceDataPtr,...
GetMeasuredValues - LDD_TError ADC_InputPS_GetMeasuredValues(LDD_TDeviceData *DeviceDataPtr,...
===========================================================================================
I can't find how to use CreateSampleGroup() to trigger and check status, is there any example for how to use the ADC?
Hi Sam,
Please let us know which Kinetis product you are using?
Wish it help.
best regards,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Sam,
You can download K60 example code from below link:
KINETIS512_V2_SC : Kinetis 100MHz Rev 2 Example Projects.
It includes ADC example code.
Wish it help.
best regards,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------