Confused over A/D settings


Closed Thread
Results 1 to 4 of 4
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Confused over A/D settings

    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
    Code:
    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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Skip the "PBP Project book".

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

    ADCON1 = %00001011

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

    ADCON2.7 = 1
    DT

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    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 !

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Well that's fixed... now able to set the temps by the pots..



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

Similar Threads

  1. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 02:16
  2. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  3. Need advice on A/D
    By james in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th August 2007, 19:30
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. 18F2525 A/D, Comparator and Vref modules
    By fbraun in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th May 2005, 23:17

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts