µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: Phil on May 15, 2018, 02:39:16 AM
-
Mark,
I am trying to do a simple ADC port read and been trying to follow code from the forum to no avail.
static void fnInitADC(void)
{
ADC_SETUP adc_setup; // interrupt configuration parameters
adc_setup.int_type = ADC_INTERRUPT; // identifier when configuring
adc_setup.int_adc_controller = 0; // ADC controller
adc_setup.int_adc_bit = ADC_SE15_SINGLE; // pressure sensor location
adc_setup.int_adc_mode = (ADC_CONFIGURE_ADC | ADC_CONFIGURE_CHANNEL | ADC_SINGLE_ENDED_INPUT | ADC_LOOP_MODE ); // single ended configuration in loop mode
adc_setup.int_adc_int_type = 0; // no interrupt
fnConfigureInterrupt((void *)&adc_setup); // configure and start operation
}
static void fnReadPressure(void)
{
int iADC_delay = -1;
ADC_SETUP adc_setup; // interrupt configuration parameters
ADC_RESULTS results;
adc_setup.int_type = ADC_INTERRUPT; // identifier when configuring
adc_setup.int_adc_controller = 0; // ADC controller
adc_setup.int_adc_bit = ADC_SE15_SINGLE; // pressure sensor location
adc_setup.int_adc_result = &results;
adc_setup.int_adc_mode = (ADC_READ_ONLY | ADC_GET_RESULT);
do {
fnConfigureInterrupt((void *)&adc_setup); // get result
iADC_delay++;
} while (results.ucADC_status[ADC_SE15_SINGLE] == ADC_RESULT_NOT_READY); // 'poll until the result is ready
if (results.ucADC_status[ADC_SE15_SINGLE] != ADC_RESULT_NOT_READY) {
fnDebugMsg("ADC value = ");
fnDebugHex(results.sADC_value[ADC_SE15_SINGLE], 2);
fnDebugMsg("\r\n");
}
else {
fnDebugMsg("ADC not ready\r\n");
}
}
fnInitADC() gets run at initialization.
fnReadPressure() gets run periodically from a task every 3 seconds.
MCU = MK64FX512VLL12
Pin 71 = PTC1 (ADC0_SE15) (voltage at the pin varies from 0.5 to 2.5 vdc)
I am trying to read "ad hoc". Is a interrupt handler actually required/recommended?
-
Result is always: ADC value = 0000
-
Phil
Use the code in the file ADC_TImers.h as reference. The code that you have used is not compatible with the Kinetis parts [it looks like the Coldfire interface] (see the setup conditional on _KINETIS for the method).
An interrupt is not necessary. If you start a conversion and read it after a time delay greater than the conversion time its result can be read since it will be ready.
A method to read without interrupt (polling until ready) was added to this file on 9.2.2018 (if you have access to the developer's version, noting that the driver was also updated slightly to allow it to work correctly). See the define TEST_POLL_ADC for the example.
Regards
Mark
See also http://www.utasker.com/docs/uTasker/uTaskerADC.pdf for standard reference code with some explanations too (it should match the examples and discusses Kinetis interface)