ADC Help Please


Closed Thread
Results 1 to 15 of 15

Thread: ADC Help Please

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    I will try to read the ADC manually then,

    And I missed your hint, because the code is working for those I/O's (however the comments are wrong!).

    'Set entire PortB as digital output
    PORTB = %00000000
    TRISB = %00000000
    'Set entire PortC as digital output
    PORTC = %00000000
    TRISC = %00000000
    'Set entire PortD as digital output
    PORTD = %00000000
    TRISD = %00000000
    Looks better now

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    Ok, I just tried to recompile my code for a 16F877A and if does work much better. Values are still fluctuating a bit so I will have to find a way to stabilize this (using software and or hardware).

    here is the new init code

    '************************************************* ******
    'Init for PIC16F877A
    '************************************************* ******

    'Set ADC pins to digital operation
    ADCON1 = %10001001 'AN0 to AN5 are analog input
    CMCON = %00000111 'disabling the comparator module

    'Define pin function
    TRISA = %00101111 'Set PortA as input or output
    TRISB = %00000000 'Set entire PortB as digital output
    TRISC = %00000000 'Set entire PortC as digital output
    TRISD = %00000000 'Set entire PortD as digital output
    TRISE = %00000001 'Set PortE0 as input and rest as output

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    I thought I would use a 16F88x since the 877A is being phased out. Also I have a couple 884 on hand... but with all the extra trouble I think I will stick to the 877A to write the code and then transfer it to the 884 afterward.

    Will update the status of the project here


    PS: as far as my noise problem comming from the HV generation circuit, I now switch off the PWM module that drive the switching mosfet slightly before doing my analog readings and they are now rock solid
    Last edited by aberco; - 12th February 2009 at 16:11.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 18:29
  3. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 0

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