Joystick potentiometer on digital pins

I've been developing a robot controller over the past couple months, and one thing I'm having difficulty with is the joysticks. They are two 10K potentiometers and I've been using Resistive Capacitance to operate them, However they don't wanna seem to work too well, The values are quite jumpy. My question is, Would a A/D converter be useful? I'm not trying to drain too much power from the batteries, however if the converters are necessary i will take the risk of batteries dying quicker.

on the transmit side i have
rc.time(8, 1, @rv)
repeat 1
xbee.tx(rv & $FF)

and on the receiver I have,

repeat until xbee.rx("!")
rv := xbee.rx & $FF

if rv > 248
pst.Str(String("Servo 1 activated"))


  • JonnyMacJonnyMac Posts: 6,818
    edited 2019-11-16 - 02:41:35
    I have used both RC circuits and ADCs.

    Here's a simple RC method that I used in a commercial audio player (EFX-TEK AP-8+). This code could be modified to read by channels at once by using both counters.
    pub read_pot(p) : level 
    '' Reads RC circuit on pin p
    '' -- takes about 2ms
    '' -- assumes 10K + 0.01uF
      ctra := (%01000 << 26) | p                                    ' ctra in pos detect mode
      frqa := 1
      io.high(p)                                                    ' charge the cap
      phsa := 0                                                     ' clear counter
      dira[p] := 0                                                  ' start discharge
      repeat                                                        ' wait for discharge to finish
      while (ina[p])
      ctra := 0                                                     ' disable ctra
      ' scaled for AP-8+ at 80MHz
      ' -- for volume, 0 to 100
      level := (0 #> ((phsa >> 4) - 37) <# 400) >> 2                ' return scaled value
  • I have tried this on several projects and found that I had to round or average things to get some what stable readings.

    I have since switched to ADC and found it works much better. I used the PMC3202.

    I discus this here: Pan and Tilt Servo

  • JonnyMacJonnyMac Posts: 6,818
    edited 2019-11-17 - 03:45:29
    If you look at the end of that code you'll see that is removes the noise bits. I came up with this after a bit of time testing.
      level := (0 #> ((phsa >> 4) - 37) <# 400) >> 2                ' return scaled value

    Again, this was for a commercial audio player, and we couldn't very well have a situation where the volume seemed to be bouncing around on its own.

    I have also coded commercial camera platform controllers; another situation where we have to be a little careful with noise bits. In that particular case, I used a background cog to sample each ADC channel eight times per frame, then took a running average of those samples. The camera platform controllers, of course, use very high quality joysticks.
  • The problem is that the power supply along with the application can make it more or less noisy. The Propeller chip as it clocks along and changes the state of pins causes spikes in the power which in turn effects the RC circuit causing noisy readings. This is impossible to filter out.

    With the joystick I had, I had a very limited throw which required a high resolution to fit the application. I wanted a range of 1000 to 2000 and that required at least 10 bits of resolution. Dropping bits was not an option.

  • RM,
    If you want to avoid the interfacing issues to analogue joysticks you might consider a mobile phone bluetooth joystick app. There are single and double joystick mobile phone apps widely available using bluetooth and a serial protocol. They also have options for data display and switch control.
    I just found the whole analogue controller sub-project clunky with all the components - batteries, circuit boards, switches, joysticks, data display and a cable.
    I used Bluetooth (BT) Joystick Commander on an Android phone as a quick robot/prototype controller for a long time, using JonnyMac's excellent coding as the basis.
    That old phone is gone and the app with it, but I am thinking of reinstating the latest version of the app on my new phone.
  • @macrobeak I understand where you're coming from. if it was a personal project, I would consider using a smartphone. However this particular project is a controller for the robotics team for my school district, Not just high schools, but potentially middle and elementary schools.
Sign In or Register to comment.