16F684 AtoD problem


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    37

    Default 16F684 AtoD problem

    Hi!
    I am trying ADC of 16F684 with this simple code.The problem is that the analog input channels are pulled high.I have tried with different registers but all in vain.


    PORTC=0
    CMCON0=$07
    'CMCON0=$00
    ANSEL=$00
    TRISC=$00
    WPUA=$00 'doesnt effect the output
    'OSCCON=%1110111

    'configure ADC
    ADCON1=%01110000
    TRISA.0=1
    PORTA=$00
    ANSEL.0=1

    ADCON0=%00000001

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

    adval var word ' Create adval to store result
    Res Var word


    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    Define LCD_RSBIT 4
    Define LCD_EREG PORTC
    Define LCD_EBIT 5
    DEFINE LCD_BITS 4


    Lcdout $fe,1
    loop:
    ADCIN 0, adval

    Res = 2*adval

    Lcdout $fe, $80
    Lcdout "T:", DEC2 Res,"C" 'text for the line 1

    Pause 300
    goto loop

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think this is all you need to set for this PIC. I have not used one for awhile...
    Code:
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    TRISA.0=1
    ANSEL.0=1
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    I have Set these bits in my program but still the port pins are pulled up.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What is your analog source?
    Can you post a schematic and your current code?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    I have already posted the code.Analog source is simply a pot for 1-5V range.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello hell_pk,
    Try adding OPTION_REG.7 = 0 to the upper area of you code.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hell_pk View Post
    I have already posted the code.Analog source is simply a pot for 1-5V range.
    Post #1 shows a lot of things but it is difficult to tell where the code is or the things you hace tried. Post your current code in tags like Mr.E suggest.

    You have ANSEL set two different ways in post #1. Is that the way you have it in your code?

    Did you read and try post #2? Some of the registers PBP handles for you when using ADCIN.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. 877A AtoD config problem?
    By ttease in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st April 2007, 16:57
  4. 16F684 ADC problem
    By markedwards in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th August 2006, 06:51
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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