ADC in 12F683; puzzled


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2010
    Posts
    25

    Question ADC in 12F683; puzzled

    I have started my second project, which is a temperature regulator.
    My first project used one ADC channel, but I only used it as 8 bit ADC.
    This time I thought that I needed 10 bits and specified that in the set up...

    To test the first mock up, I set up a trip point of 512, which should be 2,5V.
    -But it's not. By trying different numbers, I came to the conclusion that the ADC gives 13300 per Volt!??
    What's up here? I'm totally lost!

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,616


    Did you find this post helpful? Yes | No

    Default

    Hi, Mike

    How do you want us to give you any idea ???

    PLEASE ...

    Your program With the Config Header ... as always !!!

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

  3. #3
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Your program With the Config Header ... as always !!!

    Alain
    Right, of cource...

    Code:
     
    'Define ADCIN parameters
    ANSEL = %00000011 'GP0 = AN0, GP1 = AN1
     
    DEFINE ADC_BITS 10 'Set number of bits in result
    DEFINE ADC_CLOCK 3 'Set clock source
    DEFINE ADC_SAMPLEUS 50 'Set sampling time in us
     
    time1 VAR WORD 'First time in seconds
    time2 VAR WORD 'Second time in seconds
    time3 VAR WORD 'Third time in seconds
    involt1 VAR word 'Value for ADC0 (temp)
    involt2 VAR word 'Value for ADC1 (adjust)
    ut4 var bit 'Status for LED 4
    ut5 var bit 'Status for LED 5
    trip1 var word 
    trip1 = 13300 'Default value
    trip2 var word 
    trip2 = 13300 'Default value
     
    TRISIO = %11001011 'Defining PORT
    GPIO = %00111000 'Turn off all LEDs
    time1 = 0 'Zero time 1
    time2 = 0 'Zero time 2
    time3 = 0 'Zero time 3
    ut4 = 1 'LED 4 = off (inversed)
    ut5 = 1 'LED 5 = off (inversed)
     
    loop1: 
    ADCIN 0, involt1 'Read channel 0 to involt1
    ADCIN 1, involt2 'Read channel 0 to involt2
    pause 100 'Wait 100 ms
    IF involt1 >= trip1 THEN 
    GPIO.4 = 0 'Turn on LED4
    else
    GPIO.4 = 1 'Turn off LED4
    endif
    IF involt2 >= trip2 THEN 
    GPIO.5 = 0 'Turn on LED5 
    else
    GPIO.5 = 1 'Turn off LED5
    endif 
    goto loop1 'Go back to loop1
    END
    trip1 = 13300 gives exactly 1V trip level. I don't mind having this kind of resolution, but it doesn't seem realistic.
    Last edited by Acetronics2; - 21st September 2010 at 13:20.

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Just guessing with your code, It looks like your result is left justified (or right) but in any event, you appear to be reading the the 2 LSB as bit 6,7 of your answer. since the 10 bit result is a word, you seem to have result high as valid 8 bits. but your result low is ddxxxxxx. So your LSB is really = dec128 and not 1!

    How do i guess this? if you right shift your 13300 6 times, you get ~207. Assuming you are testing 0-5V you expect 1024/5=204 per volt. Pretty close.

    If you need help understanding or fixing this, post code!

    Sorry, we posted together
    Last edited by cncmachineguy; - 21st September 2010 at 13:24. Reason: code posted while I was postng
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,616


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    Right, of cource...

    trip1 = 13300 gives exactly 1V trip level. I don't mind having this kind of resolution, but it doesn't seem realistic.
    Missing :

    - Deactivate comparators
    - ADC result right justified

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

  6. #6
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Acetronics View Post
    Missing :

    - Deactivate comparators
    Is this specific for 10 bit ADC, or should it be there for 8 bit conversion as well?
    And how? -CMON0 something?

    Quote Originally Posted by Acetronics View Post
    Missing :
    - ADC result right justified
    Alain
    Hm, the example programs that I have (for 16F877A) do not have such an instruction, does that PIC not need it?

    ADCON0.7 = 1 seems to have have cured the problem, thanks guys.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    Is this specific for 10 bit ADC, or should it be there for 8 bit conversion as well?
    And how? -CMON0 something?
    have a look to datasheet ... Comparator section !!!

    Hm, the example programs that I have (for 16F877A) do not have such an instruction, does that PIC not need it?
    some pins share the comparator and ADC functions ... you HAVE to verify which function is deactivated and which is to activate. ( one at a time ... )

    Depends on the chip used - and the ports used ...

    ADCON0.7 = 1 seems to have have cured the problem, thanks guys.
    Full config done = NO suprise ...

    sometimes, the pic defaults @ reset are the ones you want ... sometimes not. so you have to verify everything with the pic Datasheet !!!
    ************************************************** ***********************
    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
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    have a look to datasheet ... Comparator section !!!
    Done that, but didn't understand it (new to this stuff).

    Code:
    CMCON0 = %00000000
    seems to be accepted by PBP and the chip (still) works.

  9. #9
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    sometimes, the pic defaults @ reset are the ones you want ... sometimes not. so you have to verify everything with the pic Datasheet !!!
    Yes, I have had some interesting output signals on outputs that were not specified in the program!

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,616


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    Done that, but didn't understand it (new to this stuff).

    Code:
    CMCON0 = %00000000
    seems to be accepted by PBP and the chip (still) works.
    Boooooooooooooo .... the chip is really gentle with you ...

    look a bit closer at the drawings and the corresponding config @ $8 p 53 ...

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

  11. #11
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    I said that I don't understand this kind of data sheet...

    Well, I think it says that .....000 only turnes the comp output off, but ....111 turnes the comp off as well. It doesn't matter much for this project, but my first project is battery operated and saving some current is welcome.


    I guess it's nice to have a comparator integrated, but right now I would need an OP-amp instead!

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,616


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    I said that I don't understand this kind of data sheet...
    !
    I do promise you lots of fun ...

    Swedish hot nights ... I believed it was a bit different

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

  13. #13
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Not sure if you're sorted, but as someone who recently struggled with this very type of same thing, here are the 12F683 commands towards helping you out ...

    If using 10 bit AtoD, then right justify is required**.....

    ADCON0.7 = 1 (right justifies your 12F683 AtoD result)

    .....whereas with 8 bit AtoD, left justify is required....

    ADCON0.7 = 0 (left justifies your 12F683 AtoD result)

    and finally this one....

    CMCON0 = 0 (turns the pesky 12f683 comparator off - of course if you need the PIC's comparator, then it's not pesky at all & this command should not be used!)

    Good luck!



    ** and no matter how many times I read the datasheet with respect to left/right justifying, I end feeling like an amoeba being wafted around the bottom of a refuse tip pond.
    Last edited by HankMcSpank; - 23rd September 2010 at 16:35.

  14. #14
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    mikebike, Here is something I thru together last year for quick motor control pwn controller. Try it... The A/D works just fine.. You can get rid of the 64 samples...

    Dave Purola,
    N8NTA
    Attached Files Attached Files

Members who have read this thread : 1

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