PDA

View Full Version : 10bit ADC with offset on 16F88



Amoque
- 29th March 2012, 14:14
Some days ago I posted for help with this, but I think it was overlooked in a post with 2 issues to address. Below is my best effort at configuring a 16F88 ADC (AN0) to operate 10bit with an offset +Vref on AN3. Some unexpected results with a standard ADC setup (a 10K pot gives expected results, but the sensor does not) have me wondering if the sensor (LM34CZ) is damaged. My intent is as here: http://www.rentron.com/PicBasic/LM34.htm, but of course the ADC setup is different for the ’88.

Will someone who knows this chip verify/ correct my configuration?

Thank you.




‘----------------------configure P16F88 fuses
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF
__config _CONFIG2, _FCMEN_OFF & _IESO_OFF
#ENDCONFIG
‘----------------------configure oscillator for 8M internal
DEFINE OSC 8
OSCCON = %01110000

‘----------------------configure ADC for +Vref on AN3, ADC on AN0
ANSEL= %00001001 'ANALOG OFF, EXCEPT +Vref (AN3) AND AN0
TRISA = %00001001 'PORTA TO MATCH ANSEL
TRISB = %00000000 'PORTB DIGITAL
ADCON1.7 = 0 : ADCON1.6 = 0 : ADCON1.5 = 1 : ADCON1.4 = 0 'LEFT JUSTIFIED : ADCS2 DISABLED : VCFG Vref+ AVSS
ADCON0 = %01011001 'Fosc/8 : AN3 ACTIVE : ADC ON

cc1984
- 30th March 2012, 22:37
Amoque,
Looking at the data sheet it looks like you have your setup right. Might be in the code that you have for reading, converting, etc. LM34 should be easy to check if it is working correctly. Apply power and check to see if the output matches what your thermometer says.
Chris.

retepsnikrep
- 31st March 2012, 05:22
ADCON1.7 = 0
ADCON1.6 = 0
ADCON1.5 = 1
ADCON1.4 = 0 'LEFT JUSTIFIED
ADCS2 DISABLED : VCFG Vref+ AVSS



Double check all this in the data sheet. Asfaik you need to right justify for ten bit results. 1.4 is not the justify bit

Dave
- 31st March 2012, 13:15
amoque, Here ia a bit of code I wrote some time ago for a boost gage used to read the boost pressure for a car using a 16F88 and displaying the results on a 7 segment display. It should have everyting you need.... PLease give credit where credit is due....

Amoque
- 1st April 2012, 15:11
Thank you all for the responses!

There is significant there to digest Dave, but be assured I will give proper credit now, and as I study the other concepts you demonstrate, in the future as well--including the "COWS_COME_HOME" reference! :)