Pot signal modification - Picaxe or not?

Wrenow

Senior Member
I have a circuit that has me scratching my head.
This is for a special mix in radio control.
The 2 channels are controlled by an analog voltage using pots as voltage dividers from 0-5v.

When pot A is between 0 and 2v, I want to add 3v and feed that to the second channel in place of the normal signal from B (i.e., 1v on A feeds 4v to B, ov on A feeds 3v to B, 2v on A feeds 5v to B)

When pot A is between 3v and 5v, I want to subtract 3v and feed that to the second channel in place of the normal signal from B (i.e., 3v on A feeds 0v to B, 4v on A feeds 1v to B, 5v on A feeds 2v to B)

Between 2v and 3v on A, the voltage on Pot B is passed through, regardless of its value.

Been cogitating using an I2c DAC, but then it occurs to me there may be simpler electronics to accomplish the same thing, but that requires a minimum of an 18x, I believe.

Then thought about using an 08M with an ADC read, some figuring, and a PWM out with a capaciot0or to smooth out the signal (thoug I have never done this, and am not sure how sensitive the inputs on the encoder board are to the fluctuations of a PWM simulated analog voltage).

Am I missing some easy solution by overthinking this thing?

Any thoughts/suggestions are welcome.

Cheers,

Wreno


ps - Yes, this is the flip side of the Fire Control Assistant project for Radio Control Model Warship Combat, which kind of does the same thing downstream of the receiver, based on the servo pulses (reading and modifying them), but this attacks the problem upstream of the transmitter encoder for those who want to put the circuit in one transmitter rather than build, say, 5 for 5 different ships. Or flip a switch on the TX to disable it.

ww
 
Last edited:

BeanieBots

Moderator
I'm a little confused as to your exact requirements but the adding and subtracting of voltages is very easy with just a few resistors and an op-amp.
If you make a basic "differential amplifier" (one op-amp + 4 resistors), the pot could feed one input and a PICAXE digital output could feed the other input. You would then have POT voltage or POT voltage + V when the output is high.
Is that what you were trying to do?
 

hippy

Technical Support
Staff member
Your spec is a little confusing and I think you have a typo in the second paragraph, "When pot B is between 3v and 5v". My interpretation is ...

Two analogue inputs, Ain and Bin ( 0V to 5V ). Two analogue outputs Aout and Bout ( 0V to 5V ). Aout is Ain passed through without processing, Bout is derived from Ain and Bin as follows -

1) When Ain is 0V to 2V, Bout = Ain + 3 ( 3V to 5V )
2) When Ain is 2V to 3V, Bout = Bin
3) When Ain is 3V to 5V, Bout = Ain - 3 ( 0V to 2V )

That should be easy enough to implement, a dozen lines of code at most to determine Bout. The main issue being the creation of the Bout analogue signal; I2C DAC or RC by PWM.

A PICAXE-18M is all you would need.

PWM and RC should work and easy enough to breadboard test it. It will be a good idea to test it with whatever it will connect to attached as that loading could affect the output. Having an oscilloscope will help.

An I2C DAC can be controlled by an 08M with some bit-banging, there are enough I/O lines to do two ADC and I2C and enough program memory for the analogue procesisng and I2C bit-banging.

There are pro's and con's for each. I'd test RC with PWM and see if it's good enough.
 
Last edited:

Wrenow

Senior Member
Hippy,

Your interpretation is correct, as was typo catch (thanks, I have edited it to correct it, though that may cause later confusion for others, sigh). I was kind of thinking that the 08M with PWM out might be the way to go, since you have to generate 3 different signals (A+V, A-V, and B passthrough) depending on the voltage of A.

Any thoughts on the values for the RC circuit to begin with (I have a ton of .1uF capacitors, if that is a good starting point, though I suspect it may be a bit weak from the bits I have read on RC circuits - got a reasonably wide value of resistors, though).

In looking at RC circuits, I know you wire the resistor in series to the output pin, and the cap from the load side of the resistor to ground, but, for some reason, my feeble brain thought putting the cap before the resistor would be a better choice (the resistor trying to force juice into the cap before it gets to the load is what is going through my mind's eye). I am guessing I will need to have another long session with one of my EE friends when we get together next month.... ;-)

Beanie,

You are on track with me trying to figure a non-picaxe, or at least non PWM, way around this, like with the differential amplifier you were talking about, but adding voltage is only half of the problem. When at the other end of the throw, it needs to subtract voltage. Having the Picaxe just do the logic of when to add and when to subtract the voltage and activating the particular circuit needed (boost A, attenuate A, or pass B), but I am thinking the PWM solution might be fewer components and easier to both implement and "tune".

Thanks guys,

Wreno
 
Last edited:

wapo54001

Senior Member
If I understand correctly, I think an 08M is enough -- all you need is 3 ADC and one output -- two ADCs to read the two pots, one output to modulate the "B" pot output (controlled by either the A or B pot depending upon the position of the A pot), and the third ADC to monitor and control the output with precision using the 08M-controlled linear voltage regulator circuit and BCJKiwi's optimized (fast) code. As long as the 1023 steps will give you the resolution you need.

If all you need is 0-5 volts, you can omit the LM317 and feedback voltage divider of the regulator circuit. Connect the mosfet to +5 through a suitable resistor and take your output voltage from the resistor/mosfet junction. Load current will not be a problem as long as you choose the correct pullup resistor and the mosfet can handle the load.

If circuit response is more important than precision, you can make that tradeoff by slightly modifying BCJ's published code.
 

goom

Senior Member
How about using analog logic switches?
Lets assume that you can generate the A+3v and A-3V using op amps. Analg switches (or relays?) between:
A+3V and pot B wiper
A-3V and pot B wiper
Pot B wiper and +5V
Pot B wiper and 0V
The control of which switches are on or off would be under PICAXE control depending on the ADC reading from pot A.
One problem is likely to be that the op amps would need to output from 0 to 5V, so would likely need a supply of, say, -1V to 6V.
I have not thought this through thoroughly, so may have missed some fundamental flaw.
 

hippy

Technical Support
Staff member
I don't really understand RC networks, not in terms of optimum values, but I've got a general understanding ...

You're right about PICAXE output via R then into C. The R determines the rate of charge which determines how quickly the voltage rises and falls as the I/O switches high and low. Thus there's always some ripple on the C as it's a saw-tooth with an average voltage.

If you put the C direct to the I/O it would switch instantly high and low. While the average voltage is proportional to duty it's continually moving between 0V and 5V, with the R that keeps it moving between V-v and V+v. The first isn't really an analogue signal, the second is.

The R and C determine how responsive the voltage change is; too high a value of R or C and it takes a long time to change the voltage, too low and it's too responsive, more ripple. Getting the right values comes down to t = R * C and fc = 1 / ( 2 * pi * R * C ) I think. The good thing is that you can choose a C then an R to match which is probably easier than vice-versa; the electronics experts probably have some comments on good C choices.
 

hippy

Technical Support
Staff member
@ wapo54001 : I didn't notice your post #5 ( bad me ). From the voltage regulator thread experience, that does look like a good option.
 

wapo54001

Senior Member
BCJKiwi and I use different code for reading an ADC and also for adjusting.

For reading, I simply read multiple times and take an average. I need many samples because I am reading pressure delivered by a pulsing pump and need to get an average pressure. I read twenty times with no pauses (why waste time pausing when I could be using that time taking more readings), but for faster speed suggest five or fewer samples per cycle.

My adjust code is different than BCJ's, but it's subtle and would take longer to explain than it would for you to simply compare them. Basically, I stay in the adjust loop until the desired and actual output are within 1 count of matching (.0048V error max), and then return to the input for a new input read. You can speed up the process and return to reading the input by accepting a larger error, say 5/1023 or .024V.

Here are my read and adjust code modules:

(If you use the code, remember to change the pin numbers to match your application!)

PS I always run this code at 8MHz.

Code:
'Read Sensor Input and average multiple readings if desired
b10 = 0							'reset count to zero
w1 = 0							'reset average value
do								'loop to get readings to average	
	readadc10 4,w0
	w1 = w1 + w0
	inc b10
loop while b10 < 20
w1 = w1 / 20					'take the average value of readings



'Adjust Output Voltage

adjust:
readadc10 1,w4 			'get voltage data from output

If w1 > w4 then			'if input value > output value, use this calc
w0 = w1 - w4
else
w0 = w4 - w1				'if w4 > w1 OR w4 = w1, use this calc
endif

if w0 < 2 then				'if difference is less than 2, turn off output and go to main 
input 2
goto main
endif	

'if difference is greater than 1, set output high or low to adjust, then loop to compare again
if w4 > w1 then			'output is greater than input
high 2					'set pin2 high to decrease Output
else
low 2 					'otherwise, set pin2 low to increase Output
endif
goto adjust
 
Last edited:
Top