Thanks MartinK.
I just revisit the files, and found that the above solutions were conceptually right but practically incorrect, and I have fixed them.
For those who cannot wait for the new release, here is what I have done to get it work:
1. In ".\Freescale MQX 3.8\mqx\source\io\adc\adc_mk60.h":
Modify this line so that it looks like this:
#define ADC1_SOURCE_AD20 (ADC_SOURCE_MODULE(2) | ADC_SOURCE_MUXSEL_B | ADC_SOURCE_CHANNEL(20))
Insert this line:
#define ADC1_SOURCE_DM1 (ADC1_SOURCE_AD20)
2. In ".\Freescale MQX 3.8\mqx\source\bsp\twrk60f120m\twrk60f120m.h":
Modify this line:
#define BSP_ADC_CH_POT (ADC1_SOURCE_DM1)
3. In ".\Freescale MQX 3.8\mqx\source\bsp\twrk60f120m\init_gpio.c":
Modify so that it looks like this:
const static uint_8 adc1_conv_table_bx[] = {
ADC_SIG_NC, /* 0 leave as default */
ADC_SIG_NC, /* 1 leave as default */
ADC_SIG_NC, /* 2 leave as default */
ADC_SIG_NC, /* 3 leave as default */
ADC_SIG_PORTC | 8, /* ADC1_SE4b/CMP0_IN2 */
ADC_SIG_PORTC | 9, /* ADC1_SE5b/CMP0_IN3 */
ADC_SIG_PORTC | 10, /* ADC1_SE6b */
ADC_SIG_PORTC | 11, /* ADC1_SE7b */
ADC_SIG_PORTB | 0, /* ADC0_SE8/ADC1_SE8/ADC2_SE8/ADC3_SE8/TSI0_CH0 */
ADC_SIG_PORTB | 1, /* ADC0_SE9/ADC1_SE9/ADC2_SE9/ADC3_SE9/TSI0_CH6 */
ADC_SIG_PORTB | 4, /* ADC1_SE10 */
ADC_SIG_PORTB | 5, /* ADC1_SE11 */
ADC_SIG_PORTB | 6, /* ADC1_SE12 */
ADC_SIG_PORTB | 7, /* ADC1_SE13 */
ADC_SIG_PORTB | 10, /* ADC1_SE14 */
ADC_SIG_PORTB | 11, /* ADC1_SE15 */
ADC_SIG_NC, /* ADC1_SE16/CMP2_IN2/ADC0_SE22 */
ADC_SIG_PORTA | 17, /* ADC1_SE17 */
ADC_SIG_NC, /* VREF_OUT/CMP1_IN5/CMP0_IN5/ADC1_SE18 */
ADC_SIG_NC, /* 19 not implemented */
ADC_SIG_NC, /* 20 not implemented */
ADC_SIG_NA, /* 21 not implemented */
ADC_SIG_NA, /* 22 not implemented */
ADC_SIG_NC /* DAC1_OUT/CMP0_IN4/CMP2_IN3/ADC1_SE23 */
// TODO still have 8 channels to complete, but doesn't matter for now..
};
Modify so that it looks like this:
case ADC_SOURCE_MODULE(2): /* ADC1 */
if (ADC_GET_MUXSEL(source) == ADC_SOURCE_MUXSEL_A)
{
if(ch < 4)
{
gpio_port = adc1_conv_table_a[ch];
}
else
{
return IO_ERROR; /* channel does not exist */
}
}
Note: the same should be applied to other channels. But since the tower connects the potentiometer to ADC1_DM1, I only hightlight this channel.
You should get the reading printed on the debug screen.