really simple adcin question


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    i would go a step back first :

    which pic did you use? how is your setup of ANSEL, CMCON? OSC?

    best is you post the whole code
    i know it's only microcontrolling, but i like it!

  2. #2
    kitcat's Avatar
    kitcat Guest


    Did you find this post helpful? Yes | No

    Default

    pic16f688

    OSCCON = %01110000
    DEFINE OSC 8
    trisa = %101111
    vin var byte
    compvalue var byte
    main:
    adcin porta.0, vin
    if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin]
    compvalue = vin
    goto main

    CMCON0 = 7 gives me a syntax error for some reason.

  3. #3
    kitcat's Avatar
    kitcat Guest


    Did you find this post helpful? Yes | No

    Default

    CMCON0 = 7 gives me a syntax error for some reason.......
    no it doesn't. I got the patch. This setting has not made a difference though.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Try this. Change your serout to HIGH to light an LED as an indicator. Then sample compvalue only once.

    start:
    low portb.0
    adcin porta.0, compvalue

    main:
    adcin porta.0, vin
    if compvalue > (vin + 1) or compvalue < (vin - 1) then high portb.0 : pause 1000 : goto start
    goto main

  5. #5
    kitcat's Avatar
    kitcat Guest


    Did you find this post helpful? Yes | No

    Default

    Hey. That works. THis is my code:

    start:
    low porta.5
    adcin porta.0, compvalue

    main:
    adcin porta.0, vin
    if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin] : goto start
    goto main


    can you explain why this works and the other way doesn't?

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


    Did you find this post helpful? Yes | No

    Default

    Without going into your code in any detail, your original code (below) has a flaw in it's thinking...

    if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin]
    compvalue = vin

    If vin increases by ONE, no change happens, but you replace compvalue with the content of vin.

    Next time around, if vin changes by ONE, you do the same.

    So vin can slowly change by ONE, you don't get a SEROUT but compvalue starts drifting.

    What your code should have done is this...

    if compvalue > (vin + 1) or compvalue < (vin - 1) then
    serout porta.5,6,[#vin]
    compvalue = vin
    endif

    this way, compvalue is updated ONLY if you've done a SEROUT, no SEROUT so no update of compvalue.

  7. #7
    kitcat's Avatar
    kitcat Guest


    Did you find this post helpful? Yes | No

    Default

    Oh yes. Thankyou. It all makes sense now!

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 01:43
  3. Simple question regarding ports
    By rngd in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd February 2008, 16:37
  4. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 18:27
  5. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 22:02

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