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

    Default Again ADC with 12F675 ...

    Hi !
    I wote this code for 12F675:
    Code:
    @ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_OFF & _CP_ON 
    
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    CMCON = 7
    OPTION_REG  = %10000110
    TRISIO      = %00001100	  		
    GPIO        = %00000001
    ANSEL       = %00010100   
    ADCON0      = %10001001
    In ISIS I have multiple errors ... what did I do wrong ?
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Hi,
    Is that really ALL of the code?

    When you select an analog input which you want to convert the sample and hold circuit for the ADC needs to charge the S/H capacitor. It takes a certain amount of time (called acquisition time) for this capacitor to charge up. When the the A to D conversion starts the capacitor is disconnected from the input. If the A to D conversion is started before the acquisition time has expired the conversion result will not be correct.

    I'm not sure if perhaps ISIS can, based on the simulation, figure out that the acquisition time isn't long enough. I've never used ISIS (haven't been able to justify the cost) so I don't know.... From the time stamp it looks like you're doing a A to D conversion in a quite tight loop, I don't know if that's a possible problem. It think you're going to have to post more of the code.

    Finally, it's not an error, it's message telling you that it has happend. It doesn't prevent the code form compiling or from running but the behaviour of the code, as written, might not be what you actually wanted.

    /Henrik.

  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 so much for reply !
    The rest of code is :
    Code:
    main:
    pause 200
     ADCON0.1 = 1
     WHILE ADCON0.1 = 1 : WEND
     adval.HighByte = ADRESH
     adval.LowByte = ADRESL
     if k=0 and adval > 10 and adval < 750 then
     k=1
     pause 250
     endif
    
     while k=1
     gosub start
     wend
     goto main
    
    
    start:
    
     ADCON0.1 = 1
     WHILE ADCON0.1 = 1 : WEND
     adval.HighByte = ADRESH
     adval.LowByte = ADRESL
    if adval > 10  AND adval < 103 then gosub VolDn     
    
    return

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Hi,

    >The rest of code is :

    Is it? You're calling VolDn but I don't see that in the code but I guess there's nothing to do with the ADC there?

    Anyway, have you tried using ADCIN just to see if the message from ISIS goes away then?
    I'm asking beacuse the DEFINE ADC_SAMPLUS 50 is for use with the ADCIN command I don't think it does anything for you when you run the ADC "manually". Alternativaly, whenever you're doing a converstion try:
    Code:
    ADCON0 = %10001001    ' Right justify, VRef=Vdd, select AN2, enable ADC.
    PAUSEUS 100     
    ADCON0.1 = 1          ' Start conversion
    WHILE ADCON0.1 = 1 : WEND
    adval.HighByte = ADRESH
    adval.LowByte = ADRESL
    In this case I don't think anything of it really matters since you're always sampling the same channel but it might be worth a try just to see if ISIS stops generating the message.

    Finally, you're doing DEFINE ADC_CLOCK 3 but then you're overriding that by manually setting ANSEL to %00010100 which will set the ADC Clock to FOsc/8 instead of FRC. I don't think that's a problem in this case though.

    /Henrik.

  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 verry much !
    Indeed, my mistake was the overriding of defines ...I didn't know until today the things You've posted. Hm ... so much to learn ! I'm glad I met people like You and other kindly members of this forum !
    Best regards !

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

    Me, again ...with something strange (at least for me) !
    I try to use ADC for reading a couple of buttons. I have two situations :
    - three buttons, with 82 ohms, 164 ohms, 1448 ohms resistors ; ADC reading = 1023 nothing pressed ; 78 with button 1 pressed ; 144 with button 2 ; 605 with button 3 ;
    - three buttons, with 300 ohms, 1300 ohms, 3110 ohms AND 100 Kohms in parallel ; ADC reading = 1013 nothing pressed ; 236 with button 1 pressed; 575 with button 2 ; 768 with button 3.

    I tried with 2 version of code (for both situations):
    Code:
     ADCON0.1 = 1
     WHILE ADCON0.1 = 1 : WEND
     adval.HighByte = ADRESH
     adval.LowByte = ADRESL
    if adval > 10  and adval < 300 then  gosub LED1
    ...etc....
    and

    Code:
    ADCIN 3, adval
    if adval > 10 and adval < 300 then gosub LED1
    ...etc...
    For first situation everything works fine, with both version of reading ADC !
    BUT ... for second situation, NOTHING HAPPENS !!! I really not understand what I do wrong ... Can me point to the right direction ? Thanks in advance !

    Name:  working.jpg
Views: 1863
Size:  98.3 KB Name:  not_working.jpg
Views: 1842
Size:  125.8 KB

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    may be we could suspect the debounce time for your switches ... 50 µs is rather a short time !

    did you try to use a little pause for settling ???

    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 " !!!
    *****************************************

  8. #8
    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 !
    That means to add something like "Pause 50" before or after ADCIN command ?

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Here you can find an example ( in assembler ... YES ! ) that shows how it is done.
    http://www.piclist.com/techref/micro...x4key1ad7r.htm

    did you also read that one ???
    http://www.picbasic.co.uk/forum/showthread.php?t=17956

    Alain
    Last edited by Acetronics2; - 3rd April 2015 at 11:14.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Thanks ! But still no have answers on my problem ...

  11. #11
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Hi Fratello,

    1) Do you have two PCB with different resistor values?
    or
    2) Have you changed resistors to same board and tested with two SW settings?

    In case
    1) there must be some other differences on PCB
    2) resistors are not with correct values

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


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Thanks, Mr. Gusse, for support !
    I have only one PCB, without the resistors from chain (just R2=1k is soldered on PCB, between +5V and ADC_IN).
    I put the resistors from chain 1 from R2/ADC_IN to ground ; in first case works perfect.
    Then I soldered the R9=100k from R2/ADC_IN to ground ; I put resistors from chain 2 into circuit (in parallel with R9). In this case nothing happens.
    All the resistors are measured, look to be OK (this was my first concern too ...).

    Tomorrow I'm going to try to set some debounce ...
    Attached Images Attached Images   
    Last edited by fratello; - 3rd April 2015 at 20:35.

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


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    Update picture...
    Name:  upd.jpg
Views: 1825
Size:  135.4 KB

  14. #14
    Join Date
    May 2009
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Again ADC with 12F675 ...

    I think you may wat to try the following: if (vala >650) and (vala <920) then go sub xx

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