hi mark,
thanks for your prompt reply. i have tried many times on ADC settings, unfortunately i can't make it work. my objective is very simple, to create 4 channels of ADC to AN0, AN1, AN2, AN3. my reference voltage is 2.5V.
below is all my codes for a single channel, in most simplified form. all these codes are modified based on TEST_ADC in ADC_Timers.h only, without creating any new task, which i think easier to make it work. i followed the instructions given referring to your posts,
in my fnConfigureADC()
static void fnConfigureADC(void) //M5223X
{
ADC_SETUP adc_setup; // interrupt configuration parameters
adc_setup.int_type = ADC_INTERRUPT; // identifier when configuring
adc_setup.int_handler = adc_level_change_high; // handling function
adc_setup.int_priority = ADC_ERR_PRIORITY; // ADC interrupt priority
adc_setup.int_adc_bit = 1; // ADC bit 0
adc_setup.int_adc_int_type = (ADC_HIGH_LIMIT_INT); // interrupt types
adc_setup.int_adc_offset = 0; // no offset
adc_setup.int_high_level_trigger = (unsigned short)(ADC_VOLT * 2);
adc_setup.int_adc_mode = (ADC_CONFIGURE_ADC | ADC_CONFIGURE_CHANNEL | ADC_SEQUENTIAL_MODE | ADC_SINGLE_ENDED | ADC_LOOP_MODE | ADC_START_OPERATION); // use to test single ended
adc_setup.int_adc_speed = (unsigned char)(ADC_SAMPLING_SPEED(100000)); // {29} 5MHz sampling (must be between 100kHz and 5MHz)
adc_setup.int_adc_result = 0; // no result is requested
fnConfigureInterrupt((void *)&adc_setup); // configure test interrupt on high level trigger
fnResult(); //my result reading function
}
subsequently my fnResult()
static void fnResult(void)
{
int iADC_delay = -1;
CHAR *cBuffer[100];
ADC_SETUP adc_setup;
ADC_RESULTS results;
adc_setup.int_type = ADC_INTERRUPT;
adc_setup.int_adc_bit = 1;
adc_setup.int_adc_result = &results;
adc_setup.int_adc_mode = (ADC_READ_ONLY | ADC_GET_RESULT); //ADC_ALL_RESULTS
do {
fnConfigureInterrupt((void *)&adc_setup);
iADC_delay++;
} while (results.ucADC_status[1] == ADC_RESULT_NOT_READY);
if (results.ucADC_status[1] != ADC_RESULT_NOT_READY) {
fnWrite(SerialPort1, (unsigned char *)"\r\nResult = \r\n", 16); //result ready
fnBufferHex(results.sADC_value[1], (unsigned char)(4 | NO_LEADIN | WITH_TERMINATOR), cBuffer[100]);
fnWrite(SerialPort1, (unsigned char *)cBuffer, 10); //display the value
}
else {
fnWrite(SerialPort1, (unsigned char *)"\r\nResult = NA\r\n", 16);
}
}
my configuration for channel 1 is exactly like above. it's actually free running, and when i inject a low voltage, say 1.5V or 2V, it proceeds to the line fnWrite "Result = ", without showing any value.
after this it will stuck at the handling function adc_level_change_high. by adding a line message fnWrite "lvl high" in adc_level_change_high, what i get in serial output is "Result = ", then "lvl high" and it keeps repeating until i remove the input voltage. i really have no idea which part i make mistake because i follow all the steps, and i presume EVENT 2 has nothing to do with this.