need simple A/D converter

We want to use PIC 18F452 to convert a voltage from solar cell into a digital value, to be read by a PC using parallel port. This cannot be changed.

Can someone provide me a pointer to a sample code or a simple book or URL where to find the basic programming for Analog to Digital conversion using 18F452 ?

Our actual problem now (one of few ... or lots of them) is how to define the "range" of the input signal.

I mean, how does the PIC know if an input of 3 volts is "100 %" of the signal, ( corresponding to "0xFF" digital output ) or it is just "50 %" of the voltage range ( corresponding to 0x80 digital output, more or less ... ) ?

Thanks.

Reply to
SebastiaNot
Loading thread data ...

Hi!

Each ADC needs a reference voltage which defines 100% or 0xFF (for a 8-Bit ADC). In the case of your PIC there is a matrix in the datasheet

formatting link
on page 184 (chapter 17). From this you could read out, whats the reference voltage when using a defined configuration.

regards,

--
Bernhard Schauer
schauer_at_cruxy_dot_net
Reply to
Bernhard Schauer

Yeah, the data sheet, plus a potentiometer, a voltmeter, and a loop that writes the reading to a serial port will get you pretty far...

Reply to
cs_posting

Thanks a lot, Bernhard - including the URL to the datasheet was also great. I can manage the potentiometer, and the voltmeter ... the problem is with that crazy (at first sight) micro-processor.

It used to be ... the A register, plus the Flags, and the B-C registers, and the H-L registers .... and that was all !

(:-))

Reply to
SebastiaNot

I'd be very surprised if there isn't example code somewhere on their website.

Reply to
cs_posting

One easy way is to do it with Forth !

FlashForth is a a Forth OS that runs on the PIC18F452. See

formatting link

After you have programmed the FF kernel to the PIC, you can via the serial port expirement with how the PIC works.'

Here is the Forth source code of how to read the AD converter on the PIC18F452.

hex ram ffc4 constant adresh ffc3 constant adresl ffc2 constant adcon0 ffc1 constant adcon1 ff80 constant porta ff92 constant trisa

bin : adinit ( -- ) \ Init the registers 00111111 trisa c! 11001100 adcon1 c! 10000001 adcon0 c! ; hex

: ad@ ( channel -- n ) 3 lshift adcon0 c@ c1 and or adcon0 c! \ Select the AD channel pause \ Aquisition delay 4 adcon0 mset \ Start conversion begin 4 adcon0 mtst 0= \ Wait for conversion to complete until adresl @ \ Fetch the result ;

Now with the command " 1 ad @ " you can read the AD conversion result for channel 1 !

adinit ok 1 ad@ ok . 3ff ok

The converted value 3ff is returned on the parameter stack and printed with "." .

Reply to
Mikael Nordman

I have been told "Sample code is in the 18F452 datasheet" ... and you do know "39564c.pdf" is 300 pages +++ ... so I am still searching. Thanks for your help !

Reply to
SebastiaNot

Michael - thanks for the clue. I shall spend some time in that URL, of course. And thanks also for the code - I will read, even if it takes me 10 days !!! (;-)) Cheers. !

Reply to
SebastiaNot

OOOOHHHHH NNNOOOOOOOO !!!!!!!!!!!!!

You want to damage his brain ??!!!

donald

Reply to
donald

This may be all you need. Low speed low cost. reasonably accurate. It can be set up to generate engineering units like volts directly.

formatting link

Regards,

-- Walter Banks Byte Craft Limited Tel. (519) 888-6911

formatting link

Reply to
Walter Banks

You can also look at the App Notes on the Microchip Website. Try Piclist.com too.

Reply to
Neil

Walter : I dont understand why shall I implement an A/D converter ... ... if 18F452 already has this function implemented ?

Eventhough, you page looks very nice to me, HW people ...

(:-))

Reply to
SebastiaNot

Neil : thanks for both links

I was begging some sweet soul to point me to a SPECIFIC App Note ... And PicList is also quite Huge ....

Thanks anyway !

Reply to
SebastiaNot

If you want to post a followup via groups.google.com, ensure you quote enough for the article to make sense. Google is only an interface to Usenet; it's not Usenet itself. Don't assume your readers can, or ever will, see any previous articles.

More details at:

Some useful links on quoting:

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

Bernhard :

At the begin of chapter 17 of "

formatting link
" it says

The analog reference voltage is software selectable to either the device's positive and negative supply voltage (VDD and VSS), or the voltage level on the RA3/AN3/VREF+ pin and RA2/AN2/VREF- pin.

How do I tell the PIC I want VDD as "reference" (100%) voltage ?

Seb.

Reply to
SebastiaNot

ADCON1. You can assume that if Vref+ and/or Vref- are not routed to a pin they are Vdd/Vss respectively.

You're pretty much going to have to read and understand that whole section if you expect to reliably use the ADC. Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

Yes, mr Spehro .... ... Chapter 17 will have to be read by me, from its begin to its end. Cheers.

Reply to
SebastiaNot

mr Chuck - thanks a lot for the improvement - I shall try to improve my notes ! cheers.

Reply to
SebastiaNot

Hi Chuck, This was generated by clicking on the 'reply' button. I have left the entire quote intact to demonstrate that it appears that Google has solved the quoting problem. Rocky

Reply to
Rocky

Better. However you have still failed to snip portions that have nothing to do with your reply. This especially includes my sig (everything from the "-- " marker on). Read the links I gave you.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.