Problem with ADC


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default Problem with ADC

    I have this configuration in my program

    Code:
    ' ******************************** LCD **************************************
    
        DEFINE LCD_DREG PORTB		    'Selection of the port B
        DEFINE LCD_DBIT 4
        DEFINE LCD_RSREG PORTB		    'RS on port RA1
        DEFINE LCD_RSBIT 2
        DEFINE LCD_EREG PORTB		    'E on port RA0
        DEFINE LCD_EBIT 3
        DEFINE LCD_BITS 4		        'Mode 4 bits
        DEFINE LCD_LINES 4		        'LCD 4 lines of 16 caracter
        
    	PAUSE 500
    
    ' 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
    	
        INCLUDE "LCDbar_INC.bas"        'Include the BARgraph routines
    		
        CMCON = 7                       'PortA = digital I/O    
    	ANSEL = %00000111               'Will set RA2 as analog and all others as digital
    and this asm: (is for frequency meter)

    Code:
    Asm
    	movlw   0x10	       ;PORTA 4 in entry
    	movwf   0x5
    	MOVLW	0x37
            option      	   ;charge 00110111 in the register option
    	MOVLW	0x10		   ;init freq with RA4 in entry
    	MOVWF	_trisabuf
    EndAsm
    and this asm: (is for frequency meter)

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    AUTHORIZATION OF COUNTING
    
    	       clrf    TMR0		        ; RAZ timer
    	       bsf	    _trisabuf,3	    ; RA4 in entry and RA3 in entry authorization counting
    	       movf 	_trisabuf,W
    	       tris	   PORTA
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    BASE TIME  
          
    	       movf	   _TEMPS,W
               movwf   _COUNT1
    dxxx	   nop
    	       decfsz  _COUNT1
    	       GoTo	dxxx
    	       nop
    	       nop
    	       Call delay
    	       Call delay
    	       Call delay
    	       Call delay
    	       Call delay
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      STOP OF COUNTING
    
    	       bcf     _trisabuf,3	 ;RA4 in entry and RA3 at Exit to block counting
    	       movf    _trisabuf,W         
    	       tris    PORTA
    My problem is the pot not adjust the volt. Show on lcd only if it is full. If i turn litle the pot the volt go to 0volt on lcd.
    If i remove the two code : tris PORTA on asm code at the end of code the pot adjust linear, but the frequency meter
    is not show properly.
    In the image the resistor is 47omh and the pot 47kohm
    Attached Images Attached Images  
    Last edited by savnik; - 22nd November 2006 at 12:37.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Part of your problem ....

    you need TRISA.1 = 1 (RA1 = input) somewhere before doing your ADC.

    Your ASM routines clear this bit, making it an output. Do you set it elsewhere before sampling?

    Also, why the ASM? Everything you show is easy in PBP?

    (side note - OPTION and TRIS are going away .. avoid them – see datasheet)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default problem solved

    Thank you very much.
    I put TRISA.0 = 1 before ADC and it's work.

  4. #4
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    Also, why the ASM? Everything you show is easy in PBP?
    How change the code from asm to PBP

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    For the first block of ASM, replace with

    PORTA = $10
    TRISABUF=$10
    OPTION_REG=$37

    You need to post the rest of your ASM code in order for us to see how to completely convert the second block (.i.e, where is your delay routine?)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    For the first block of ASM, replace with

    PORTA = $10
    TRISABUF=$10
    OPTION_REG=$37

    You need to post the rest of your ASM code in order for us to see how to completely convert the second block (.i.e, where is your delay routine?)
    Code:
        FHI		    VAR BYTE
        FLO		    VAR BYTE
        COUNT1		VAR BYTE
        TRISABUF	VAR BYTE
        TEMPS		VAR BYTE
    All the ASM code

    Code:
    Asm
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    AUTHORIZATION OF COUNTING
    
    	clrf	TMR0		        ; RAZ timer
    	bsf	_trisabuf,3		        ; RA4 in entry and RA3 in entry authorization counting
    	movf 	_trisabuf,W
    	tris	PORTA
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    BASE TIME  
          
    	movf	_TEMPS,W
            movwf	_COUNT1
    dxxx	nop
    	decfsz	_COUNT1
    	GoTo	dxxx
    	nop
    	nop
    	Call delay
    	Call delay
    	Call delay
    	Call delay
    	Call delay
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      STOP OF COUNTING
    
    	bcf	_trisabuf,3		        ;RA4 in entry and RA3 at Exit to block counting
    	movf 	_trisabuf,W         
    	tris	PORTA
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      RECUPERATION OF THE METERS
      
    calcul	MOVF    TMR0,W		    ;timer   -> work
    	MOVWF   _FHI	       	    ;work -> FHI	8 bits of weight strong counting
    	clrf	_COUNT1		        ;handing-over has zero meter
    Toggle	incf	_COUNT1,F	    ;incrementation of the meter
    	bsf	PORTA,3		            ;RA3 a 1
    	bcf	PORTA,3		            ;RA3 a 0
    	movf	TMR0,W		        ;reading of the timer
    	subwf	_FHI,w		        ;it is looked at if the divider incremente the timer
    	btfsc	STATUS,2		    ;comparison
    	GoTo	Toggle		        ;if the timer did not incremente one starts again
    	comf	_COUNT1,F	        ;complement with the meter
    	incf	_COUNT1,W	        ;incrementation of the meter
    	movwf	_FLO		        ;work -> FLO 	8 bits of weight weak counting
    	GoTo fin
    	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;     BASE TIME 
      
    delay   	movlw	197         ;1ms according to AN592
    	movwf	_COUNT1          	
    	nop                     		
    	GoTo	$+1              		
    	GoTo	$+1             		
    dly	GoTo	$+1              		
    	decfsz	_COUNT1         	
    	GoTo	dly             		
    	Return		            	
    fin
    EndAsm
    Last edited by savnik; - 22nd November 2006 at 21:35.

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


    Did you find this post helpful? Yes | No

    Default

    Save us to guess what you want to do... AND give us your PIC model.

    There's only few hundreds of model.. but who want to guess?
    Last edited by mister_e; - 22nd November 2006 at 22:54.
    Steve

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

  8. #8
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Save us to guess what you want to do... AND give us your PIC model.

    There's only few hundreds of model.. but who want to guess?
    My problem solved by paul borgmeier.
    My pic is 16f88.

  9. #9
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    His schematic shows a F88 but he fixed his code by adding TRISA.0 = 1 (pot on RA1 not RA0) - does not make sense??

    Try this for the second block of ASM code

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    AUTHORIZATION OF COUNTING
    TMR0 = 0
    TRISABUF.3 = 1
    PORTA = TRISABUF
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    BASE TIME  
    COUNT1=TEMPS
    PAUSEUS (COUNT*4+2)
    PAUSE 5
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      STOP OF COUNTING
    TRISABUF.3=0
    PORTA=TRISABUF
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      RECUPERATION OF THE METERS
    FHI=TMR0
    COUNT1=0
    Toggle:
    COUNT1=COUNT1+1
    PORTA.3=1
    PORTA.3=0
    IF (FHI-TMR0) = 0 THEN Toggle
    COUNT1=(COUNT1^$FF)
    FLO=COUNT1+1	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;     BASE TIME
    Any second opinions on the conversion?

    Savnik, what does your program do?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  10. #10
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    His schematic shows a F88 but he fixed his code by adding TRISA.0 = 1 (pot on RA1 not RA0) - does not make sense??

    Try this for the second block of ASM code

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    AUTHORIZATION OF COUNTING
    TMR0 = 0
    TRISABUF.3 = 1
    PORTA = TRISABUF
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;    BASE TIME  
    COUNT1=TEMPS
    PAUSEUS (COUNT*4+2)
    PAUSE 5
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      STOP OF COUNTING
    TRISABUF.3=0
    PORTA=TRISABUF
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;      RECUPERATION OF THE METERS
    FHI=TMR0
    COUNT1=0
    Toggle:
    COUNT1=COUNT1+1
    PORTA.3=1
    PORTA.3=0
    IF (FHI-TMR0) = 0 THEN Toggle
    COUNT1=(COUNT1^$FF)
    FLO=COUNT1+1	
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;     BASE TIME
    Any second opinions on the conversion?

    Savnik, what does your program do?
    Sorry ,the pot is on RA0 (the schematic is wrong)

    With the first block of asm the frequency meter work.

    When i change the second asm with yours code i take error when compile.
    When I change the PAUSEUS (COUNT*4+2) with PAUSEUS (COUNT1*4+2) and the Toggle with Toggle1 the code compile , but the frequency on LCD is above 14Mhz the regular (90.6Mhz -> 104.6Mhz)

  11. #11
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Now that it is not 2Am, I see that it might be the PAUSEUS line - PAUSEUS has a minimum delay of 24uS when used with a 4 MHz XTAL. I also took "your" comments about the delay loop as being accurate at 1 mS. I will check that as well.

    What XTAL speed are you running?

    Unfortuantely, it is "Off to Grandma's House" here as it is a major holiday. I will not have a minute to debug until tomorrow night (36 hours from now). As asked before,

    Anyone else have an opinion on the ASM to BASIC conversion or want to take a stab at the problem? If not, I will revisit when I return.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  12. #12
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    What XTAL speed are you running?
    I use 4MHZ xtal.

  13. #13
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Also, why the ASM? Everything you show is easy in PBP?
    I guess I lied - I do not see an easy solution to the minimum PAUSEUS problem noted above - I am glad it works for you with the ASM blocks.
    Good Luck,
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  14. #14
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik
    Thank you very much.
    I put TRISA.0 = 1 before ADC and it's work.
    Thank you again because you solve my problem with ADC.
    For the ASM never mind.

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 : 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