Stuck with ADC and justification!

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I am presently involved in my project of making a power supply with an LCD readout for voltage.

The other thread I started was in general electronics and I am with the help of Eric Gibbs, just about getting things moving on the PSU side of things.

Now I am coming to the PIC micro part which I am using a 16F872 to read 3 sets of voltage and 1 current measurement. My problem is due to ADC being new to me. Most of my projects so far have been digital only. I program using PicBasic Pro.

Can anyone explain in simple terms what Left Justify or Right Justify means. I just don't get that when I have a 10bit ADC and justify it either way, if it reads 6bits as zero then surely won't it leave me with only 4 bits of data?

Also I am a little puzzled as to what to do with ADCON1? I am wanting 4 ADC readings so I figure I need to set the last four bits as 0011 (I am also using a 4096 presicion Ref on Vref) but WHERE in the program do I use it? Should I set the MSB to Left or right Justify? And finally do I need to set ADCON1 more than once or is it sufficient to set and leave it?

All help appreciated, Al

PS here is the part of the 16F872 datasheet showing the ADCON1 data.
 
As the result of the ADC is 10 bits you can have the result in the 8 bit registers ADRESH and ADRESL in two different ways...

Right justified..

.....ADRESH.................ADRESL........
|X|X|X|X|X|X|9|8| |7|6|5|4|3|2|1|0|

Left justified..

.....ADRESH.................ADRESL........
|9|8|7|6|5|4|3|2| |1|0|X|X|X|X|X|X|

If you want to run with just an 8 bit result. left justified then read ADRESH only

If you want 10 bit you need to add the two registers

EDIT!! Combine the two registers, ie.. multiply the ADRESH before adding the ADRESL....
 
Last edited:
Hi Al,

May I ask if PBP doesn't have built-in ADC functions for you to use? And if so, is there a chance that the functions may automatically take care of the justification settings?

Regards, Mike
 
Hi Ian,

Thanks mate! You explained that perfectly! I now understand it at last.

I have been looking for hours for the justification meanings.

Al
 
Hi Mike,

Well you would think that the manual would have all the info required but here is the COMPLETE part of the manual pertaining to ADC.

Then they expect you to be fluent?

Al

Please note that though the justification is seemingly taken care of that the channel being read can be more than one on some chips and it seems they expect you to know about that beside knowing basic.

The info on ADCON1 is very limited and nowhere does it say where and when it needs to be applied.

 
Last edited:
Oh my goodness, that's not really very helpful, is it? Did you look for examples over on the PBP forum, Al?
 
they expect you to be fluent?
Yes, you should at least have some cursory knowledge of the datasheet. Regardless of which MCU you use (Microchip, Atmel, etc), there are two main things that compose them: MCU core and Peripherals. Before using any peripherals you need to configure them - that is true no matter which device/vendor you use.

This states you must configure TRIS, ADCON (0 and/or 1), ANCON and/or ANSEL before you use the ADCIN command.

I haven't used PBP in years; but if I recall there were examples of how to use the built-in ADC on the Examples folder.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…