Can't get POT work on P12f675 - Newbie


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2008
    Posts
    4

    Default Can't get POT work on P12f675 - Newbie

    Hi Guys,

    First I must thank you all, since this forum is great, and I managed to find solutions without posting untill now.
    I am working on an imitation of the interactive led table by evilmadscientist, with slight variances. For those who don't what it is, basically set of leds blinking in a wavy fashion in response to varying ambient light.

    I managed to get the leds do the wave thing by PWM on the 16f675. My problem starts at detecting the ambient light. I have never used analog digital conversion till now and after a brief try, decided POT command would be sufficient too, ansd switched to it(will use it with a photoresistor). I managed to get it work on 16f84A with a 22K potentiometer, grounded after a 0,1 uf capacitor. But want to do it on 16f675. So far it does not read the potentiometer at all and acts erratic. tried connecting the 3rd pin to 5V, but no change. After this circuit works, I will swap the potentiometer with the photoresistor and that will be the light sensor.

    There are two things I suspect.
    1-internal OSC is not good for this.
    2-I just noticed that I activated the weak pullup on all pins, I am at work now and can't wait until the evening to see if this is the problem.

    The simple code I wrote to isolate the problem is given below:

    ---------------------------

    define OSC 4 'define osc speed
    define OSCCAL_1K 1 'write internal osc value
    CMCON = 7 'disconnect comparator
    ANSEL = 0 'disable a/d converter
    TRISIO = %00001000 'set ports
    WPU = %11111111 'weak pullup
    GPIO = 0

    potval0 var byte

    loop:
    Pot 3, 255, potval0 'write pot reading to potval

    if potval0>127 then 'if reading is bigger than 127
    high 0 'blink led on 0
    pause 1000
    low 0
    else
    high 1 'else blink led on 1
    pause 1000
    low 1
    endif

    goto loop
    ---------------------------
    and the include file is below as I have modified it to work with internal OSC

    ---------------------------

    NOLIST
    ifdef PM_USED
    LIST
    include 'M12F675.INC' ; PM header
    device pic12F675, intrc_osc, wdt_on, mclr_off, protect_off
    XALL
    NOLIST
    else
    LIST
    LIST p = 12F675, r = dec, w = -302
    INCLUDE "P12F675.INC" ; MPASM Header
    __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    NOLIST
    endif
    LIST


    ----------------------

    Please gusy help me get out of this. I have been stuck here for 5 desk hours now. After this, my question about interrupts comes, but I havent given up on search for that yet.

    Thanks to responders in advance.

    Oh, one last thing. Since it is my first post, I am not sure if my message is good as a thread here, so please let me know if you have any suggestions, on how and what else to include.
    Last edited by berslan; - 26th March 2008 at 09:53. Reason: typo

  2. #2
    Join Date
    Mar 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Unhappy anyone?

    Come on guys, did I ask such a stupid question that has to be ignored?

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


    Did you find this post helpful? Yes | No

    Talking Was a pretty good question ....

    Quote Originally Posted by berslan View Post
    Come on guys, did I ask such a stupid question that has to be ignored?
    Hi,

    Yes and No ...

    If you had read your Datasheet ...you could have noticed that GP3 is not a pin like the others ...

    BUT, in your favour, you are not to know how "POT" works ...

    So, just remember POT needs the pin to turn from time to time into an OUTPUT ...

    And this is written nowhere in the manual ...

    The Proof :

    Code:
    POTT    movwf   RM1             ; Save bit mask
            call    HIGHT           ; Set pin high to charge cap
            movlw   10              ; Charge cap for 10ms
            call    PAUSE
            movf    RM1, W          ; Get bit mask
            iorwf   INDF, F         ; Set pin to input
            bcf     FSR, 7          ; Point to port
            xorwf   INDF, F         ; Flip bit to low
            clrf    R0              ; Zero counter
            clrf    R0 + 1
    potloop bsf     FSR, 7          ; Point to TRIS
            movf    RM1, W          ; Get bit mask
            xorwf   INDF, F         ; Set pin to output
            CLRWDT?NOP		; Discharge a little (& clear Watchdog timer)
    Alain

    Change pin used ... no other solution ( ... RCTime won't work either )
    Last edited by Acetronics2; - 26th March 2008 at 12:44.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    To add to Alain's explanation, GP3/MCLR is an input only. But huh... why using POT while your PIC have an ADC converter? Check in your manual and on this forum for ADCIN.

    Make sure your pot impedance meet the datasheet requirement (<2.2K if my memory serves me well)

    If you're using a Photoresistor, you will need to use a buffer (op-Amp, transistor or else) in between to match the impedance.
    Steve

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

  5. #5
    Join Date
    Mar 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Smile Cant wait to go home now

    Thanks Alain. Now I get it. In fact I already knew that GP3 is input only and without thinking about how pot works, I used GP3 intentionally, since I could not use it as an output if I needed one later. Smart huh?
    And mister_e, I will give a try to ADCIN. And will make sure to use a analog available pin. thanks for the guidance.

  6. #6
    Join Date
    Mar 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Hours later, at home...

    Just changed the pin, and it works.
    Thanks a lot guys, you are good.

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


    Did you find this post helpful? Yes | No

    Default

    Usually we don't accept anything under "You're the best"... but Just kidding.

    Enjoy!
    Steve

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

Similar Threads

  1. Newbie needs help with POT...
    By greenflight in forum General
    Replies: 3
    Last Post: - 29th August 2007, 01:39
  2. Replies: 4
    Last Post: - 24th January 2007, 22:20
  3. pot controlled pwm -- help
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th January 2006, 12:29
  4. Replies: 4
    Last Post: - 8th September 2005, 15:42
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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