POT command and Scale factors


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2011
    Posts
    16

    Smile POT command and Scale factors

    Hi Guys,

    I'm a newbie. I am having trouble using the "POT" command with my 12F675. It simply doesn't work on any port (neither does RCTIME). I have had success using ADCIN using a voltage divider which worked fine but not POT or RCTIME? Why?

    Next question, I have a variable that I want to scale from say 50% up to 105%. How can I do this in code? When I try to multiply or divide large numbers from the ADCIN (say 1023) the result is usually 1 or 0 and nothing in between. I'm guessing its a bit limitation thing. Please help. Thanks.

    P.S... I'm using an external XT as I stuffed up the internal calibration value.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    Do you have the hardware connected as the manual shows in the POT command section?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    Quote Originally Posted by mackrackit View Post
    Do you have the hardware connected as the manual shows in the POT command section?
    yep tried it and still not working. Any hints?

  4. #4
    Join Date
    May 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    Fanman:

    I can't help you with the POT and or RCTIME command, but I can help you recover the internal oscillator calibration value.

    The attached file OSC-CAL.bas is a small PBP program to load into your 12F629 and or 12F675.

    The attached file OSC-CAL.doc is a word doc showing how to recover your OSCAL value.

    Hope this helps,
    Ron

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    Hi,
    If ADCIN works on the same pins you're trying to use for POT and/or RCTIME then my guess is that when trying POT/RCTIME you're forgetting to switch the pins from analog to digital inputs. POT/RCTIME both need the pin to be in "digital mode" and they default to analog on startup.
    Code:
    ANSEL = 0  'Turn off ADC functionallity on all analog pins
    CMCON = 7  'Turn off comparator functionallity.
    When scaling values you need to make sure that the result of the calculation fits in the variable to which you assign it. As you know, a value of 1023 won't fit in a BYTE variable, you need a WORD. The result of multiplying 1023 by anything above 0.25 won't fit in a BYTE either so the result variable must be WORD as well.

    Scaling 50 to 105 is the same as multiplying by 2.1, PBP doesn't do floating point, ie you can't program Result = ADCValue * 2.1 but you can do something like:
    Code:
    Result VAR WORD  'Must use a 16bit variable here
    Result = ADCValue * 21  'Result is now 0-21483
    Result = Result / 10    'Result is now 0-2048
    /Henrik.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Angry Re: POT command and Scale factors

    It's amazing how many of my post get deleted suddenly...

    However, Henrik's spot-on!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    May 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    Hi guys,

    Thanks that helped. I decided to use the ACDIN to read the pot value and then scale as you recommended.

    By the way, does using the ACDIN command slow things down much? I'm using it to control a gain control to trigger a strobe (LED).

    cheers

    mark

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: POT command and Scale factors

    To read analog, you really want to use ADCIN (or manually set/read the PIC registers) anyway.

    Nope it shouldn't slow things up.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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