Stable ADC readings


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Hello,
    i made this to programm ADC

    bmf_comm1 VAR PORTB.0
    bmf_comm2 VAR PORTB.1
    'Variables
    bmfsD VAR WORD
    bmfs1D VAR WORD
    iled var byte
    blink1 var byte 'pour clignotement 1ère led
    blink2 var byte 'pour clignotement 2ème led
    'configuration du port pour lire l'entrée analogique
    TRISA = %00000011 ' RA0 et RA1 en entrée
    TRISB = %11111100 ' RB0 et RB1 en sortie
    ADCON1 = $10000010 'RA0 à RA3

    test_depart:
    Low bmf_comm1
    Low bmf_comm2
    High bmf_comm1
    high bmf_comm2
    pause 2000
    goto mainloop
    'lecture de la valeur
    getad:
    PAUSEUS 50 ' Wait for A/D channel acquisition time
    ADCON0.2 = 1 ' Start conversion
    WHILE ADCON0.2 ' Wait for it to complete
    WEND
    Return

    ' Subroutine to get pot x value
    getx:
    ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
    Gosub getad
    bmfsD = ADRESL + (ADRESH*256)
    Return

    ' Subroutine to get pot y value
    gety:
    ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
    Gosub getad
    bmfs1D = (ADRESH*256) + ADRESL
    Return
    val_leds:
    low bmfs_comm1
    low bmfs_comm2
    gosub getx
    gosub gety

    if (bmfsD > 1000) Then Goto val_leds
    if (bmfsD > 750) Then Goto boucle_led
    if (bmfsD > 500) Then Goto boucle1_led
    if (bmfsD > 250) Then Goto boucle2_led

    High bmf_comm1
    High bmf_comm2
    pause 1500
    goto val_leds
    boucle_led:
    iled = 0
    while iled < 5
    if iled = 1 or 3 or 5 then high blink1:low blink2
    if iled = 0 or 2 or 4 then low blink1:high blink2
    iled = iled + 1
    pause 1000
    wend
    goto val_leds
    boucle1_led:
    High bmf_comm1
    low bmf_comm2
    pause 3000
    goto val_leds
    boucle2_led:
    low bmf_comm1
    high bmf_comm2
    Goto val_leds
    End

    The leds works but always lightning , action on button (RB0 only for the moment) don't change anything.
    No blinking .
    I don't know what .
    thanks.

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Salut et Bienvenue sur le forum

    I haven't check the whole thing in deep but I think you should modify the boucle_led section to
    Code:
    boucle_led:
            iled = 0
            while iled < 5
                    if iled = 1 or 3 or 5 then 
                            high blink1
                            low blink2     
                            endif
                            
                    if iled = 0 or 2 or 4 then 
                            low blink1
                            high blink2
                            endif
                    iled = iled + 1
                    pause 1000
                    wend
            goto val_leds
    Probably it will solve your problem though... let me know the PIC you're using and your PBP version.

    EDIT: Your code have 2 compilation error
    1) no mainloop label
    2) adcon1: the way you have written it, it's value should start with a % instead of a $
    Last edited by mister_e; - 24th August 2011 at 20:07.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Looking at your code, I guess it's your first program, There's quite a few mistakes in and it is also hard to follow what you want to do.

    No problem, been there...done that. Tell us what you want to do and we could build something to help you to get started.

    Tell us the PIC your're using and post your schematic if you have any, or describe it.
    Steve

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

  4. #4
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Sorry for double post but i tried many many modifications.
    my pic is 16F877A , i desire to put multifunctions buttons of steering wheel and decode for command radio car system .
    i make a test with leds for ADC value input .
    Oh,oh,oh,
    i have just see that i don't put MCLR to any connection , a resistor of 4.7kohms to +5V ?

    It is a very simple schematic for test but the entire schematic is for steering wheel command and FIS Tachometer car display modification in live .
    example : see the kwp1281 protocol codes of line K (not can bus) like VCDS soft but more simple.

    This is the first part ( BMF )

    For mainloop , it is because i modify the labels and i forgot it (val_leds) .
    For $ , it is a mistake , THANKS.
    i will try now

    Regards
    Last edited by mazoul72; - 24th August 2011 at 22:42.

  5. #5
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    my leds light off after 2 sec , it is ok for starting (mainloop replaced by val_leds)
    But after i have only two leds lightning together , it is not good with all boutons
    and i have no blinking leds

    And now i have no actions on leds (off always) , i don 't undertand why , AD not stable or other....
    it is the same with or without MCLR .

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Ah ok I see, you read a voltage then act upon. Cool, I did something like that awhile back but it was for car remote starter purpose (Door lock, alarm bypass, Windows roll-up/down) Oh well, those were the days

    Yes MCLR must be tied to Vdd. 4.7K is fine.

    not sure of what you want to do and how it should flash your LEDs but try this one
    Code:
            bmf_comm1   VAR PORTB.0
            bmf_comm2   VAR PORTB.1
            
            LEDBlinkRate CON 200
            
            'Variables
            bmfsD       VAR WORD
            bmfs1D      VAR WORD
            iled        var byte
            
            'configuration du port pour lire l'entrée analogique
            TRISA = %00000011       ' RA0 et RA1 en entrée
            TRISB = %11111100       ' RB0 et RB1 en sortie
           
            DEFINE ADC_BITS 10      ' Set number of bits in result
            DEFINE ADC_CLOCK 3      ' Set clock source (rc = 3)
            DEFINE ADC_SAMPLEUS 50  ' Set sampling time in 
            ADCON1 = %10000010      ' RA0 à RA3
    
    test_depart:
            PORTB = 3               ' Turn ON PORTB<1:0>
            pause LEDBlinkRate      '  
           
    val_leds:
            PORTB = 0               ' Turn OFF PORTB<1:0>
            PAUSE LEDBlinkRate        
            ADCIN 0,BMFSd           ' Read CH0
            ADCIN 1,BMFS1d          ' Read CH1
            if (bmfsD > 1000) Then val_leds
            if (bmfsD > 750)  Then boucle_led
            if (bmfsD > 500)  Then boucle1_led
            if (bmfsD > 250)  Then boucle2_led
            
            goto test_depart
            
    boucle_led:
            PORTB = 1
            for ILED = 0 to 5
                    PORTB = PORTB ^ 3
                    PAUSE LEDBlinkRate
                    NEXT
            goto val_leds
            
    boucle1_led:
            High bmf_comm1
            pause LEDBlinkRate
            goto val_leds
            
    boucle2_led:
            high bmf_comm2
            PAUSE LEDBlinkRate
            Goto val_leds
            End
    seems to work for me here, 4MHz oscillator, some different led blinking opattern depending of the value of AN0.
    Last edited by mister_e; - 24th August 2011 at 23:54.
    Steve

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

  7. #7
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Hello,

    it still doesn't work ....I don't understand why .
    The leds are still off whenever i select any buttons .
    I see 3.96 V between middle point of my buttons and external pull up resistors (on RA0 and RA1) .
    When i push buttons , i have 1.44V / 0.80 V / 0.40 V .
    Whith quantum 4.88xxx mV , it gives to me 295 , 164 , 82 .
    For 3.96V , 811 aproximatively .

    LED replace resistors out (to test)

    Name:  bmf.JPG
Views: 4740
Size:  31.4 KB

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Simple, there's no voltage in there as it is right now. You'll need to modify the circuit to add some voltage there. The pull-up thing should work.

    Do yourself a big favor, output the value of the ADC reading to a LCD or to your computer, push on a single button, note the value and modify the IF-THEN value in the code.

    What are your pull-up value?
    Steve

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

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    On F877 or F877A there are NO pull-ups on port A. Only on Port B.

    Ioannis

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