Software: Attenuator Control Panel


This page describes the operation of the Attenuator Control Panel.
See the design specifications for the detailed input/output formats.
The Attenuator Control Panel is implemented by the file TyE_FrmAttenuatorPanel.FRM
 
AttCtrl.gif

The Attenuator Control Panel handles all communication with the Attenuator Unit. This communication goes with a simple serial protocol on 19200 Baud, 8 bits, no parity, no hardware handshake, no software handshake, no error detection or -correction. The only test on the incoming data is that it must have the correct number of bytes (2), more data will be ignored.
The Attenuator Unit is designed to act as a serial port through the USB. It needs a suitable driver on the PC which emulates a serial port to the PC-software. The Attenuator Unit will not work through a real serial port on the PC.

Determining whether the comport exists.
Note that for most USB emulated serial ports the commport will not exist until the USB device is connected, the correct driver has loaded and the USB connection has been established. This may take a few seconds after plugging in the USB connector.
Also, if more than 1 emulated serial port is/are in use the assignment of commport numbers may be different each time the computer is switched on, or dependent on the order of powering the serial-USB devices. Also using an other USB port may lead to a different commport number. This is a property of the Operating System and I cannot do anything about it.
There is no check whether the device connected is indeed the Attenuator Unit from this project. The only check is that the return message must consist of exactly 2 bytes. Messages of other length will be ignored.
The Attenuator Control Panel sends a 3-byte message to the Atttenuator Unit each 50 ms, or 20 times per second. The Attenuator Unit almost instantaneously responds with its 2 byte return message.
If the connection has established the black text boxes change to white and they will change to green upon pressing the corresponding button.

Setting the values for the Attenuator.
Two byte values are sent to the PGA2311, the attenuator chip. These are the values as they go into the PGA.. That is without any scaling or calibration for headphones sensitivity and the like. See the PGA2311 Datasheet for the meaning of hese values.
The textboxes associated with each scrollbar indicate the decimal number (unsigned byte) and the attenuation of the PGA, again without calibration for headphone sensitivity and the liike. If the setting is zero the text box will display the word "Mute", because that is what the PGA does.

Setting the values for the Led's.
Each of the 3 Led's have 4 operating modes: Off, Continuously on, Slow blinking or Fast blinking. For each Led there is a 2-bit field in the control byte. These bit values correspond to the numeric values of the Enum type  "LedStates". (Normally numeric Enum values are irrelevant. The Enum trick is just to give them unique meaningfull names)  Here the numeric Enum values are important!

Reading the Button Status.
For each of the 3 buttons there are two bits in the status byte. One bit indicates that the button is currently pressed, the other indicates that it has been pressed at least 1 time since reset of the Button Status.

Resetting the Button Status.
In the control byte there is 1 bit indicating that the "has been pressed" status in the Attenuator Unit must be cleared. The attenuator unit does this clearing only once upon receipt of the control byte with that bit set.

Measuring the peak-to-peak input voltage from the Audio Device.
The Attenuator Unit constantly monitors the output signal from the audio device on the left channel. It registers the Peak-to-Peak value as a 1-byte value, with a range of  0 .. 255, where 255 equals 3.3 Volts. In fact 255 indicates a possible overflow and the calibration will fail with a warning message.

Resetting the peak to peak monitor.
As with the "Button has been pressed" status the peak to peak monitor can be reset to zero by a bit in the control byte.
In the Attenuator Unit the reset is done only once upon receipt of the control byte with that bit set.


Interfacing between the Attenuator Control Panel and the rest of the program.

On the program side of the Attenuator Control Panel the interfacing is done through a few global variables. You will never have to access the internals of the form. The variables of concern are listed in the module TyE_ModGlobals.BAS in the section "Communication with the Attenuator Unit"
From the namegiving and the comments there the operation must be clear, such that a VB-programmer can easily interface with the unit.

In fact, when you want to use this Attenuator Unit in another program for some other purpose it is sufficient to take the file TyE_FrmAttenuatorPanel.frm and the above mentioned section from the TyE_ModGlobals.BAS file. And you will need to deliver a CommPortNumber as Byte.