Ok, I don't understand why and I hope someone can enlighten me. All I did was change all of my pins on the PortA to inputs. Previously TRISA =%00001000 - my program did not work. I changed TRISA = %0011111 and then the A to D function works fine and my LCD displays a linear value from 0 to 255 for as I turn my pot. I can also read the voltage on the pin and it is linear.
I checked my code and I think must have just had the wrong pin selected as an input. I changed TRISA to TRISA = %00010000 and everything works fine now. Thanks to all of those that posted.
Now that I have gotten that the A to D to work, I have switched to a 10 bit result to get greater resolution.
Does anyone have suggestions as to how to make change the value that I am displaying from 0 to 1024 into a voltage? I guess it would be to take 5 and divided by 1024, so 5/1024 = 0.00488 and use this to multiply the result to come up with a voltage. So say the voltage is 3.5, I would need a reading of 716 multiplied by 0.488 to come up with 3.5V.
Does anyone have a better idea than this to use to display the voltage from a pot? Thanks.




Bookmarks