PICAXE to PGA2310 Volume Control

blip1882

New Member
Hi,

I've been thinking about building a PICAXE controlled audio pre-amplifier. For volume control I've been considering using a TI PGA2310 (http://focus.ti.com/docs/prod/folders/print/pga2310.html) digital potentiometer.

I was wondering what the simplest way to interface a PICAXE 18x and the PGA2310 would be? Maybe using the SEROUT command? I'm new to PICAXE so any advice you could give me would be appreciated.
 

hippy

Technical Support
Staff member
It's a three-wire SPI-style bus ( SCK, SDI, SDO ) with an additional chip select, and SEROUT won't help here. You'll need to allocate three output lines to drive the chip ( CS\, SCK, SDI ); SDO is only used for daisy-chaining and doesn't need to be read back to the PICAXE ( Fig 4 ).

You might also want to use two additional output lines to control ZCEN and MUTE\. The chip is 5V so will connect directly to a PICAXE also running at 5V.

With the chip wired up it's a simple matter of ensuring that the three lines are set high and low in the right sequence as indicated by the data sheet ( Fig 2 ).

The documentation on SHIFTOUT in "PICAXE Manual 2 - Basic Commands" is what you will need to get to grips with.
 

hippy

Technical Support
Staff member
SYMBOL CS = pin0 ' Output Pin 0
SYMBOL SCK = pin1 ' Output Pin 1
SYMBOL SDI = pin2 ' Output Pin 2

SYMBOL leftVolume = b0
SYMBOL rightVolume = b1
SYMBOL pan = b2
SYMBOL bitNumber = b3
SYMBOL tmp = b4

StartOfProgram:
CS = 1
:
' Pan Left to Right
FOR pan = 0 TO 255
leftVolume = 255-pan
rightVolume = pan
GOSUB SetVolume
PAUSE 50
NEXT
END

SetVolume:
CS = 0
tmp = rightVolume
FOR bitNumber = 0 TO 7
SDI = tmp AND $80 MAX 1
SCK = 1
SCK = 0
tmp = tmp * 2
NEXT
tmp = leftVolume
FOR bitNumber = 0 TO 7
SDI = tmp AND $80 MAX 1
SCK = 1
SCK = 0
tmp = tmp * 2
NEXT
CS = 1
RETURN
 

blip1882

New Member
Wow! Thanks for the quick reply. I've just started digging through your code sample with the command reference at hand... Looks like a much simpler implimentation than I had originally imagined.

Thanks again.
 

blip1882

New Member
Well I think I understand the application of shiftout now. Basically you use shiftout sub-routine and associated symbols... you specify the data length (128 for 8 bit) and then insert the value into the var_out. Seems pretty simple and it would be easy to build an interface for this. (I'm going to have a remote control vary the volume from the -95 dB point to around -8 dB)

I'm having trouble understanding the math behind this, though. I guess I'm struggling with the concept of bitwise &. Does anyone have canned explanation of how the shiftout sub-routine works... Or just a site that will help to give me a bit of education on this topic. Thanks.
 
Top