Potentiometers gone mad ?!

Hey all !!!

Background knowledge:
I have built a project that uses a 28x1 chip, has 7 inputs that are all push to make switches, 8 LED outputs and 4 100K potentiometers.

I also have a midi output that is working with the computer perfectly.
(see thread http://www.picaxeforum.co.uk/showthread.php?t=13403 )

The Project is a control surface for certain music programs on the computer that read the midi data comming in and then use it to change values e.g. volume :D

The Problem: :confused:
I am sending out the data being read from the potentiometers after it has been halved (potentiometers are 0-255 where as midi is 0 to 127 so its roughly right when halved) but where the potentiometers are flicking between 2 values most of the time im getting constant streams of data from the 4 potentiometers which is locking up the system a bit !!! :(
Is there any possible way of avoiding this ????

Cheers !!


Alex
 

westaust55

Moderator
You could add some hysteresis into the code.

Before you do the divide by 2 bit

check the current value with the previous value. If the difference is less than say 3 then skip otherwise use the new value . . .
 
I have tried to do that but in the way I have written it in the program it means when the pot's are turned the value change is not smooth anymore and jumps value each second which is no good :(
 

hippy

Ex-Staff (retired)
I recently wrote some code to handle a similar situation and this is what I used ...

Code:
Symbol adcValue     = w1
Symbol lastAdcValue = w2
Symbol goingUp      = bit0
Symbol tempAdc      = w3
Symbol change       = w4

lastAdcValue = $FFFF
Do
  Gosub ReadAdcValue
  If adcValue <> lastAdcValue Then
    Gosub SendAdcValue
    lastAdcValue = adcValue
  End If
Loop

ReadAdcValue:

  ReadAdc10 3, tempAdc
  If tempAdc = adcValue Then
    Return
  End If
  If tempAdc > adcValue Then
    If goingUp = 1 Then
      adcValue = tempAdc
    Else
      change = tempAdc - adcValue
      If change > 1 Then
        adcValue = tempAdc     
        goingUp = 1
      End If
    End If
  Else
    If goingUp = 0 Then
      adcValue = tempAdc    
    Else
      change = adcValue - tempAdc
      If change > 1 Then
        adcValue = tempAdc
        goingUp = 0
      End If
    End If
  End If
  Return
 
Last edited:

BeanieBots

Moderator
First off, your 100k pots are way out of spec for a PICAXE ADC input.
Try 10k pots instead.
Secondly, make sure your power supply is rock solid and well decoupled.

Once those two issues have been sorted, you should get good solid ADC readings. If not, try the advanced download circuit (improves accuracy when download cable is plugged in). Any noise issues can be improved by putting up to about 100nF capacitance on the ADC pin.

Adding hysteresis in code can be used to 'mask' ADC issues but it is much better to remove the actual cause of the problem whenever possible.
 

MFB

Senior Member
I think that 10K is the maximum recommended input resistance that can be used with a PICAXE analog input. Even if you don't mind the errors associated with using 100K, it might be as well to add capacitors at the ADC inputs for low-pass filtering.
 

hippy

Ex-Staff (retired)
Note that even with a perfect supply and excellent filtering the smallest amount of noise can flip the ADC reading between one reading and another when it's sitting on the boundary between two values. Sod's law says that, despite the small chance of ever setting a pot exactly right to get such an effect, it's just where you turn the pot to most times :)

The only real way round that is using software filtering and using a READADC10 and reducing to 8-bit can help there - though you still have to handle the fact even with 10-bits it can flip from %0000000011 and %0000000100 etc. The trick is to keep the noise down to below 1 or 2 bits and use the lowest two bits to determine what's seen as 8-bits ..

%0000001000 = %00000010
%0000001001 = %00000010
%0000001010 = %00000011 <---
%0000001011 = %00000011 <---
%0000001100 = %00000011
%0000001101 = %00000011
%0000001110 = %00000100 <---
%0000001111 = %00000100 <---
%0000010000 = %00000100
 

boriz

Senior Member
10K pot and 1uF capacitor from ADC input to ground. Average the last two readings: Value=ThisReading+LastReading/2
 
I have 2 picaxe boards working along side one another for this project so if i leave the 100k pots on the first chip and buy 10k ones for the second it should help out. (the boards are both competely separate units just send data along the same line which causes no problems so far)

Just a quick check incase ... Will having 100k pots damage the chip at all if i leave them ????

Also i will add in the capacitors as i need as little delay in the software as possible !!

Will get back soon

Thanks

Alex:D
 

hippy

Ex-Staff (retired)
No, 100K pots won't damage the PICAXE.

Using 100K probably can alter linearity of the ADC value and have other effects on the value read but in practive I've never had a noticeable problem with anything between 4K7 and 100K. Probably depends on application.
 
Top