Analog input problem


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2008
    Posts
    43

    Default Analog input problem

    Hi everybody,

    When I use this code i get correct results

    Code:
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS  4
    DEFINE LCD_LINES 2
    DEFINE OSC 4                                                                       
    DEFINE ADC_BITS     8       
    DEFINE ADC_CLOCK  3       
    DEFINE ADC_SAMPLEUS 100
    bilgi var byte
    red var byte
    green var byte
    blue var byte
    flag1 var byte
    flag2  var byte
    flag3 var byte
    SYMBOL VERI=PORTA.0
    ADCON1=2
    TRISA=%00000001 
    TRISB=0
    PORTB=0
    TRISC=0
    LCDOUT $FE,1 
    
    
    
    
    yap:
    
    flag1=0 
    flag2=0
    flag3=0
    
    high PORTA.1
    PAUSE 750
    CALL ADC_OKUMA
    red=bilgi
    pause 5
    low PORTA.1
    
    
    high PORTA.2
    PAUSE 750
    CALL ADC_OKUMA
    blue=bilgi
    pause 5
    low PORTA.2
    
    
    high PORTA.3
    PAUSE 750
    CALL ADC_OKUMA
    green=bilgi
    pause 5
    low PORTA.3
    
    
     
    pause 7000
    
    goto yap
    
    
    
    ADC_OKUMA:
    ADCIN VERI,bilgi
    RETURN
    But I cannot use porta.5 and get wrong results
    Where am I wrong adcon1 settings or something else???

    Code:
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS  4
    DEFINE LCD_LINES 2
    DEFINE OSC 4                                                                       
    DEFINE ADC_BITS     8       'A/D çevirim sonucu kaç bit olacak
    DEFINE ADC_CLOCK  3       'Clock kaynağı (3=rc)
    DEFINE ADC_SAMPLEUS 100
    bilgi var byte
    red var byte
    green var byte
    blue var byte
    ADCON1=2
    input PORTA.5
    SYMBOL VERI=PORTA.5 
    TRISB=0
    PORTB=0
    TRISC=0
    LCDOUT $FE,1 
    
    
    
    yap:
    
    high PORTD.7                    
    PAUSE 750
    ADCIN VERI,bilgi
    red=bilgi
    pause 5
    low PORTD.7
    
    
    high PORTD.6
    PAUSE 750
    ADCIN VERI,bilgi
    blue=bilgi
    pause 5
    low PORTD.6
    
    
    high PORTD.5
    PAUSE 750
    ADCIN VERI,bilgi
    green=bilgi
    pause 5
    low PORTD.5
    
    CALL GOSTER
    
    
    
    
    
    
    
    
    
    
    
     
    
    
       
    pause 7000
    goto yap
    
     ADC_OKUMA:
    ADCIN VERI,bilgi
    RETURN 
    
    GOSTER:
    LCDOUT $fe,2,#red," ",#blue," ",#green," "
    
    RETURN

  2. #2
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    By the way I just tried adcon1=0 it didnt work again...How can I use porta.5 as analog input ????

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


    Did you find this post helpful? Yes | No

    Default

    Knowing your PIC model would help us.
    Steve

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

  4. #4
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    my pic is 16f877a

  5. #5
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    ı wrote this code.


    What i see on lcd is the values getting bigger .Started 90,100,108,120,145

    How can i use first analog five input pins in 16f877a...

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE OSC 4
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 100
    SYMBOL VERI=PORTA.5
    deneme var byte
    ADCON1=10000010
    TRISA=%11111111
    basla:
    LCDOUT $FE,1
    adcin veri,deneme
    LCDOUT $fe,2,#deneme," "
    pause 3000
    goto basla

    end
    which setting is wrong ???

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


    Did you find this post helpful? Yes | No

    Default

    1. you have to set trisa.5 to 1, make this pin as input
    2. choose an ADCON1 setting that set AN4 as analog, =0 or =2 have to work
    3. make sure analog comparator is disable. CMCON=7
    4. use ADCIN with analog channel number, not his pin name
    ADCIN 4, YourVariable

    HTH
    Steve

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

  7. #7
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    I wrote this but same problem continues.the value starts 111 gets bigger and bigger up to about 249-254

    Code:
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS  4
    DEFINE LCD_LINES 2
    DEFINE OSC 4                                                                       
    DEFINE ADC_BITS     8       
    DEFINE ADC_CLOCK  3     
    DEFINE ADC_SAMPLEUS 100
    deneme var byte
    ADCON1=2
    trisa.4=1
    CMCON=7 
    basla:
    LCDOUT $FE,1 
    adcin 4,deneme
    LCDOUT $fe,2,#deneme," "
    pause 3000
    goto basla

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


    Did you find this post helpful? Yes | No

    Default

    try ADCON1=%11100010
    Steve

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

  9. #9
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    i tried this it worked !

    deneme var byte
    ADCON1=0
    trisa.5=1
    CMCON=7
    basla:
    LCDOUT $FE,1
    adcin 4,deneme
    LCDOUT $fe,2,#deneme," "
    pause 3000
    goto basla


    after that i tried this it didnt work
    values is getting smaller now..
    its so weird

    bilgi var byte
    red var byte
    green var byte
    blue var byte
    ADCON1=0
    trisa.5=1
    trisa.1=1
    trisa.2=1
    trisa.3=1
    trisa.0=1
    CMCON=7

    TRISB=0
    PORTB=0
    TRISC=0
    TRISD=0
    LCDOUT $FE,1



    yap:

    high PORTD.7
    PAUSE 750
    ADCIN 5,bilgi
    red=bilgi
    pause 5
    low PORTD.7


    high PORTD.6
    PAUSE 750
    ADCIN 5,bilgi
    blue=bilgi
    pause 5
    low PORTD.6


    high PORTD.5
    PAUSE 750
    ADCIN 5,bilgi
    green=bilgi
    pause 5
    low PORTD.5

    CALL GOSTER


    pause 7000
    goto yap


    GOSTER:
    LCDOUT $fe,2,#red," ",#blue," ",#green," "


    Where am i wrong this final code???

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


    Did you find this post helpful? Yes | No

    Default

    In the first you have ADCIN 4, the second you have ADCIN 5.

    What is your analog source? Any available schematic ?

    You want to use GOSUB instead of CALL. don't forget the RETURN as well.
    Steve

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

  11. #11
    Join Date
    Sep 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    sorry. i put code there imcomplete.there is a "return" at the end.i saw this picture .there is RA5 after RA3.thats why i used porta.5.do you have any idea why did it work with first code and didnt with second???



  12. #12
    Join Date
    Jan 2009
    Location
    Ankara,TURKEY
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    I saw and I experience that my friend's a pin of pic16f877 was not working. Only one pin was not working others are works well may be u should change your pic

    so weird
    Electrical & Electronic Engineering
    Undergraduate Student

  13. #13
    Join Date
    Jan 2009
    Location
    Ankara,TURKEY
    Posts
    45


    Did you find this post helpful? Yes | No

    Question

    when my friend changed his MCU hic circuit worked well.
    I was shocked when I saw it
    Electrical & Electronic Engineering
    Undergraduate Student

Similar Threads

  1. PIC16F877A analog problem
    By DeViLa_Q8 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 30th July 2009, 20:19
  2. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  3. Analog Input on PIC16F88
    By penelopepug in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2008, 22:49
  4. problem with input and output (18F452)
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th March 2008, 23:21
  5. 16C55 Problem.
    By hope_man in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th March 2006, 16:15

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