The goal
Build little low power sound player.Usability
Big: adding sound to toys, digital answering machines, jokes, etc...Parts
- atmega8 - MCU
- at45db161d - 16Mbit flash (2megabytes)
- lm386m-1 - 0.5W smd amplifier
- LD-SP-U15.5/8A - 8 Ohm 0.5W micro speaker
- resistors, connectors, ...
Code
- atmega8 flash sound player C source code
- raspberry pi flash sound loader C++ source code [REFERENCE]
Hardware
Description
Amplifier
Amplifier is made from lm386, M-1 version which can give max power output of 0.5W.
Main circuit is from manufacturer's datasheet. I've added additional condensator at input, to smooth modulated PWM output from amtega8. Without it, signal looks like modulated square wave, condensator make something more like triangle.
Amplifier electric diagram |
When I assembled the board, and connected speaker, input from mp3 (not from MCU yet), I've noticed, that speaker squeaks at certain cases, removing C2 and R1 resolved this problem.
Amplifier board |
MCU + Flash
Microcontroller is driven with 8Mhz clock, which is a maximum frequency for atmega8-L. L version can be powered from 2.7 to 5.5V (whole circuit works at 3.3V).
Flash is connected directly to MCU by SPI interface.
Board has programming connectors for MCU and Flash.
Flash was programmed from Raspberry Pi, this is much faster. Another option is to write program on atmega8, which will read data from UART and put it into flash, but this would be slow.
8 bit player diagram |
On circuit you can see 7805DT, but in real is LF33 (I did not found proper package in Eagle).
JP4 pinout is additional, I used it as ADC input to choose sounds. ADC lines was connected to joysticks in Lady Bug 2.4GHz quadrocopter remote control. Attached source code doesn't have this feature.
8 bit player board |
How sounds are represented in flash memory ?
At45db161 can work in 2 modes, pages can be represented at 528 (default) and 512bytes. Pages configuration can be done one time only.
For this project pages were configured at 512bytes, this gives 4096 pages at 16Mbit memory.
First 512bytes from memory (first page) works as a sound description table. This is only used when flash is connected to Raspberry Pi. In sound loading program, this page is mapped to unsigned char byte array, which holds information such as sound name, page start and page end.
Putting sound from PC into flash
First of all, sounds must be speeded up - sound would place less bytes in memory and MCU can play it with proper speed (MCU + SPI + PWM is slower than PC + soundcard).
When I export sound to Raspberry Pi, I speed it up 2 times, then save it as RAW unsigned 8-bit.
Sounds from Raspberry Pi are read with another program written in C++ [REFERENCE]. Which loads them at first free place in memory, then sound description table is filled by sound name, page start and page end.
First free place in memory is found by searching for last end page from last sound in description table.
When sounds ends in the middle of a page, rest of a page is filled with 0 (zero).
Zero is a general 'end of sound' flag, which is used by MCU to stop playing, therefore sound byte value (read from file) cannot be 0, it is incremented by 1.
Playing sounds from flash memory by MCU
Program written in C atmega8 flash sound player C source code, has only page start definitions, playing is made by 'continuous read' from Flash. Stop condition is reached, when 0 (zero) byte is read from flash.
After one byte have been read, is directly written to PWM output.
[ THIS DESCRIPTION IS NOT FINISHED YET ]
how to select the eeprom driver in kernel level for raspberry pi
ReplyDelete