10/27/2022 0 Comments Waveplayer 2.0 bit ratePWM Resolution = Log/Log(2) = Log/Log(2) = 8 The resolution of the PWM signal can be calculated using the function: The wave file must be 8-bit and for that I configured the PWM outputs to give the maximum frequency with 8-bit resolution, for that I configured Timer2 module as shown below: The function fat_read_data(16, data) keeps reading file data from the SD card until it returns 1 which means end of the wave file is reached. The data buffer can be less or higher than 16. I set the data buffer to 16 so each time the microcontroller reads 32 bytes from the SD card. If the wave file is mono => channel_count =1 and if it is stereo => channel_count = 2. Where the variable address_pointer belongs to the FAT library, this variable allows me to know the starting address of the wave audio file. Sdcard_read_byte(address_pointer + 22, &channel_count) To detect if the wave file is mono (1 channel) or stereo (2 channels), the MCU reads the byte 22 of the wave file using the function : If the initialization of the SD card, the FAT system and opening of the file were OK that means the variable which named ok = 0 and playing the wave file starts using the function play(). After the initialization of the SD card I initialized the FAT file system using the function fat_init() and then I opened the wave audio file with the pre-selected name mywav.wav, all the three previous function returns 0 if OK and no-zero if error. The name of the wave audio file which I used was mywav (mywav.wav with the extension), its sample rate is 8000 Hz with 2 channels (stereo).įirst of all I initialized the SD card using the function: sdcard_init() this function return 0 if the initialization was OK and non-zero if there was an error. I tested this project with FAT32 8 GB and FAT16 2 GB micro-SD cards. In this project I used the FAT library (FAT16 and FAT32), its source file can be found in the the following topic: Waveplayer 2.0 bit rate code#The C code below was tested with CCS C compiler versions 5.051. If the wave audio file is stereo both speakers will give sound. The microcontroller generates audio using PWM technique, if the wave audio file is mono (1 channel) the microcontroller will generate only 1 PWM signal (PWM1) and hence we will hear the sound from 1 speaker only.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |