Again ADC with 12F675 ...


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    ...so I'm back !
    After solving first problem, I meet another one ... I can not reading two channel ADC.
    I try two version of code :
    -first variant
    Code:
    @ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_ON & _CP_ON 
    DEFINE OSC  4
       
    
    CMCON       = 7
    OPTION_REG.7= 1 
    TRISIO      = %00001110	  	
    GPIO        = %00000001
    ANSEL       = %00110110 
    ADCON0.7    = 1
    
    adval  var word
    advalb var word
    
    PAUSE 200
    
    main:
    
     ADCON0.2 = 1 
     ADCON0.3 = 0      
     ADCON0.1 = 1
     WHILE ADCON0.1 = 1 : WEND
     adval.HighByte = ADRESH
     adval.LowByte = ADRESL
     PAUSE 50
    
    if adval < 950 then
    	if adval < 940 AND adval > 650 THEN gosub Led1
    	IF adval < 600 AND adval > 450 THEN gosub Led2  
    	IF adval < 400 AND adval > 150 THEN gosub Led3
    	IF adval < 100 THEN gosub Led4                   
    endif
    
     ADCON0.2 = 0
     ADCON0.3 = 1
     ADCON0.1 = 1
     WHILE ADCON0.1 = 1 : WEND
     adval.HighByte = ADRESH
     adval.LowByte = ADRESL
     PAUSE 50
    
    if advalb < 950 then
    	if advalb < 940 AND advalb > 650 THEN gosub Led1
    	IF advalb < 600 AND advalb > 450 THEN gosub Led2   
    	IF advalb < 400 AND advalb > 150 THEN gosub Led3
    	IF advalb < 100 THEN gosub Led4                 
    endif
    
    goto main
    -second variant
    Code:
    @ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_ON & _CP_ON 
    
    DEFINE OSC  4
    
    DEFINE ADC_BITS     10          
    DEFINE ADC_CLOCK    3
    DEFINE ADC_SAMPLEUS 200      
    
    CMCON = 7
    OPTION_REG  = %10000110
    TRISIO      = %00000110	  	
    GPIO        = %00000110
    ANSEL = %00000110
    ADCON0.7    = 1  
    
    
    
    ADVALA  VAR WORD
    ADVALB  VAR WORD
    
    pAUSE 100
    
    main:
    
    adcin 1, advalA
    pause 5
    if advalA < 950 then
    	if advaLA < 940 AND advalA > 650 THEN gosub LED1
    	IF advalA < 600 AND advalA > 450 THEN gosub LED2     
    	IF advalA < 400 AND advalA > 150 THEN gosub LED3     
    	IF advalA < 100 THEN gosub LED4                   
    endif
    
    adcin 2, advalB
    pause 5
    if advalB < 950 then 
     	if advalB < 940 AND advalB > 655 THEN gosub LED1 
    	IF advalB < 600 AND advalB > 450 THEN gosub LED2   
    	IF advalB < 400 AND advalB > 150 THEN gosub LED3   
    	IF advalB < 100 THEN gosub LED4  
    endif                  
                   
    
    goto main
    ONLY "advalA < 100" is sensing and LED4 command is executed ...
    Can somebody pointing to the right direction ? Thanks in advance !
    Schematic added.
    Name:  ADC_double.jpg
Views: 2154
Size:  139.1 KB

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    A couple of suggestions second variant.
    Remove "GPIO = %00000110" you are trying to set a high on the input pins.
    Change "ANSEL = %00000110" to "%01110110", this will set the PIC ADC clock to RC mode and will match the
    "DEFINE ADC_CLOCK 3" directive.

    Then give Variant 2 a try.
    Regards,
    TABSoft

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    I will try this, thanks !

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Hi Fratello. A while back I did the same basic thing you're doing. On an ADC pin I attached a 47K pullup resistor. Then a 22K resistor with pushbutton to ground, 10K with button to ground, 2.2K with button to ground and a 1K with button to ground. Here is the code. It works perfect for me.

    ANSEL = 0 'all inputs digital
    CMCON = 7 'comparators off
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device to accurize osc
    TRISIO = %11111111 'SET I/O'S to all inputs for now
    @ device pic12F675, INTRC_OSC_NOCLKOUT, wdt_on, BOD_ON,pwrt_on, mclr_off, protect_on
    BUT VAR BYTE 'BUTTON VARIABLE
    BUT2 VAR BYTE 'VARIABLE TO COMPARE READINGS TO PREVENT WRONG ADC READINGS
    Pause 500 'SETTLE DOWN

    STAYHERE:
    ADCIN 3,BUT 'ADCIN COMMAND AUTOMATICALLY CONVERTS I/O TO ADC PORT
    IF BUT < 100 Then STAYHERE 'IF BUTTON STUCK on power up WAIT HERE

    BEGIN:
    NAP 0 'REDUCE BATTERY DRAIN
    ADCIN 3,BUT
    IF BUT > 100 Then begin 'BUTTON not PUSHED

    table:
    ADCIN 3,BUT
    Pause 100
    ADCIN 3,BUT2
    IF BUT <> BUT2 Then TABLE 'RE-READ ADC should both be same

    IF BUT < 91 AND BUT > 71 Then (DO FUNCTION 1)
    IF BUT < 50 AND BUT > 40 Then (DO FUNCTION 2)
    IF BUT < 15 AND BUT > 8 Then (DO FUNCTION 3)
    IF BUT < 8 AND BUT > 4 Then (DO FUNCTION 4)
    IF BUT < 5 AND BUT > 2 Then (DO FUNCTION 5) '1K & 2.2K BUTTON PUSHED @ SAME TIME
    GOTO BEGIN

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Thank you !
    As I say, with just one resistors chain , everything works PERFECT !
    My troubles appears when I try to use TWO resistors chains (and TWO ADC channel).
    I wrote another version :
    Code:
    @ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_ON & _CP_ON 
    
    DEFINE OSC  4
    
    DEFINE ADC_BITS     10          
    DEFINE ADC_CLOCK    3
    DEFINE ADC_SAMPLEUS 100      
    
    
    
    CMCON = 7
    OPTION_REG.7= 1
    TRISIO      = %00000110	 		
    GPIO        = %00000001
    ANSEL       = %00110110
    ADCON0.7    = 1
    
    adval   var word
    valb    var word
    vala    var word
    
    PAUSE 200
    
    goto mainloop
    
    getadv:
            PAUSEuS 50                      	' Wait for A/D channel acquisition time
            ADCON0.1 = 1
            WHILE ADCON0.1 = 1 : WEND
            adval.HighByte = ADRESH
            adval.LowByte = ADRESL
    Return
    
    getadvala:
            ADCON0 = %10000101             		
            Gosub getadv
            vala=adval
    Return
    
    getadvalb:
            ADCON0 = %10001001            		
            Gosub getadv
            valb=adval
    Return
    
    mainloop:
    gosub getadvala
    gosub getadvalb
    
    
    if vala < 950 then
    	if vala < 940 AND vala > 650 THEN gosub LED1
    	IF vala < 600 AND vala > 450 THEN gosub LED2      
    	IF vala < 400 AND vala > 150 THEN gosub LED3     
    	IF vala < 100 THEN gosub LED4                  
    endif
    
    if valb < 950 then
    	if valb < 940 AND valb > 650 THEN gosub LED1
    	IF valb < 600 AND valb > 450 THEN gosub LED2
    	IF valb < 400 AND valb > 150 THEN gosub LED3 
    	IF valb < 100 THEN gosub LED4                   
    endif
    
    goto mainloop
    But still no have proper results ...

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    My schematic/code are from here : http://www.imdb.com/title/tt0052520/ !!!
    I did it work ... by re-reversing all those commands :
    " If VALA > 650 and VALA < 940 Then Gosub LED1"" ...
    instead of :
    " If VALA < 940 and VALA > 650 Then Gosub LED1"

    Nothing else ! And now everything works just fine !
    Thank you all for support !
    Have a Nice and Happy Easter !

Similar Threads

  1. ADC values above 4095 for 12 bit ADC
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st February 2015, 23:24
  2. ADC problem on 18F46K22 device using all 28 ADC pins
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd February 2012, 21:22
  3. 12f675
    By mystified in forum mel PIC BASIC
    Replies: 6
    Last Post: - 10th September 2007, 03:47
  4. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 02:55
  5. ADC on 12f675?
    By peu in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th March 2005, 18:44

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