I had a similar problem. We thought it was the encoder at first, but it would up being the transponder itself. If you've got a good local avionics shop, give them a try.
If you have a G327, you can enter the setup menu and have it display the grey code input from the encoder - start there. Then, if that shows Ok, check the grey code from the encoder to see if it's working. It sounds like you have one of the bits of the grey code stuck. Google for encoder grey code and you'll get a table of the bits and resulting altitudes.
When I had the problem, it turned out to be in the G327 iteslf. Garmin charges a flat $600 to service a G327, regardless of what is wrong. On mine, all they did was flash and upgrade the firmware and it's worked fine ever since. Strange.
Doug
190 hours in the CT and have loved every one.