Audio Multiplexer (MUX) Circuit With PIC 16F84A
by jandb86 in Circuits > Audio
1172 Views, 3 Favorites, 0 Comments
Audio Multiplexer (MUX) Circuit With PIC 16F84A
This is a break-out circuit board of a three-channel audio multiplexer.
By pressing any of the three buttons, an audio signal from a PC, Bluetooth receiver module, or FM radio can be selected and interfaced with the power amplifier.
As mixing more than one audio signal is meaningless, only a single audio channel is selected among three audio sources by the circuit.
The whole audio multiplexer requires other additional circuits for completion.
What I'm introducing in this Instructable is the main control circuit of the audio multiplexer that will be shown later.
Let's see more detail of the circuit.
Schematics and Parts
For the PIC micro-circuit expert, it shall be a "Hello world" kind of basic circuit.
But for me as a beginner, it takes a long time to figure out this circuit.
Anyway, the following parts are used for making the audio MUX circuit.
***
- Microchip 16F84A Microprocessor x 1
- 2MHz crystal oscillator x 1
- 22pF ceramic capacitor x 2
- 220ohm 1/4W resistor x 3
- LEDs (Red, Green, Yellow) x 3
- 10K 1/4W resistor x 4
- Small tact switch x 3
- Universal PCB and cable wires (Red, Blue)
- Pin-header 3 pin x 1
***
Somehow I happen to have the 2MHz crystal oscillator in my inventory.
Maybe this kind of low-speed part shall be very difficult to get recently as the minimum clock speed of the microprocessor is more than 10MHz.
Therefore you can use a 10MHz or 20MHz oscillator if you want to make the audio MUX circuit.
Probably 16F84A is produced from the year 1995 and is very popular for electronic DIYers.
It is still available and seems to cost you 5~6$ per chip.
But you need ICSP (In-Circuit_Serial Programming) programmer (or hex file burner) for storing binary executable code to the chip.
PIC Programmer and Microprocessors
The ICSP programmer I bought two years ago (2020) is shown in the picture above along with other PIC microprocessors.
I remember that I bought the first 16F84A around 2005 for studying microprocessor programming by myself.
But the old MPLAB (PIC programming IDE) application only supports Assembler or PIC BASIC at that time for programming.
Therefore I used free Assembler for programming the 16F84A chip instead of buying PIC BASIC compiler and expensive custom programmer hardware at that time.
But the Assembler link and loader is too much difficult for me to produce any program code according to my needs.
Due to the reason above, the purchased microprocessor is thrown into my inventory and eventually forgotten.
As the Arduino or Raspberry Pi controllers are available recently for making any control functionalities, these PIC microprocessors are forgotten for a long time.
But for making the simple control function like audio MUX circuit, any PIC microprocessor can be a cheap and very effective solution.
Therefore, I'm revisiting the PIC programming and utilizing the chips used to think useless and just stored in my inventory.
You can use a recent version of the MPLAB application and XC8 C-language compiler for making executable code at this time.
Also, the ICSP programmer above (the model name is K150) supports PL2303 serial communication driver and micro-burner application software for loading hex executable code to 16F84A microprocessor.
Making Audio MUX Circuit
As circuit complexity is not high, the wiring of components is relatively simple as shown in the diagram above.
When pressing any tact switch, a pre-defined LED is turned on as follows.
***
- The first tact switch (connected to RB0 port of 16F84) turn on the red LED (RA2)
- The second tact switch (RB1) turn on the green LED (RA1)
- The third switch (RB2) turn on yellow LED (RA0)
***
When any LED is selected, other LEDs are turned off instantly.
After a certain LED is selected, turn on the specific LED is continued until you select another by pressing the other tact switch.
XC8 C-program Code
When installing MPLAB and XC8 C-compiler, executable code of audio MUX circuit can be produced as shown in the picture above.
As I'm a newbie for the PIC micro C language, still I have some difficulties making a little bit of efficient source code.
You can find code details in the file attached to this step.
The logic flow of audio MUX is simple as described in the steps below.
***
- Define RA0, RA1, RA2 ports as output and RB0, RB1, RB2 ports as input
- Running endless loop for testing any tact switch is pressed (Therefore, testing if RB0, RB1, or RB2 port state become "0")
- If the first tact switch is pressed (So the RB0 become "0") wait 100ms (__delay_ms(100)) for discarding debouncing switch inputs
- If RB0 input is still 0 after 100ms later (So the first switch is actually pressed), turn on RA2 (Red LED) and turn off RA1 and RA0 (Green and Yellow LEDs)
- Then test the second tact switch status (check, wait 100ms, turn on Green LED, and turn off Red and Yellow LEDs)
- Then test the third tact switch status (check, wait 100ms, turn on Yellow LED, and turn off Red and Green LEDs)
***
When tact switch is pressed, initially chattering inputs (switch contact closes and opens happen several times) is created within several tens of milliseconds.
As continuous "0" and "1" inputs are entered to the port (RB0, RB1, or RB2) during the switch chattering (debouncing) stage, forcibly waiting 100ms for reading steady and correct input port status.
When you look at the source code in the file below, you can easily understand the operational logic of the audio MUX circuit driving program as described in the list above.
Downloads
Loading and Burning Executable to 16F84A Chip
When source code compilation is completed, the binary executable (hex file) is created by the MPLAB application.
Then the hex file can be loaded to the 16F84A chip (burning code into the flash memory) by the micro-burner application provided by the K150 programmer manufacturer as shown in the picture above.
After loading executable code to the chip, the 16F84A can be plugged into the audio MUX circuit for running the program.
***
While interfacing the K150 PIC programmer to PC and running the micro-burner program on Windows 10, I'm experiencing continuous PL2303 device driver errors.
I tried many different versions of PL2303 drivers which support PC USB ports interacting with the serial port of the PIC programmer.
Still, I can't find a 100% error-free device driver configuration method on Windows 10.
Maybe the PL2303 drivers seem to be fully compatible with Windows 7.
But I'm guessing the drivers are not working well with Windows 10.
Anyway, I can run the micro-burner application after several times of PL2303 driver installation and removing attempts.
To Be Continued …
As mentioned in the head of this Instructable, the audio MUX circuit will be interface with the PC, Bluetooth receiver module, and FM radio.
And this PIC micro-circuit is the only control part of the overall audio multiplexer (MUX) that will be completed by plugging other additional circuits.
A partially completed audio MUX is shown in the picture above.
I will show the completed multiplexer in the other Instructable later...
Thank you for reading this story.