​ ​ ​ ​ Really strange READADC10 Behavior
Results 1 to 4 of 4

Thread: Really strange READADC10 Behavior

  1. #1
    Senior Member
    Join Date
    May 2013
    Location
    Ireland
    Posts
    265

    Default Really strange READADC10 Behavior

    Hello everyone.

    I have been working on a project which is almost completed now.

    However, i have came across an issue that i am not able to resolve after many days of troubleshooting.

    The project is build on 14M2 chip with AD623 INAMP and a half bridge load cell.

    Within the MAIN program loop i am continuously monitoring ADC on PIN C.4

    When a certain threshold is met the program jumps to FIRE subprogram.

    It turns a couple of things ON and OFF and then program continues to another subprogram called WAITQS1.

    The WAITQS1 subprogram start by reading ADC value on the same pin C.4.

    Then this value is being compared to another value.

    The really strange thing is, READADC10 within the MAIN program and READADC10 within the WAITQS1 subprogram read different value even though the weight n the load cell is remaining the same.

    I have been doing some testing and looking at the ADC values from both MAIN and Subprogram and the ADC value from the Subprogram is always returning around 200 more.

    So if ADC reading from the MAIN program is 550, straight after the ADC reading from WAITQS1 subprogram will return 700-750 value.

    So if the pressure is still being applied on the load cell and ADC reading is below 500 then the program should just loop within WAITQS1, but for some reason ADC reurns value greater then 500 and the program returns to the MAIN, then the main loop reads the ADC to be below 600 and the program goes to FIRE and then WAITQS1 and then ADC within WAITQS1 reads a high value and the circle continuities.

    Any idea what might be causing that?

    Why ADC reading from two different routines would return different value when the input to ADC remains constant.

    I have literally tried everything i could.

    Thanks very much in advance.,

    Code:
    ;Program rev.1.3; Date 16-Nov-2017
    ;PICAXE14M2
    
    #picaxe 14m2
    setfreq m8 ` Running at 8Mhz, all pause values are x2 times
    symbol greenled=B.1 	`GREEN LED
    symbol redled=B.2		'RED LED
    symbol RELAY1=C.0
    symbol RELAY2=C.1			
    symbol old_adc=w3
    symbol new_adc=w9
    
    
    main:		high greenled
    		low redled
    		readadc10 C.4,new_adc		'w4-b8/b9 - strain gauge running
    		sertxd("NEW_ADC reading at MAIN is ",#new_adc,13,10)
    	
    	
    	#terminal 9600
    		if new_adc<600 then gosub fire
    		
    		
    		
      	
    goto main
    
    
    
    fire: 	high relay1
    		high relay2
    		high redled
    		low greenled
    		pause 200
    		low relay1
    		low redled
    		pause 40
    		low relay2
    		
    			
    
    waitqs1: 	readadc10 C.4, new_adc
    
    		sertxd("NEW_ADC reading at waitqs  is ",#new_adc,13,10)
    			
    		select case new_adc
    			case < 500 goto waitqs1
    					
    		endselect
    		
    
    return

  2. #2
    Senior Member
    Join Date
    May 2013
    Location
    Ireland
    Posts
    265

    Default

    Image showing two different ADC readings, one from the MAIN program and one from WAITQS1 subprogram.
    The load on the loadcell remained untouched.

    READADC Issue.JPG

  3. #3
    Senior Member
    Join Date
    Jan 1970
    Location
    Perth, Western Australia
    Posts
    4,466

    Default

    I have only had a very quick look at your code.

    It is not a good idea to do an ADC reading immediately after releasing a relay. The supply rail is likely to jump about (or only twitch about) with the back-emf being dumped by the relay's coil. The impulse on the supply rail may not be enough to reset the PIC but it will affect the PIC's reference point for its ADC readings. Remember that ReadADC10 is trying to read a voltage to about 0.2%.

  4. #4
    Senior Member
    Join Date
    May 2013
    Location
    Ireland
    Posts
    265

    Default

    Quote Originally Posted by inglewoodpete View Post
    I have only had a very quick look at your code.

    It is not a good idea to do an ADC reading immediately after releasing a relay. The supply rail is likely to jump about (or only twitch about) with the back-emf being dumped by the relay's coil. The impulse on the supply rail may not be enough to reset the PIC but it will affect the PIC's reference point for its ADC readings. Remember that ReadADC10 is trying to read a voltage to about 0.2%.
    You are an absolute genius Pete.

    Problem solved.

    Working as expected now.

    Dont know how i missed that.

    Thanks very much again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •