PDA

View Full Version : Confused over A/D settings



malc-c
- 22nd February 2010, 09:50
In reference to this thread http://www.picbasic.co.uk/forum/showthread.php?t=12714 I still can't get the A/D conversion working when porting the code from 16F877A to an 18F4550.

For some reason the following code work on the 16F877A but not the 18F4550


DEFINE ADC_BITS 10 ' Set-up ADC for fastest 10-bit results
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 5
INCLUDE "DT_Analog.pbp"

MaxSetPoint CON 350 ' Pot fully clockwise
MinSetPoint CON 100 ' Pot fully counter clockwise
ADbits = 14 ' set A/D resolution to 14-bits
CMCON = 7 ' disable Comparators
ADCON1 = %10000010 ' AN0-4 Analog, Right justify
ADCON1 = $0F


I've checked the datasheet and read a section on A/D from one of my PbP project books, and if I've read it correctly the ADCON1 = %10000010 should set the register up as output right justified (bit 7 set to 1), AN7-AN5 digital, AN4-AN0 analogue, Vref+=vdd and Vref-=Vss.

However it then has the line ADCON1 = $0F which (from googling) sets all pins to digital... OK fair enough I though, simply comment out this line, however when I do this all I get on the LCD display is a row of squares on the top row, which flash as the PIC is performing the rest of the functions (PID calculations etc). If I then uncomment the ADCON1=$0F line the temperatures from all the probes (which are on port D) are displayed. It is as if ADCON1 is setting all pins on all ports to digital :confused:

Darrel Taylor
- 22nd February 2010, 10:09
Skip the "PBP Project book".

Have another look at the datasheet for an 18F4550.
http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
Page 266, Register 21-2 ADCON1

ADCON1 = %00001011

Also notice that the ADFM bit isn't in ADCON1 anymore.

ADCON2.7 = 1

malc-c
- 22nd February 2010, 10:38
Cricky... you're up late !

Thanks again.... one day I'm hoping all this will click and I'll understand these subtle differences in the different PICs !

malc-c
- 22nd February 2010, 10:44
Well that's fixed... now able to set the temps by the pots..

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4037&d=1266835401

Just need to work out why the outputs have stopped working, especially when the PID should be resulting in a value above zero ....:mad: