📜 ⬆️ ⬇️

Dramophon: Portable Digital Drum Set

Good afternoon, dear habrovchane. While the next article on STM32F microcontrollers is in the process of writing, I decided to share with you my old project compiled on AVRs. Honestly, I was not too drawn back to the topic of AVR, but because I recently dug up old materials on my projects, I decided that it would be better to share them with the public. The project is very simple, and the result, in my opinion, is quite interesting, which makes this device a good start for beginners. In general, if anyone wants to repeat - welcome under the cut, we begin to make a digital portable drum set.

Introduction


The name for the device turned out quite loud, but in fact it is just a fun toy. Although, we used it with friends as a drummer several times while playing the guitar.
What are we collecting? We are assembling a device that has 8 touch buttons, by clicking on which it reproduces the drum sample recorded in memory.
This is how the device looks like:

image

And this is how it works (in the video of the drama before being placed in the case).
')


Structurally, the device consists of the actual drum card, on which the controlling controller is located, a flash memory mikruha, a slot for an SD card, a 12-bit DAC and an amplifier, sensor boards connected to the main board with an SPI interface and a speaker. All this electronics is assembled in the case of the old column Genius, which fits perfectly.

image

In general, I advise you to adopt this case - if you assemble a device that should output a more or less loud sound, and you think in which case to stuff it - look at the old speakers, it is quite possible that they will suit you.
In my scheme, there was also a display, but apart from the test message, I didn’t display anything on it, so we’ll discard them.
How to assemble a touch keyboard, I already told in the relevant article . We turn to the circuitry of the main board.

Circuitry


The scheme of the device is very simple. Four-watt amplifier, assembled on a TDA1904 chip, fully according to the scheme recommended in the datasheet. Capacitor C14 cuts off the unnecessary DC component of the voltage, the low-pass filter on R2 and C16 restores the waveform after the DAC (the so-called interpolating filter).

image

The digital part consists of an ATMega32 microcontroller, an AT25FD161 flash chip, an SD card and a 12-bit DAC7611 DAC. All peripherals, including the external touch keyboard, are connected via the SPI bus.

image

Since the project is old, one of my first, I can not say that the choice of components is perfect. The plans were originally Napoleonic, so I took “more” for mega, and stuck the display - in fact, in the form in which it is now assembled, it would be quite enough ATMega88. Since the mega and DAC are powered by 5V, and the card and flash drive require 3.3, the levels are consistent with the dividers. This is not a very good solution, now I would not do that, but would use a special converter so as not to overwhelm the signal fronts (and best of all, I would build the entire schematics on 3.3V elements), but this is now)
As for the SD-card, when connecting it, I used the information from the following site :
I must say, there are a large number of interesting projects and useful documentation on it, if you started working with AVR, be sure to look there.
The device is powered by a 9V battery, the amplifier is powered directly from it, the digital schematics is powered by 3.3 and 5V linear stabilizers.



Here, in principle, is all that concerns the circuit part. Since the project is more than two years old, I could have missed something, or the scheme could turn out to be an older version of what I had in hardware, but I conveyed the main idea. You will not be difficult if you want to repeat and improve what I suggested.

Software implementation



How does all this work?
If we omit the question of how I originally conceived it (display, etc., aha), then we get the following: I didn’t play the samples directly from the card, because I was afraid that I didn’t have enough time to read the data (SPI-mode SDbk is rather slow), so I used the card to transfer the samples to the USB flash drive once, then disconnect it from the device and no longer connect it.
The device every few milliseconds polls the keyboard on the SPI, having received data from it, finds out which buttons are pressed. Since he does not have “polyphony”, the priority is given to the last pressed. After that, the timer turns on, and with a sampling frequency of 16 kHz, the sample corresponding to the button begins to be read from the flash drive and output to the DAC.
The program principles of working with the card are stated on the already mentioned site. In short, the card can work in two modes: SPI and standard. By default, the standard mode is enabled, and by SPI it can accept only one command - to switch the mode. Standard mode does not impose additional restrictions on speed, allows the use of a bus of 4 conductors, instead of one, but requires a CRC calculation, which without a hardware calculator will make this mode on mega even slower than SPI. Therefore, a card is given a command to change modes (in this command, the CRC is checked, but it can be pre-calculated and output with hard code), after which it can communicate with the same commands, but without CRC, with standard SPI signals. Library for working with the card can be found here . Again, who is engaged in AVR - add this link to your favorites, this is a huge library that includes peripheral drivers (cards, displays, etc.), protocol implementations, and much more. In order not to waste forces on the file system, the samples recoded in 16 bits x 16 kHz were folded raw, starting from the first byte of the card. This is easily accomplished with WinHEX , an excellent hex editor that allows low-level writing to physical media. In the same form, the samples are overwritten on the flash memory chip as well. For convenience, the duration of all samples is the same and amounts to 8000 samples (half a second at a sampling frequency of 16KHz)
Working with a DAC and a flash drive is also not difficult: the DAC simply needs to send 12 bits of data, the most significant bit forward, and then jerk with LD, meaning a transfer from the input register to the internal one. Since the mega works with bytes, you should add 12 bits to 16 zeros.
A flash drive accepts commands to read, erase and write. After the read / write commands, data can be received / sent by the stream, since the address counter in it is auto-incremented.
I would gladly share the program code with you, as I usually do, but alas, the source code was lost during hard formatting, apparently, it looked through and did not save ... But I think it will not be difficult for you to start a 16 KHz timer and issue it in the interrupt on the DAC, the value read from the flash drive)

Conclusion



I must say that it is rather funny after a few years to write an article about your old projects developed during the training. Every now and then, thoughts arise, “Oh, well, I am so, because it could have been done differently, it would have been better!”. Not to mention that the element base also does not stand still, and developing a similar device on the same STM32F1xx will not be able to take care of either an external DAC (there is a built-in!) Or level coordination (powered by 3.3V, like with a card ), nor about communication with the card (STMka can communicate with them in normal mode, with CRC). However, whatever this project was, it served as an excellent training in the development of devices. Therefore, I recommend to all beginners: after you master the flashing LEDs, choose a project that will be of interest to you and try to implement it. Any - even though I described the drama, at least one of the hundreds of other projects on the AVR, lit on the Internet, and even better - completely your own. Let it end up being not the way it was originally conceived, and in consequence you will seem simple and crooked - but it will give you a very rewarding experience.
Good luck in the development!

PS
Links from the article:

Source: https://habr.com/ru/post/124112/


All Articles