Shop OBEX P1 Docs P2 Docs Learn Events
problem reading capacitor in RC circuit — Parallax Forums

problem reading capacitor in RC circuit

ispearispear Posts: 20
edited 2012-10-31 17:09 in Propeller 1
Hello,

I am working with a 2-axis joystick that uses two 10K pots. I have a .01uF capacitor spanning the leads of each pot and wires going from ground to the pot and then the pot to the propeller's I/O pins respectively. My program works and displays a value for the position of the pot but I only have half of the pot's range. When I turn the pot past half way the value seems to max out and will not deliver a value. So, I get feedback from the UP and RIGHT motions of the joystick but I do not get anything for the LEFT and DOWN motions. I have tried many different 10K pots. Any Ideas???

Many thanks,

-Isaac

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-31 14:01
    Issac,

    Your description is pretty vague. Please post a schematic, along with your source code.

    -Phil
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-10-31 14:11
    Maybe you can post your code and a schematic? Do you use SPIN for the measurement? Or do you use a counter?

    You could also have a look at sigma delta ADC available as application note somewhere on parallax.
  • ispearispear Posts: 20
    edited 2012-10-31 14:19
    Sure thing, here is a schematic and my code. Take a look

    Thanks, Isaactestpot_2a.spin
    schematic.jpg
    1024 x 700 - 82K
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-10-31 14:30
    Are you sure with the schematics? Usually a poti has 3 connectors. 2 simply work like a resistor - these are 2 connectors you use according to your schematic. The 3rd connector is connected to the "slider" and is the one which has a varying resistance. This one is unconnected in your schematic which would mean that nothing will change for the capacitor if you turn the poti.

    Do you have some specs of the joystick? Maybe the 2 resistor connectors of both axles are connected internally.
  • ispearispear Posts: 20
    edited 2012-10-31 14:36
    You are correct but I only need to use two of the three pins. The middle and an outside pin. At least to my understanding that is. This is how i have it wired, i may have drawn it wrong. Thanks. Isaac
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-10-31 14:48
    Ok, here is how I read your code:
    You set the pins high to load the capacitor and you wait for a while until it's loaded.
    Then you set the pins to input so that the capacitor is unloaded via the poti. The counter counts as long as it sees HIGH signal. But you immediately read PHSx which means that you only give the counter the time that SPIN needs between setting the pin to input and the read PHSx instruction. You should simply add a little waitcnt between DIRA[x]~ and TIMEx:=PHSx.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-31 15:03
    Or, better yet, arrange your code this way to make sure both caps are discharged before reading the counters:
    PUB main| time[2]
                      
      repeat
      
        dira[15] := outa[15] := 1
        dira[16] := outa[16] := 1
        waitcnt(clkfreq/10_000 + cnt)
    
        phsa~
        dira[15]~
        phsb~
        dira[16]~
    
        repeat until ina[15] == 0 and ina[16] == 0
    
        time[0] := (phsa - 656) #> 0
        time[1] := (phsb - 656) #> 0
    
        pst.str(string(pst#NL, "time[0] = "))
        pst.dec(time[0])
        pst.str(string(pst#NL, "time[1] = "))
        pst.dec(time[1])
    

    -Phil
  • cavelambcavelamb Posts: 720
    edited 2012-10-31 16:44
    ispear wrote: »
    Sure thing, here is a schematic and my code. Take a look

    Thanks, Isaactestpot_2a.spin
    CAP-POT.JPG

    You mean like this?

    What kind of response / range / timing will this provide?
    1024 x 700 - 116K
  • tritoniumtritonium Posts: 543
    edited 2012-10-31 17:09
    Hi
    I was just wonderin.. you are using a LINEAR pot?
    Because if its a LOG pot, setting it halfway does not give the expected half value...

    on second thoughts if it is an industry joystick then the pots will be linear
    Dave
Sign In or Register to comment.