A/D, Pot, Input, A,B So lost now....


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2008
    Posts
    6

    Default A/D, Pot, Input, A,B So lost now....

    1st off I would like to say thank you to all for these forums, It has helped me solve many many issues so far.

    I am new to the PIC world but have made leaps and bounds so far.

    Ok. What I am trying to do is control the limits of a servo based on the position of two pots. To give a whole over view of the application I am trying to make a replacement power valve controller for a 2 stroke motorcycle. This being my 1st real Pic project, Im having more than my fare share of issues, but working through them, so any help is greatly appreciated.

    Im trying to use 16f690 chip because I think I need the AD converter to handle the pot command.

    But so the simplified version of the code I am going with is. I am still struggling with the RPM pick up, but one problem at a time. I am replacing the RPM input with a simple low high switch to help simplify testing. I know this isn't the fastest code method due to the pulse pause, but... It should be well quick enough.

    Servo VAR Portc.5 'The servo being used is a Futaba Digital RC Servo.
    Scale VAR Byte
    Pulse VAR Byte
    RinTot VAR Porta.2
    Potin VAR Porta.4
    potvar VAR Byte
    RPMin VAR portc.4
    RPM VAR Word


    POT RinTOT, 255, Scale 'According to docs. By setting the scale to 255, then useing the max resistance of the pot it will give a correct scale? Store this on start up to use later.


    Loop:
    POT Potin, Scale, potvar
    IF RPMin=1 THEN
    PULSOUT Servo, potvar 'I should only get a useable value between 100-200, so effectively limiting my pot, through, I droped the scaling until I could get this fixed.
    PAUSE 18 'The pause for the servo input.
    ELSE
    PULSOUT Servo, 100 'Go back to the lowest pulse position.
    PAUSE 18
    ENDIF
    GOTO Loop
    END

    Ok so I get servo active and locked, if I change it to go to a fixed pulse time on RPM press it works. But once the pot is added in I get nothing. I am probably making a really dumb mistake. So if you do help, Thank you.

    I have read so many different ways of doing this I am very very lost now. I tried some functions with the A/D converters but didn't get very far. Then I read many different approaches to converting the Pot to something useable. Tried some plug and drop in methods, with other code.. So maybe its my way of wiring. Both of my reference books I use have two totally different ways of doing it. So I'm very very confused now. SO again Thank you.

    I drew how I was wiring the pot in if I am screwing that up as well , But I am horrible at drawing on a computer so its pretty rough, but gives the idea.

    Thank you all so very much for even taking the time to look at this.
    Attached Images Attached Images  

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Helmutt View Post
    Ok. What I am trying to do is control the limits of a servo based on the position of two pots.
    Sounds exactly like this other thread out there recently...

    Im trying to use 16f690 chip because I think I need the AD converter to handle the pot command.
    PBP manual says it gets the POT value by charging up an external, then measuring the time it takes to discharge to a low logic level...on a digital input pin.
    I think you'd be better off using an analog input and some ADC type commands and registers.
    Besides, if you're using POT, you'll be at the mercy of your capacitor...which are notorious for having very wide tolerances.
    If you set your potentiometer up as a simple voltage divider, you'll get much more accurate results, and repeatable.
    The POT command is a holdover from way back when, and not a very good command in my opinion.

    Code from another thread using a 12F675...
    Uses a couple of switches and pot to set some endpoints...
    Change the registers over to '690 equals and make something out of it...
    Code:
    @ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; Using Internal Clock, no clock out
    @ DEVICE pic12F629, WDT_ON ; Enable Watch dog timer
    @ DEVICE pic12F629, PWRT_ON ; Enable Power-up timer
    @ DEVICE pic12F629, MCLR_OFF ; Disable MCLR pin
    @ DEVICE pic12F629, BOD_ON ; Enable Brown-out detect
    @ DEVICE pic12F629, CPD_OFF ; EEPROM Protect
    @ DEVICE pic12F629, PROTECT_OFF ; Code Protect off
    TRISIO = %11111110
    INTCON.6=0 ' Disable all unmasked Interrupts
    INTCON.7=0 ' Disable Global Interrupts
    CMCON = 7 ' Disable analog comparator
    ServoOut var GPIO.0
    SetLimitSw var GPIO.1
    PotIn var GPIO.2
    MinSw var GPIO.4
    MaxSw var GPIO.5
    wPosit var word
    Posit var byte
    MinPosit var byte
    MaxPosit var byte
    'load starting min and max positions
    data @ 0, 100
    data @ 1, 250
    '************************************************* ***************
    low Servoout
    'read in stored min and max limits
    read 0, MinPosit
    read 1, MaxPosit
    'for power-on reset of positions:
    if minsw = 1 then
    minposit = 100
    write 0, minposit
    endif
    if maxsw = 1 then
    maxposit = 250
    write 1, maxposit
    endif
    pause 1000
    Start:
    gosub GetServoPosition
    pulsout servoout, posit
    pause 20
    if setlimitsw = 1 then 'check min max buttons
    if minsw = 1 then
    MinPosit = Posit
    write 0, MinPosit
    pause 250
    endif
    if maxsw = 1 then
    MaxPosit = Posit
    write 1, MaxPosit
    pause 250
    endif
    endif
    goto start
    '************************************************* ***************
    GetServoPosition:
    high potin
    pause 1
    rctime potin, 1, wPosit 'at 4 mhz, returns 0 - 120
    'adjust posit to get values between 75 and 250
    'use word-sized variable because calculation might exceed 255
    wposit = wposit + 75 + (wposit / 2)
    'now limit posit to 100 - 250 (1 ms - 2.5 ms)
    'and put into byte-sized variable
    if wposit > 250 then
    posit = 250
    else
    posit = wposit
    endif
    if posit < 100 then posit = 100
    if setlimitsw = 0 then 'apply limits
    if Posit < MinPosit then Posit = MinPosit
    if Posit > MaxPosit then Posit = MaxPosit
    endif
    return
    '************************************************* ***************
    Last edited by skimask; - 9th March 2008 at 09:06.

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Wow, skimask, you must _live_ on this forum
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    Wow, skimask, you must _live_ on this forum
    Nope, just passing by every few minutes in-between work benches and/or projects... Keyboard is at waist level. Easy to type...

  5. #5
    Join Date
    Mar 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    wow, thanks for the reply.

    But damn now Im lost.

    Can I just read the AD converter value to a byte? Then use that as my pulse out. I think thats what that code above is doing, but also applying some limits and boot up procedures.

    I guess where Im getting most lost is how do I define what I am using on that pin? Or Will it just read what ever it wants to? Do I have to write it to a data spot or can I just use it as a variable?

    Servo VAR Portc.5
    Potin VAR AD.4 ' Can I do that? Or Do I call it something else to call the AD converter inside the pin.
    PULSE VAR BYTE


    Loop:
    READ AD.4, Pulse
    PULSOUT Servo, Pulse
    Pause 18
    Goto Loop

    Thanks again, Sorry I am new at this. Im trying.

    EDIT: Ok so super noob question, Is there a difference between calling a PIN by GPIO.? versus Porta.? or Pin 5. I get the port/pin references but I can seem to figure out where the GPIO comes from.
    Last edited by Helmutt; - 9th March 2008 at 18:57.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Helmutt View Post

    EDIT: Ok so super noob question, Is there a difference between calling a PIN by GPIO.? versus Porta.? or Pin 5. I get the port/pin references but I can seem to figure out where the GPIO comes from.
    Hello Helmutt,
    Yes, GPIO is for the PICs that have GPIO like the 12fseries as they only have 1 port. PortA, B, C are assigned to the ports you actually have. I E. a 16F628a has 2 ports, A & B, whereas another PIC might have several more A B C D . . .
    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.

  7. #7
    Join Date
    Mar 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Ah cool, Finally stopped skipping over the 12 pin section and found that out. Thank you.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Helmutt View Post
    Can I just read the AD converter value to a byte? Then use that as my pulse out. I think thats what that code above is doing, but also applying some limits and boot up procedures.
    Easy way...if you left justify the results, you can use the high byte of the result and use the upper 8 bits (low 2 bits ignored), if you right justify, you read both high and low byte of ADRES into a word

    As far as how to use the A/D converter, read the manual. There's an example in there, and while it doesn't fit all scenarios, it fits many of them.

Similar Threads

  1. floating A/D input
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th April 2009, 13:21
  2. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  3. Advice on Input circuitry for 0-10v or Pot
    By bcd in forum Schematics
    Replies: 18
    Last Post: - 12th April 2008, 10:47
  4. Question from New member A/D input 16f876
    By mbruno in forum General
    Replies: 2
    Last Post: - 26th January 2008, 14:52
  5. Replies: 4
    Last Post: - 24th January 2007, 22:20

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