Skip to content

TDTPA5 User Guide

Use TDTPA5 to control a PA5 Programmable Attenuator from MATLAB or Python.

Requirements

  • TDT Drivers

  • TDT ActiveX package

  • Python only: pywin32

About TDTPA5

TDTPA5 is a wrapper for the PA5x ActiveX control that installs with the TDT ActiveX package. It provides direct access to the attenuator (connect, set and read attenuation, write to the front panel display, set User mode parameters) and is generally easier to use than calling the PA5x object directly.

TDTPA5 installs with the ActiveX controls into:

C:\TDT\ActiveX\ActXExamples\Matlab
C:\TDT\ActiveX\ActXExamples\py

or you can download it in the ActiveX Controls example zip.

TDTPA5 Functionality

Note

See PA5 Programmable Attenuator in the ActiveX User Reference for the complete PA5x programming guide.

Creating a TDTPA5 object

Connecting also resets the attenuator, so you always start from a known state.

Input Parameter Values
'INTERFACE' String, interface type. Can be 'USB' or 'GB' (default for fiber optic interface)
'NUMBER' Integer, device number as enumerated by zBusMon (default 1)
'ATTEN' Float, attenuation to set once connected (default 0)
PA5 = TDTPA5();

% or, connecting to the second PA5 over USB and starting at 20 dB
PA5 = TDTPA5('INTERFACE', 'USB', 'NUMBER', 2, 'ATTEN', 20);
from TDTPA5 import TDTPA5

pa5 = TDTPA5()

# or, connecting to the second PA5 over USB and starting at 20 dB
pa5 = TDTPA5(interface='USB', number=2, atten=20)
PA5 = actxserver('PA5.x');
if PA5.ConnectPA5('GB', 1) == 0
    error('Unable to connect')
end
PA5.Reset

Setting and Reading Attenuation

Attenuation is a floating point value from 0.0 to 120.0 dB. Values outside that range are rejected before the call reaches the hardware.

PA5.atten(20);         % set 20 dB of attenuation

current = PA5.atten;   % read it back
pa5.atten(20)          # set 20 dB of attenuation

current = pa5.atten()  # read it back
PA5.SetAtten(20);

% SetAtten sets an error flag rather than returning failure, so the
% error string is what actually tells you whether it worked
err = PA5.GetError;
if ~isempty(err)
    disp(err)
end

current = PA5.GetAtten;

Front Panel Display

The display is eight characters wide. Longer text is truncated rather than rejected. Position is 0 (left, the default) through 7 (right).

PA5.show('20 dB');
PA5.show('CAL', 4);   % starting at position 4
pa5.show('20 dB')
pa5.show('CAL', 4)    # starting at position 4
PA5.Display('20 dB', 0);

Resetting

Restores the factory defaults: attenuation 0.0, step size 3.0, update dynamic.

PA5.reset;
pa5.reset()
PA5.Reset;

User Attenuation Mode

User values change what the front panel displays and how the dial behaves. They do not change the actual attenuation applied to the signal. Use atten for that. They are intended for quickly comparing several PA5s from their front panels.

Parameter Meaning
'BASE' Base attenuation (0.0 .. 120.0 dB). Use when several speakers vary in output so each displays the same attenuation.
'STEP' Dial step size (0.0 .. 120.0 dB)
'REFERENCE' Reference dB level (0.0 .. 120.0 dB). Lets the display show smaller, or negative, numbers.
'UPDATE' 'DYNAMIC' changes attenuation continuously as the dial turns; 'MANUAL' only applies it when the dial is pressed.
'ABSMIN' Minimum attenuation the dial will allow, to prevent accidentally playing something very loud.
PA5.user('BASE', 5);
PA5.user('STEP', 5);
PA5.user('REFERENCE', 120);
PA5.user('ABSMIN', 20);
PA5.user('UPDATE', 'DYNAMIC');
pa5.user('BASE', 5)
pa5.user('STEP', 5)
pa5.user('REFERENCE', 120)
pa5.user('ABSMIN', 20)
pa5.user('UPDATE', 'DYNAMIC')
% the raw control takes numeric parameter codes
PA5_USERPAR_BASE = 1;
PA5_USERPAR_STEP = 2;
PA5_USERPAR_REFERENCE = 3;
PA5_USERPAR_UPDATE = 4;
PA5_USERPAR_ABSMIN = 5;
PA5_USERUPDATE_DYNAMIC = 0;

PA5.SetUser(PA5_USERPAR_BASE, 5);
PA5.SetUser(PA5_USERPAR_STEP, 5);
PA5.SetUser(PA5_USERPAR_REFERENCE, 120);
PA5.SetUser(PA5_USERPAR_ABSMIN, 20);
PA5.SetUser(PA5_USERPAR_UPDATE, PA5_USERUPDATE_DYNAMIC);

Checking for Errors

Returns the last error string, or an empty string if there was none. atten already checks this for you and warns.

msg = PA5.error;
if ~isempty(msg)
    PA5.show(msg);
end
msg = pa5.error()
if msg:
    pa5.show(msg)

Examples Using TDTPA5

You can find examples installed with ActiveX in:

C:\TDT\ActiveX\ActXExamples\Matlab
C:\TDT\ActiveX\ActXExamples\py

or you can download them in the ActiveX Controls example zip.

Step a PA5 through a range of attenuations:

import time
from TDTPA5 import TDTPA5

pa5 = TDTPA5()
for atten in range(0, 61, 10):
    pa5.atten(atten)
    pa5.show('{0} dB'.format(atten))
    print('attenuation now {0} dB'.format(pa5.atten()))
    time.sleep(1)
pa5.reset()
PA5 = TDTPA5();
for atten = 0:10:60
    PA5.atten(atten);
    PA5.show([num2str(atten) ' dB']);
    disp(['attenuation now ' num2str(PA5.atten) ' dB']);
    pause(1);
end
PA5.reset;