pot command


Closed Thread
Results 1 to 23 of 23

Thread: pot command

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default pot command

    Hi,

    Little problem trying to switch POrt on my pot command.
    I am geting good result using the default port . The port command only goes to port B. I want to use portA, so I would like to use this command but it do not work: PortA.02,175,B0

    The follwoing is my working code:

    B0 var byte
    Start:
    Pot 2,175,B0 ' would like PortA.2,175,B0
    Lcdout $fe, 1 'Clear screen
    Lcdout "Pot: ", Dec B0 'Display the decimal value
    Pause 300

    k

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


    Did you find this post helpful? Yes | No

    Default

    Once again, we can't guess wich PIC you're using so try one or all of the following lines

    CMCON=7
    ADCON1=7
    ADCON1=$0F
    ANSEL=0
    ANSELH=0

    if any of ADCON or ANSEL setting work... you may discover something interesting and NEVER EVER use POT command
    Steve

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

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    sorry pic16F88

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


    Did you find this post helpful? Yes | No

    Default

    Now you have to forget POT but use ADCIN instead. Just your POT on your PORTA, no capacitor in serie.

    Your PIC have ADCs AND analog comparator on PORTA... it's useless to use POT.

    Datasheet section 12.0 and 13.0.

    You need to disable the comparator first.. something is right in my previous thread about that.
    Steve

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

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    well the adcon1 I used before doing some A/d conversion.
    I also tried setting the port to output using the Tris command. NOthing works.
    Also, I guess when you say I donthave to use the Pot command you are refering to making A/D conversion ??

    k

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


    Did you find this post helpful? Yes | No

    Default

    Probably you have disable the ADCs but not the comparator? Both have to be disable.

    And yes i'm talking about doing a A/D conversion... that's already built-in, free and far better than POT
    Steve

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

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    by just using a pot on that pin, wont I have to use a voltage divider. If I just put a pot, then it will the same voltage and the convertion will be the same.
    Right now with this I am getting weird characters on the lcd.
    I did not touch portB..
    To disable I guess by using the ADCON1 = 0 it is disable (bit 2 and 3)

    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    B0 var byte
    Start:
    TRISA = 3 ' Set PORTA to all input
    ADCON1 = 0 ' PORTA is analog
    ADCIN 0, B0 ' Read channel 0 to B0

    Lcdout $fe, 1 'Clear screen
    Lcdout "Pot: ", Dec B0 'Display the decimal value
    Pause 300

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    TRISA = 3 and ADCON1 should be out of the loop...

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


    Did you find this post helpful? Yes | No

    Default Look at mister_e's question

    Quote Originally Posted by mister_e
    Once again, we can't guess wich PIC you're using so try one or all of the following lines

    <h4>CMCON=7</h4>
    <h4>ADCON1=7</h4>
    ADCON1=$0F
    <h4>ANSEL=0</h4>
    ANSELH=0

    if any of ADCON or ANSEL setting work... you may discover something interesting and NEVER EVER use POT command
    Hi Lerameur,
    I think we gave mister_e a headache tonight, The data sheet chap. 5, 12, 13 makes mention of these. Get it here if you do not have.
    Cheers
    JS
    http://www.microchip.com/stellent/id...cName=en010243
    Last edited by Archangel; - 24th November 2006 at 07:29.

  10. #10
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes I am printing them out and carefully reading them now.
    But, i am curious, if I wanted to use the POT command, what do i have to do to read from port A?

    k

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


    Did you find this post helpful? Yes | No

    Default I think...

    Quote Originally Posted by lerameur
    yes I am printing them out and carefully reading them now.
    But, i am curious, if I wanted to use the POT command, what do i have to do to read from port A?

    k
    lerameur,
    without actually doing it to verify it works . . .as I do not have a 16F88
    put the three BOLD commands into your code to make the PortA pins digital and turn off the analog comparators
    Code:
    CMCON=7              ' Disable comparators
    ANSEL=0               ' Set port as digital I/O
    ADCON1=7
    TrisA = %11111111  'sets all port a as input
    TrisB = %00000000  ' sets all port b as output
    B0 var byte            ' establishes a variable called B
    Start:
    Pot PortA.2,255,B0           ' would like PortA.2,175,B0 use number to suit you
    Lcdout $fe, 1                   'Clear screen
    Lcdout $FE,$80,"Pot: ", #B0       'Display the numerical value
    Pause 300 
    goto start
    end
    This should work.
    JS
    Last edited by Archangel; - 24th November 2006 at 07:29.

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Hi Lerameur. I have an 'F88 and this program works. The 'F88 has 5 ADC's which are better than using the pot command. I connected pin 17 (ana 0) to the center terminal of a 1 meg pot. The CCW terminal to ground, CW terminal to B+.

    OSCCON = $60 'SET INT OSC TO 4MHZ
    ANSEL = 0 'SELECT ANALOG INPUTS 0 = NONE AND ALL DIGITAL
    ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
    CMCON = 7 'COMPARATORS OFF
    TRISA = %11111111 'PORTA INPUTS
    TRISB = %00000000 'PORTB OUTPUTS
    X VAR BYTE 'VARIABLE TO PUT POT VALUE
    PORTB = 0 'ALL OUTPUTS LOW

    START:
    ADCIN 0, X 'READ VALUE ON ANA 0
    IF X > 0 AND X <= 50 THEN LED1
    IF X > 50 AND X <= 100 THEN LED2
    IF X > 100 AND X <= 200 THEN LED3
    IF X > 200 THEN LED4
    GOTO START

    LED1:
    HIGH PORTB.0
    PAUSE 1000
    LOW PORTB.0
    GOTO START

    LED2:
    HIGH PORTB.1
    PAUSE 1000
    LOW PORTB.1
    GOTO START

    LED3:
    HIGH PORTB.2
    PAUSE 1000
    LOW PORTB.2
    GOTO START

    LED4:
    HIGH PORTB.3
    PAUSE 1000
    LOW PORTB.3
    GOTO START

  13. #13
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am going to try this today thanks.
    I am following John Iovine,s book, he usesa F84a pic. He always uses the portB by default, I wanted to try using port A , but on a F88.
    Also I was reading the command CMCON=7 meaning th three first bit are set to one. When I read the legend it says 1 is for Setting th bit, I would of first thought setting would be for setting for comparator mode.

    k

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


    Did you find this post helpful? Yes | No

    Default His Book

    Quote Originally Posted by lerameur
    I am going to try this today thanks.
    I am following John Iovine,s book, he usesa F84a pic. He always uses the portB by default, I wanted to try using port A , but on a F88.
    Also I was reading the command CMCON=7 meaning th three first bit are set to one. When I read the legend it says 1 is for Setting th bit, I would of first thought setting would be for setting for comparator mode.

    k
    Hi Lerameur,
    I have his book too, I thought that was where you got that code. He , in my opinion, left too many loose ends in his code as he neglected to put in all the needed little setup routines, like the trisa and trisb etc. he relies on pbp defaults
    and that sorta leaves beginners out in the cold, if you do not rely on defaults and write in everything your code will always be usable and only require minor tweaking to port to other PICs
    Cheers
    JS

  15. #15
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes thats what I am beginning to realize too , lots of stuff missing in the book, then when you use another chip, I'm screwed.
    Abou tthe A/D, doesn't that read a voltage ? whereas the Pot read a resistance ?

  16. #16
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    both cde works,
    i am trying to figure out one thing now.

    I am replacing this command line:
    HIGH PORTB.0
    PAUSE 1000
    LOW PORTB.0

    by this one:
    serout 2,n9600,(2)

    i am getting errors:
    C:\PBP\POT_TRY.BAS ERROR Line 39: Bad expression.
    C:\PBP\POT_TRY.BAS ERROR Line 33: ID LED2 is not a LABEL.
    C:\PBP\POT_TRY.BAS ERROR Line 34: ID LED3 is not a LABEL.
    C:\PBP\POT_TRY.BAS ERROR Line 35: ID LED4 is not a LABEL.

    suddenly my labels are not labels ??

  17. #17
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Sometimes the error messages bear no relation to the actual error.

    Try changing serout 2,n9600,(2)

    to serout 2,n9600,[2]
    Keith

    www.diyha.co.uk
    www.kat5.tv

  18. #18
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes thanks,

    those french keyboards...

    k

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


    Did you find this post helpful? Yes | No

    Default

    yeah i know what you mean. It's always handy to have English(United State) driver installed too. Just need to press Shift+Alt to switch between language
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by lerameur
    yes thanks,

    those french keyboards...

    k
    Hi,

    For once one can say it's the Keyboard's error ...

    Mhhhh, have something against French Goose liver, Sauternes, Camembert, Cognac, ... and so on ...

    Ahhhh, I see ... that was just a "glitch" ...

    Alain

    PS: In French, as I've read here, your should be called " Le Ramier " ... and not "Lerameur" ....
    LOL !!!!
    ************************************************** ***********************
    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 " !!!
    *****************************************

  21. #21
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    wow shift-alt, thats cool.

    I am still confused about one part. The default selection from the compiler is great but very specific for me. Lets say you are using the Pic16F877, with port A, B, C,D,
    I then use the command serout, IS there a problem using the exact port?
    Ex: serout portC.2,N9600,[3]
    instead of 2,N9600,[3] . ( by which I know the pin number, but I dont know the port)
    For me it looks like its taking a random port, obviously , the one by default...

    ken

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


    Did you find this post helpful? Yes | No

    Default It's better

    Quote Originally Posted by lerameur
    wow shift-alt, thats cool.

    I am still confused about one part. The default selection from the compiler is great but very specific for me. Lets say you are using the Pic16F877, with port A, B, C,D,
    I then use the command serout, IS there a problem using the exact port?
    Ex: serout portC.2,N9600,[3]
    instead of 2,N9600,[3] . ( by which I know the pin number, but I dont know the port)
    For me it looks like its taking a random port, obviously , the one by default...

    ken
    Hi Ken,
    No it's better to specify PortA or PortB or . . . than just serout 2,N9600. I have only seen serout 2,N9600 used as port B, I think it is a throwback to PBasic and not the pro that still works in Pro,maybe for basic stamps, the PBasic cannot use the Pro sytax which allows you to specify the port. I only use the full name of ports so I do not allow myself to get sloppy, I am not a good enough programmer to ALLOW sloppy, I think generally speaking you can serout on any "I/O" pin which can be made digital, possible exception A.4 or 5 and IT may work with ext. pullup.
    Joe

  23. #23
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I was programing in serial and it di dnot work, then I saw another command serout2, decided to use it, and just by adding the 2 it works.. I am only doing one signal, why would this one work and not the other ? using the F88,

    serout2 PORTB.2,n9600,[2]

    ken

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Using the Pot command.
    By timseven in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th August 2009, 20:23
  3. PBP2.50b and POT command problem ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th October 2008, 17:14
  4. Replies: 4
    Last Post: - 24th January 2007, 22:20
  5. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57

Members who have read this thread : 1

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