Analog to Digital 16F628

I am a learner pic programmer and I am having some major grief trying to get the analog to digital (A2D) feature to work on my 16F628. All I would like to do is to be able to read in a value (either the most or least significant byte) and out put it again, just as a starting point for a project, the rest of which i can figure for myself. I have trauled the web for nigh on.. 3 hours and found few resources, but all were out of date or for a different chip. If anyone could help me either in terms of a bit of ASM code, some general guidence, or a link to a relevant tutorial that would be great. Thanks, Andy

sort by: active | newest | oldest
little9 years ago
Please.. I have a 16f628 and ma just trying to get it to work. I would like all pins to be output except the power pins. I can not get my blink test to work. Do i need have a special confiuration or what?? Please help.. jlittle
andy (author)  little9 years ago
I had a similar problem when I started up; I got sample code but couldn’t get it to work. 1, make sure that you have your option bits set. 2, make sure you have your outputs set. 3, make sure it’s wired correctly. The files on your orange board should work, its adapted from some sample code that came with it, hopefully the commenting is self explanatory. It will flash all of portA (or should) at a slow rate. I know how irritating it is when things should work but don't, keep at it though, it’s worth it. Best of luck, hope this helps, Andy P.S. I couldn’t get the file to upload, instructables doesn’t load my library, hence their presence on your Orange board, sorry for any inconvenience.
neelandan10 years ago
You can do A to D with a digital port pin or two. It involves charging a capacitor with the input voltage, then discharging it and measuring how long it takes. I think there are several application notes at the Microchip web site detailing the process. If you need to do ADC with a single instruction then you will have to use one with a ADC built in. The PIC16F877 is one such.
andy (author)  neelandan10 years ago
oo, thank you, that's exactly what I need. Many thanks neelandan, you have brought me back from the brink of dipair. Andy
westfw andy10 years ago
cause heaven forbid if you'd have to replace your 16f628 with a pin-compatible 16F88 (for example) that DOES have a real A-D converter? You could have free samples in a couple weeks...
andy (author)  westfw10 years ago
Sounds good also. Ill try to implement it with the capacitors myself next week when i have some time off (could not find it on the Microchip site but i can see how it would work...), if i cannot mannage it i will then try the alternitive chips suggested. Thanks for your time, Andy
frank2608011510 years ago
There is a very good reason why you can't do it

pic16f628 and pic16f628a don't have a A/D converter feature, try another pic

here's some example code in C, http://www.lika.be/content/view/21/30/ , you can compile it with sourceboost http://www.sourceboost.com it's free
andy (author)  frank2608011510 years ago
Ah, that very well could be why then, i must have miss understood the documentation. Thanks for your help, you probably saved me another 3 hours of frustration. many thanks, andy
andy (author) 10 years ago
When I say "output it" I ment into a register. Sorry, I should pay attention when I proof read, Andy