ADC problem :(


Closed Thread
Results 1 to 12 of 12

Thread: ADC problem :(

  1. #1
    Join Date
    Sep 2007
    Posts
    14

    Default ADC problem :(

    Hi again every one :P
    I have a problem i want the LCD to show 0 to 255 and not 255 to 0. In other words when the pot is on left side ( lowest ohm) it will show 0 on lcd and when its on highest it show 255 on screen. Right now it do the other way.
    Here is the code any suggestions?

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 2007-11-30                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    Define	LOADER_USED	1
    
    
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    
    ' Define ADCIN parameters
    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
    ad1	var	byte	
    ad2 var	byte	    ' Create adval to store result
    ad3	var	byte
    ad4 Var Byte
       TRISA = :%11111111	' Set PORTA to all input
       ADCON1 = %00000010	' Set PORTA analog
       Low PORTE.2		    ' LCD R/W line low (W)
       'Pause 500		    ' Wait .5 second
           
    main:	
       ADCIN 0, ad1		        ' Read channel 0 to adval
       ADCIN 1, ad2		        ' Read channel 1 to adval
       ADCIN 3, ad3 	        ' Read channel 3 to adval
       PWM portc.4 ,ad1,1' Send a 50% duty cycle PWM signal out Pin7 for 100 cycles
       PWM portc.5 ,ad2,1' Send a 50% duty cycle PWM signal out Pin7 for 100 cycles
       LCDout $fe, 1 
       LCDOUT "nacke:", #ad1
       LCDOUT $FE, $C0, "rygg:", #ad2
    
    
    
    
    
    
    Symbol delay = ad4  ' use b0 as the delay variable 
    delay = ad2         ' set the delay to 25 ms 
    
    loop: high portD.0              ' turn on Q1 
          pause ad4         ' wait 25 ms        
          low portD.0               ' turn off Q1 
          high portD.1              ' turn on Q2 
          pause ad4         ' wait 25 ms 
          low portD.1               ' turn off Q2 
          high portD.2              ' turn on Q3 
          pause ad4         ' wait 25 ms 
          low portD.2               ' turn off Q3 
          high portD.3              ' turn on Q4 
          pause ad4         ' wait 25 ms 
          low portD.3               ' turn off Q4 
     
       Goto    main        ' Do it forever
       
            End
    
    	End

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Kaldurenik, If all you want to do is reverse the way it is displayed then just say:
    LCDOUT "nacke:", #(~ad1)

    As long as ad1 is a byte variable it will work.

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Sep 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    ok thanks i will try it in a moment and post a update then.

  4. #4
    Join Date
    Sep 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    nope that did not work now when i change the pot left or right it dont work and! i get 65280 on the screen instead...

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


    Did you find this post helpful? Yes | No

    Default

    ad1=255-ad1
    Steve

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

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Question the "hard" solution ...

    May be I'm simple minded ...

    but crossing the 2 extreme taps wires of the pot might solve the problem ... as it seems Vref is 5v ...

    Did I miss something ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    yup, as long the OP didn't asked for a software solution and can do some hardware mods, unless you can't be wrong.

    PS: 30cm de neige ici aujourd'hui
    Steve

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

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking I was waiting for you ...

    Hi, Steve

    For once, you have the "soft" solution ... keep on that way ....( no more guns, ... etc,etc )

    Lots of LOL from le " maudit Français"

    Ici, c'est Water: l'eau ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Sep 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    well ad1 = 255 - ad1 make the pot "freeze" (not change number)
    Any way we will try that the solution you posted before did work with the ~ but it increased to 1111111111111111 in bin. :O in other word 655xx or something like that.

  10. #10
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Kaldurenik, I don't know how that can be? You have ad1,ad2,ad3,ad4 declared as byte variables unless you have changed them..... Using ad1 = ~ad1 if the variable is a byte should work.

    Dave Purola,
    N8NTA

  11. #11
    Join Date
    Sep 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Okey the code look like this now:

    Code:
    Define	LOADER_USED	1
    
    
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        8
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    
    ' Define ADCIN parameters
    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
    ad1	var	BYTE	
    ad2 var	BYTE	    ' Create adval to store result
    ad3	var	BYTE
    ad4 Var BYTE
       TRISA = %11111111	' Set PORTA to all input
       ADCON1 = %00000010	' Set PORTA analog
       Low PORTE.2		    ' LCD R/W line low (W)
       'Pause 500		    ' Wait .5 second
     
    main:	
       ADCIN 0, ad1		        ' Read channel 0 to adval
       ADCIN 1, ad2		        ' Read channel 1 to adval
      ' ADCIN 3, ad3 	        ' Read channel 3 to adval
        
       PWM portc.4 ,ad1,1' Send a 50% duty cycle PWM signal out Pin7 for 100 cycles
       ad1 = ~ad1
    ad2 = ~ad2  
       LCDout $fe, 1
       LCDOUT "nacke:", #ad1
       LCDOUT $FE, $C0, "rygg:", #ad2
       ad4 = ad2
    
    
    
    
    
    
    Symbol delay = ad4  ' use b0 as the delay variable 
     
    
    loop: high portD.0              ' turn on Q1 
          pause ad4         ' wait 25 ms        
          low portD.0               ' turn off Q1 
          high portD.1              ' turn on Q2 
          pause ad4         ' wait 25 ms 
          low portD.1               ' turn off Q2 
          high portD.2              ' turn on Q3 
          pause ad4         ' wait 25 ms 
          low portD.2               ' turn off Q3 
          high portD.3              ' turn on Q4 
          pause ad4         ' wait 25 ms 
          low portD.3               ' turn off Q4 
     
       Goto    main        ' Do it forever
       
            End
    
    	End
    The problem is that its "slow" to update on the screen now. its no "smooth" jumps its like 5-15-70-100
    (its 0 to 255)
    ofc its all about how fast i move it.
    but maybe the fastest way is just to turn it around ye?

  12. #12
    Join Date
    Sep 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Ok i solved it thanks every one! The
    ad1 = ~ad1
    ad2 = ~ad2
    helped alot

    Thanks again!

Similar Threads

  1. pic12f675 ADC problem
    By radu022003 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 1st September 2009, 10:13
  2. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  3. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  4. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  5. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46

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