Updated 2016-09-26 09:16:38 by pooryorick

by Theo Verelst

Using the parallel port setup examplified in applying the parallel port to drive a LED and read a switch from tcl, and a Texas Instruments PGA2310 high-quality Volume Control chip, I made an audio control application where Tcl/Tk can change the volume of a stereo sound source in real time, and with high quality.

This electronics project is not a beginners' project, though for electronicists it should not be very hard, and the interesting part is, of course, the use of tcl to control the electronics, which makes it possible to in a portable and very flexible and easy to use way make interfaces.

The PGA2310 (or 2311) is connected up using the more or less the standard application diagram, where it has two audio inputs and two outputs, a +5V and -5V power supply, with a separate 5V specified for the digital circuitry, and the 4 control pins Chip Select, Serial Data In, Serial Data clock, and Serial Data Out are connected to a standard parallel port on a PC.

The idea is now that tcl is used to write the right bit string using the serial protocol and the tcl parallel port library and driver, to set the audio chip to a certian volume.

This script makes a scale appear from Tk, which realtime interactively controls the volume of a stereo sound source using the chip and the parallel port:
proc bitno {v i} {return [expr {((1<<$i) & $v) >> $i}]}

proc setparvol {{v1 192} {v2 192}} {
    global pv1 pv2
    set pv1 0
    set pv2 0
    lpt_wrdata 0
    for {set i 7} {$i >= 0} {incr i -1} {
        lpt_wrdata [expr ([bitno $v1 $i] << 2) + 0 + 0]
        lpt_wrdata [expr ([bitno $v1 $i] << 2) + 2 + 0]
        set pv1 [expr {$pv1+(([lpt_rdstat] >> 6) << $i)}]
    for {set i 7} {$i >= 0} {incr i -1} {
        lpt_wrdata [expr {([bitno $v2 $i] << 2) + 0 + 0}]
        lpt_wrdata [expr {([bitno $v2 $i] << 2) + 2 + 0}]
        set pv2 [expr {$pv2+(([lpt_rdstat]>>6)<<$i)}]
    lpt_wrdata 1
    return [list $pv1 $pv2]

load E:/Theo/Tcl/LptTcl.dll
lpt_wrdata 0

toplevel .vsl
scale .vsl.sl
pack .vsl.sl -expand y -fill y
proc slcom v {setparvol $v $v}
.vsl.sl conf -from 255 -to 0 -tickinterval 20 -command slcom

Does it work? Yes, it works nice and smooth, and more than fast enough. The circuit and program could be a but simplified, but this version reads back the previous value from the chip via its serial out pin, which is reported back from the setparvol procedure as a 2 element list with values from 0 to 255. Zero dB for the chip is 192.

Also, I used Pcom with a adapted version of the above, to remotely control volume, over a network.

I just expanded the circuit to 3 stereo channels, which are mixed together, with 3 of tha bove slider in a Tk window, which works fine, too.

Here is the circuit diagram of the 2 channel chip [1] I used, connected to the parallel port:

Of course there must be a ground connection to the computer port, too, and grounding rules must be honoured, and I connected the SDO (serial data out) to a free inport bit.

In this picture, the 2d and 3d channel are added by adding another, 4 channel chip, in the back the parallel port cable is visisble, leading to an extra buffer stage (74HC573), and some of the cables leading to the audio sources and the amplifier.

See Also  edit

LED display driven by the parallel port under tcl control
The BF533 EZ-LITE DSP board from Analog has high-quality audio interfaces, and the IDE uses Tcl
remote execution using tcl and Pcom
Windows WAVE volume control using Snack
Because I happened to need it, and maybe to not put off people who arrived at this page for other reasons (googling for volume control...)
Fox Board Tcl: a audio mixer application
Ak extension