ADC on 12f675?


Closed Thread
Results 1 to 11 of 11

Thread: ADC on 12f675?

  1. #1
    Join Date
    Feb 2005
    Posts
    130

    Question ADC on 12f675?

    I have the attached circuit and the following program:


    TRISIO=%1 'Pic 12F675
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    cmcon=7
    ansel=1
    ADCON0=131


    number VAR word

    Pause 100
    Loop:

    ADCIN 0, number ' (0-1023)

    IF number > 0 AND number < 400 Then
    GPIO.1=1
    GPIO.2=0
    GPIO.4=0
    EndIF
    IF number > 401 AND number < 800 Then
    GPIO.1=0
    GPIO.2=1
    GPIO.4=0
    EndIF
    IF number > 801 AND number < 1024 Then
    GPIO.1=0
    GPIO.2=0
    GPIO.4=1
    EndIF


    GoTo loop
    End


    it does not work, any ideas?

    Im trying to do my 1st ADC program, a simpler working one that make me understand the concept is welcome too!!!


    Thanks a bunch
    Attached Images Attached Images  

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Peu,

    Peu>>TRISIO=%1 'Pic 12F675<

    TRISIO is your input output switch.

    I did not go through all of your code, but this put a flag up to me.

    TRISIO=%XXXXXXX is a binary representation of the switches.
    I question the usagle of just TRISIO=%1

    You are using GPIO.0 as your input, thus I would assign TRISIO one of the following:

    TRISIO=%00000001
    or
    TRISIO=1

    Notice I did not put the % in front of the second one.
    Because 1 = %00000001

    I am not saying this is your entire problem. But you may want to check it out.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    I tried but it did not worked, I think Im missing something, but I can't figure it out.

    pointers to adc examples for the 12f675/683 are welcome. Thanks

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Hi,Peu

    I remember CMCON = 7 is used on my 16F628 to DISABLE all Analogic inputs ...
    Verify if the same config. word for 12F675...

    your Pb seems to be here ...

    Alain

  5. #5
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    with this new header:

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    'cmcon=7
    ADCON0=%11000011 'dec 195
    ansel=%001


    it still does not work ... any idea?

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    All you need to set is ADCON0.7 = 1 for right justification. PBP will
    handle channel select bits and ADON.

    Try this.
    Code:
    DEFINE ADC_BITS 10 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50 
    number VAR word
    
    CMCON = 7          ' Comparators off
    ANSEL = %00000001  ' GPIO.0 A/D in, rest digital
    ADCON0.7 = 1       ' Right justify for 10-bit
    TRISIO = %00000001 ' GPIO.0 = input, rest outputs
    
        Pause 100
    
    Loop:
        ADCIN 0, number ' (0-1023)
        IF (number > 0) AND (number < 400) Then
          GPIO 1=1
          GPIO.2=0
          GPIO.4=0
        EndIF
        IF (number > 401) AND (number < 800) Then
          GPIO.1=0
          GPIO.2=1
          GPIO.4=0
        EndIF
        IF (number > 801) AND (number < 1024) Then
          GPIO.1=0
          GPIO.2=0
          GPIO.4=1
        EndIF
        number = 0
        GoTo loop
        
        End
    Assuming you have your config fuse options & oscillator setup
    properly, this should work.

    You can find several more 12F675 A/D examples here;
    http://www.microengineeringlabs.com/...ples.htm#x4pbp
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Smile

    here's an example ... with explanations !!!

    Alain
    Attached Files Attached Files

  8. #8
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Bruce:

    Thanks var word
    loop:
    thanks=$FFFF '


    it works, now I need to adjust the code because the led dont work as expected, but I put a serout after the adcin and the terminal reads the different values OK!!!

    goto loop

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE ADC_BITS 10 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50 
    number VAR word
    
    CMCON = 7          ' Comparators off
    ANSEL = %00000001  ' GPIO.0 A/D in, rest digital
    ADCON0.7 = 1       ' Right justify for 10-bit
    GPIO = %00000000 ' Initialize outputs
    TRISIO = %00000001 ' GPIO.0 = input, rest outputs
    
        PAUSE 100
    
    Loop:
        ADCIN 0, number ' (0-1023)
        IF (number > 0) AND (number < 400) Then
          GPIO = %00000010
          'GPIO.1=1
          'GPIO.2=0
          'GPIO.4=0
        EndIF
        IF (number > 401) AND (number < 800) Then
          GPIO = %00000100
          'GPIO.1=0
          'GPIO.2=1
          'GPIO.4=0
        EndIF
        IF (number > 801) AND (number < 1024) Then
          GPIO = %00010000
          'GPIO.1=0
          'GPIO.2=0
          'GPIO.4=1
        EndIF
        number = 0
        GoTo loop
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Thumbs up

    MASTER !

    I trully appreciate your prompt answers, thank you very much !!!

  11. #11


    Did you find this post helpful? Yes | No

    Default ADC with tone out and hysteresis

    Hi

    After looking to the examples above I have the following I want to do
    As this is my first ADC code I need some tips and maybe some help

    I want to do the following

    ADC on GPIO.0 8 bit

    I have a DC voltage between 0.5V and 2V approx
    Which is varying all the time

    I need to encode the DC variation by a tone between 67hz and 250hz
    with 2-4 hertz incremental/value

    The DC values needs to be stored in EEprom at setup
    (example button is pushed at powerup to enter setup)
    30 DC values should correspond to 30 tones (30 tone's might be set fix in the code)
    So example:

    0.55V = 67hz
    0.64V = 71hz
    0.71V = 74hz
    etc...

    Once setup and running: if a DC value is between or equal next value it has to
    output the tone ( set in the code)
    with a kind of hysteresis for the tone duration and before next sample)
    and a Serout to check the values
    Can anyone help me ?

    Walter

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  4. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55
  5. Serial LCD on 12F675
    By anj in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st March 2004, 23:11

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