16F684 AtoD problem


Closed Thread
Results 1 to 14 of 14
  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
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Still not working

    I have added the line but still no result.very strange.
    i have configured all registers ANSEL,WUPA etc in program.
    What am I missing!!!

  8. #8
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    You have all the inputs as digital inputs ANSEL = $00 Shouldn't A0 be an analogue input?

    Adrian

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Out of curiosity, which compiler version are you using?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    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.

  11. #11
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Compiler ver 2.50
    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
    
    OPTION_REG.7 = 0
    PORTC=0
    
    CMCON0=$07
    'CMCON0=$00
    ANSEL=$01
    TRISA=$01
    TRISC=$00
    WPUA=$00
    'OSCCON=%1110111
    
    'configure ADC
    ADCON1=%01110000
    
    PORTA=$00
    
    ADCON0=%00000001
    
    adval	var	word		' Create adval to store result
    Res Var word
    
    ' Define LCD registers and bits
    
    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
    
    Pause 300
    
    Lcdout $fe, $80
        Lcdout "T:", DEC2 Res,"C"  'text for the line 1
    
    Lcdout $fe, $80+8 ,#Res
    	Lcdout $fe, $C0  'set cursor at the beginning of line 2
    	Lcdout "V: ", #adval  'formatted text for line 2
    	
    
    Pause 300
    goto loop

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


    Did you find this post helpful? Yes | No

    Default

    Try commenting out these lines
    Code:
    ADCON1=%01110000
    
    PORTA=$00
    
    ADCON0=%00000001
    I think they may be causing a conflict.
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default No luck

    Still no luck.The Analog channel pulls up before ADCIN command therefore something must be wrong with register configs.
    very frustrating!

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


    Did you find this post helpful? Yes | No

    Default

    Sorry for all the confusion, here is some tested code.
    I have it running right now.
    Code:
    <html>
    <head></head>
    <body><!--StartFragment--><pre><code><font color="#00FF00"><b><i>'16F684 ADCIN TEST
    
    </i></b></font><font color="#008000">@  __config _INTRC_OSC_NOCLKOUT &amp; _WDT_ON &amp; _MCLRE_OFF &amp; _CP_OFF
    
    </font><font color="#0000FF"><b>DEFINE </b></font><font color="#FF0000">ADC_BITS </font>8 <font color="#00FF00"><b><i>' Set number of bits in result
    </i></b></font><font color="#0000FF"><b>DEFINE </b></font><font color="#FF0000">ADC_CLOCK </font>3 <font color="#00FF00"><b><i>' Set clock source (3=rc)
    </i></b></font><font color="#0000FF"><b>DEFINE </b></font><font color="#FF0000">ADC_SAMPLEUS </font>50 <font color="#00FF00"><b><i>' Set sampling time in uS
    </i></b></font><font color="#FF0000">TRISA</font>=%00000001
    <font color="#FF0000">ANSEL</font>=%00000001
    <font color="#FF0000">ADX</font>	<font color="#0000FF"><b>VAR</b></font>	<font color="#0000FF"><b>BYTE
    </b></font><font color="#FF0000">START</font>:
    <font color="#0000FF"><b>HIGH </b></font><font color="#FF0000">PORTC</font>.4
    <font color="#0000FF"><b>PAUSE </b></font>250
    <font color="#0000FF"><b>LOW </b></font><font color="#FF0000">PORTC</font>.4
    <font color="#0000FF"><b>ADCIN </b></font>0, <font color="#FF0000">ADX
    </font><font color="#0000FF"><b>PAUSE </b></font>250
    <font color="#0000FF"><b>SEROUT2 </b></font><font color="#FF0000">PORTC</font>.5, 17197, [<font color="#0000FF"><b>DEC </b></font><font color="#FF0000">ADX</font>, $d, $a]
    <font color="#0000FF"><b>GOTO </b></font><font color="#FF0000">START
    </font></code></pre><!--EndFragment--></body>
    </html>
    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