Answered: Help With Analog and Digital Inputs

I am having a quirky little issue where I have added a light sensor to the bot. (It is plugged into input #4) In the C code, I have set up the the IO ports as inputs and used the “Set_Number_of_Analog_Channels(FOUR_ANALOG)” statement so I could get analog in on input #4.

According to the ifi_aliases.h file, setting FOUR_ANALOG converts inputs #1 - #4 into analog inputs. All my limit switches are on #s 5-7.

Whenever I use: LightSensor=Get_Analog_Value(rc_ana_in04); all my other digital inputs read 0 and do not respond to the limit switches. (rc_dig_in## always returns zeros.) The light sensor reading comes in just fine. If I comment out the Get_Analog line, then all my digital inputs work fine.

Is there something I am missing in the configuration? Or do I need to execute a Get_Digital style subroutine to get my digital info back? (I am using the MPLAB and IFI programming environment for the VEX - very nice I must say.) I am very familiar with the PIC familiy of processors, but am hoping to not have to dig that deep.

I tracked down my problem, my “printf” statement for debugging had too many variables in it. When I broke it apart into two smaller “printf” statements, the problem went away. (I guess a 20 variable “printf” statement is a little too much for the complier).

For those more technical folks, the ADCON1 register was not getting reset to its proper value afer a Get_Analog_Value. The wrong value in ADCON1 will block digital inputs. Apparently the oversized “printf” statement was corrupting other - low level routines and ADCON1 wasn’t getting restored.

Not sure what the problem was but we were able to add printf statements to his code and it did not have any effect on reading the digital ports.