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

    I will try this, thanks !

  2. #2


    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

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

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

  4. #4
    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, 22: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, 20:22
  3. 12f675
    By mystified in forum mel PIC BASIC
    Replies: 6
    Last Post: - 10th September 2007, 02:47
  4. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55
  5. ADC on 12f675?
    By peu in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th March 2005, 17: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