12f675 A/d Miseries


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default a/d 12f675 ,i can only use 1 and 2 not 500 to test input on a pot

    clean
    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting
    intcon.6=1 'gloabal interrupt
    intcon.7=1 'gloabal interrupt
    pie1.6=1 'a/d interrupt
    pir1.6=1 'a/d interrupt

    adcon0=%10001111 'set an3 on ie gpio.4
    ansel=%00011000 ' sets fosc/8 and gpio.4[an3] as adc input
    cmcon=7 ' turn off comparator function
    trisio=%011000 'set gpio.4 as input and others as output



    'define variables
    rdg var word 'adc reading from an3
    mpin var gpio.2 ' music pin output to speaker
    led var gpio.0 'led output
    tone var word ' tone value for the sound

    'initial setting
    led=0

    'initial interrupt
    on interrupt goto testpot
    'program

    start:
    'reset led
    adcin 3,rdg 'get volt reading from an3 and place adc value in rdg

    goto start

    'isr
    disable
    testpot:

    if rdg =<1 then led=0
    if rdg =>2 then led=1 'turn on led if adc value is equal to or larger than 1


    tone=1+(rdg)*102 'converts adc value to a tone value of 1 to 120
    ' necessary to divide by 10 to avoid 65536 word limit
    'adc of 0=tone of 1, adc of 1023 = tone of 120
    sound mpin,[tone,20] 'provides a tone proportional to input volt duration = 20x12=120 min
    resume
    enable
    end

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mystified View Post
    clean
    What's that for?

    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting
    Those aren't any good as they are written (unless there's something wrong with cut-and-paste, which happens sometimes)

    tone=1+(rdg)*102 'converts adc value to a tone value of 1 to 120
    ' necessary to divide by 10 to avoid 65536 word limit
    'adc of 0=tone of 1, adc of 1023 = tone of 120
    sound mpin,[tone,20] 'provides a tone proportional to input volt duration = 20x12=120 min
    Check your math...
    If rdg = 1 then
    tone = 1 + 1 * 102 = 103
    If rdg = 2 then
    tone = 1 + 2 * 102 = 205
    If rdg = 3 then
    tone = 1 + 3 * 102 = 307
    if rdg = 500 then
    tone = 1 + 500 * 102 = 51001
    Where is this 'divide by 10' you speak of?
    You declare tone as a word variable, yet the PBP manual states that values from 0-127 produce tones, 128-255 produces white noise, and therefore only values from 0-255 are legal, implying that tone should be a byte variable...
    Why not hook up an LCD to make sure your A/D is working in the first place? Then you can actually visualize your values to be output for tones.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    What's that for?

    Probably wanted CLEAR, R vs N, Difference between BEAN and BEAR, or Been and Beer
    Last edited by Archangel; - 15th December 2008 at 20:02.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default thanks for clear

    I thank you of your time
    The code
    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting

    should set up the a the analog to digital converters (adc)
    the output from the adc converter should be 0 to 1023
    but i get just 0 to 3
    I will work on the sound after I can get the 0 to 1023to work.

  5. #5
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile In CASE this helps...

    Hi mystified,
    Quote Originally Posted by mystified View Post
    I thank you of your time
    The code
    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting

    should set up the a the analog to digital converters (adc)
    the output from the adc converter should be 0 to 1023
    but i get just 0 to 3
    I will work on the sound after I can get the 0 to 1023to work.
    Take a look at this informative thread by Melanie.

    Quote Originally Posted by Melanie View Post
    ... Watch the SPELLING of your DEFINEs

    Is your program not working as expected? ...

    Do you have any DEFINEs in your program? ...
    http://www.picbasic.co.uk/forum/showthread.php?t=558

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  6. #6
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default I changed clock 3 to clock 0

    cannot find clock 3 in datasheet it now works thank you

  7. #7
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    OK , I put clock back to 3 but used upper chase in the define statement and that is what made it work
    Thank You very much.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mystified View Post
    cannot find clock 3 in datasheet it now works thank you
    Page 45 of the latest PBP manual

    and

    Page 44 of DS41190E, PIC12F675 datasheet.

    See any similarity between DEFINE ADC_CLOCK 3 and bits 6 thru 4 of ANSEL?

Similar Threads

  1. How do I use 10 bit A/D on 8 bit Pic? 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2020, 21:10
  2. Need help with LM34 and 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th December 2009, 14:06
  3. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 15:39
  4. Need advice on A/D
    By james in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th August 2007, 20:30
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 19:57

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