7.1 channel Hi-Fi microprocessor/PC controlled Preamp
I suggest reading about the rebuild first. Information below is for reference purposes.
LCD
An LCD is important for a microchip controlled preamp. Ok, it is possible to control the preamp without one, but knowing the current volume level, cutting/boosting channel levels, switching inputs, switching surround modes all becomes a bit more difficult. All good systems have an LCD anyway!
The LCD I choose wasn't that easy to program, especially as I only intended ever to use text on it. However this is a graphic display Vikay VK5121 LCD module with 32x120 dots. Writing ASCII text codes to it won't work!
I must admit, I needed help with this and after deep searching I found this link. It is exactly what I need to get the features of this LCD up and running - except I would need to convert from the CCS PIC C compiler syntax to the C2C PIC C compiler syntax - as they are not the same!
For completeness, I have the converted source code for the C2C compiler, see lcd.c and lcd.h.
Many thanks to the author for providing this - otherwise I might of had to get some new LCDs!
I added some extra functions, and changed a few things too.
Firstly, my version stretches the text... this is so it is easier to read (like a bold format), but halves the amount of text you are able to fit on the LCD line.
If you don't like this, change the following.
for (x=0; x<10; x++) to change to for (x=0; x<5; x++)
char_row = x/2; to change to char_row = x;
That will restore it back to the original configuration.
I also added lcdString() which allows a C string to be sent to the LCD, and lcdLine() which goes to an LCD line (0-3), deletes it ready for writing new text.
C2C Code for the volume
I will dive straight into showing you the routine that outputs code to all four of my PGA2310 chips...
|
8 bytes in total needs to be sent. One for each channel, representing a volume level from 0-255 (or -96dB to +31.5dB).
Each volume level is stored in an array, with position 0 being the subwoofer channel and 7 being front left (it works in reverse order from what you would suspect). Essentially, one 64-bit word is sent out, meaning this whole process can last a few hundred micro seconds (us) - but it is fast enough as in pratice I notice no delay from turning the encoder to having a change in volume.
Connections in the above routine are all on port c. Pin 0 is serial Data (SDI), pin 1 is Clock (SCLK) and pin 2 is Latch (/CS). They can be changed as you see fit.
Calculating the volume in dB for the LCD
This is quite a complex process, as this C compiler, and PIC's in general do not support floating point numbers natively - so having a decimal point becomes slightly difficult!
However, I worked a way around it, and the code is shown below for your convenience.
|
Its not tooo complex once you've scratched your head and studied it a bit, but in
case you don't care, there are a few things to point out if you want to use this code
in your project. lcdText(' ')
is an important routine - this just takes
a simple character and writes it to an LCD - and it will of course vary depending on
the LCD you have. To make sure the text is wrote to the last line of my display, I
call a routine called lcdLine(3)
. This again will vary according to your
LCD.
Note this routine only takes one volume character - a sort of universal volume level unaffected by rear/sub/center volume cut or boost, or balance if you add that too. Since I have no balance, the character sent to this routine is one of the front levels (i.e. left).
Levels - for cut/boost
Another array of 8 chars is used to represent cut/boost to certain speakers, such as rear, center or subwoofer.
|
This routine takes a universal volume level, and automatically applies the levels from the levels array. It deals with overflow, preventing any sudden change from min to max and vice versa.
The levels array is set from byte codes sent from PIC#1 using:
|
Balance is ignored, hence the loop counter starts at 2, and applies the first byte to every rear channel. More details on how each level is set on PIC#1 is described later in the PIC control page.