Since I have a day off, I tried to test the circuit further to see what works and what doesn't.
Here's the video:
And the github page: https://github.com/uncle-yong/pic16f1579-music-box-pbver
What works:
- I have to use a 74HC125N (tri-state buffer) to convert this 1 and 0 from the PWM to the 1 and Hi-Z. The /OE pin is coupled to the PWM, the A to the +5V and the Y is the output. Just simply toggling the /OE pin gives you the +5V or the Hi-Z, so that's done already!
- Used the melody parsing system by Len Shustek and made up a 3-tone music box, with very less overheads compared to the original PICBasic's design.
- The microcontroller is a PIC16F1579 - with 4 independent PWM modules. Some more space too!
What doesn't work:
- The PWM generator doesn't alternate between 1 and Hi-Z. There is no way I can have a microcontroller with that feature! Using an external 74HC125N solves that problem.
- After the tri-state buffers, the decay envelope isn't complete! R-C combination at the bottom of the circuit - I have to replace the 2.2uF and the 100K resistor to the 10uF and 10K resistor, for the decay sound envelope to reach almost +5V, or when it passes through the bypass cap before the LM386, it is almost 0V.
What is difficult:
- Controlling the attack and decay envelopes. I had to do many trial and errors on the RC combinations. Since the RC is also coupled to the input/outputs of the microcontroller, the behaviour of the decay has been altered. If I have used a separate attack/decay generator earlier, that wouldn't have happened easily.
The schematic (1/2):
+5V
^
|
+---------------------------------+
PIC16F1579 | 74HC125 |
+------------------+ | +-----------------+ |
| | | | | |
| | | | | |
| | | | | |
Gate1 +--------+ RB5 RB7 +------------+ 1/OE | |
| | | | | |
| | +------+ 1A | |
| | | | | |
| | | +----+ 1Y | |
| | | | | | |
Gate2 +--------+ RB4 RC7 +------------+ 2/OE 3/OE +-----+ |
| | | | | | | |
| | +------+ 2A 3A +--------+
| | | | | |
| | | +--+ 2Y 3Y +--+ |
| | | | | | | |
Gate3 +--------+ RC2 RB7 +----+ | | | | | |
| | | | | | | | |
| | | | | | | | |
+------------------+ | | | +-----------------+ | |
| | | | |
+-------------------------------+
| | |
| +----+SqWave CH2 |
| |
+------+SqWave CH1 +-----+SqWave CH3
Schematic (2/2):
EACH CHANNEL: 100K SqWave CHx +----------------+--------/\/\/\/\------------>Output_x | \ / \ 10K / \ 220 / | Gate_x +----/\/\/\/\----+ | + | --- 10uF --- | +++ /// MIXING THREE CHANNELS TO LM386 MODULE: // SqWave CH1 +---------------+ +-----------------+ // | 100nF | | +--+/+ | | +-----------+ | | SqWave CH2 +---------------+-----||---->+ LM386 module | | | | | | +-----------+ | | | | | +--+\+ SqWave CH3 +---------------+ +-----------------+ \\ \\ 4 OR 8 OHM SPEAKER
ASCII Art From ASCIIFlow Infinity.
Note: Basic connections like +5V and GND on the microcontrollers and the other chip is not shown here. You need to connect these or else it won't work!
Finally this works. After what many troubles I had in 2009. Accomplished? It is very far from it.
What would it be if there's none of the microcontroller which supports the independent PWM? You gotta need to have a separate square wave generators (use an RC with the CD40106) and a digital potentiometer, and then this tri-state buffer. More components, and more hassles! So here, might as well use that PIC16F1579 instead (or the PIC16F1578)!
There are many rooms for improvisation too. That's one fun little project I've been doing so far! :)
The midi source - I lost the webpage's address! I'll put this in when I found it!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.