Haven't checked anything in detail but I see you're using ADCIN to read the pot but you're not telling the compiler anything about how you want it read.

I suspect you're either sample time is way to low or you have mismatch between the expected number of bits and the left/right justification. I don't know what PBP defaults to when you don't tell it anything with the DEFINEs.

Check the manual for the DEFINEs belonging to ADCIN.

You have x decalred as a WORD which makes me Think you WANT 10 bits from the ADC but the digipot you're using expects 8bits only. From memory I don't know how SHIFTOUT handles WORD variables like in this case. Is it actually shifting out 16 bits or is it only shifting out 8 of the 16bits and if that's the case is it the lower or higher byte.

/Henrik.