AnsweredAssumed Answered

ADC Bug found in TWRK60f120M ini_gpio.c

Question asked by keith tang on May 26, 2012
Latest reply on Jun 6, 2012 by keith tang

I am new in MQX, and still learning how to use MQX on TWRK60F120M board. Through scanning the files, I found one bug, which I hope someone can verify it.

 

In init_gpio.c, line 456:

 

        case ADC_SOURCE_MODULE(1): /* ADC0 */
            if (ADC_GET_MUXSEL(source) == ADC_SOURCE_MUXSEL_A)
            {
                if(ch < 4)
                {
                    gpio_port = adc0_conv_table_a[ch - 4];
                }
                else
                {
                    return IO_ERROR; /* channel does not exist */
                }
            }

 

Obviously if ch < 4, ch-4 will be negative. I believe it should be:

 

        case ADC_SOURCE_MODULE(1): /* ADC0 */
            if (ADC_GET_MUXSEL(source) == ADC_SOURCE_MUXSEL_A)
            {
                if(ch >= 4 && ch <= 7)
                {
                    gpio_port = adc0_conv_table_a[ch - 4];
                }
                else
                {
                    return IO_ERROR; /* channel does not exist */
                }
            }

 

or we can inert the code:

 

        case ADC_SOURCE_MODULE(1): /* ADC0 */
            if (ADC_GET_MUXSEL(source) == ADC_SOURCE_MUXSEL_A)
            {
                if(ch < 4 || ch > 7)
                {
                    return IO_ERROR; /* channel does not exist */
                }
                else
                {
                    gpio_port = adc0_conv_table_a[ch - 4];
                }
            }

 

Please let me know if this is the case. Thanks.

Outcomes