Hi All
I have updated the USB-MSD demo that I posted here: http://forum.pjrc.com/threads/25367-USB-MSD-with-SD-card-(Teensy-3-1)
One reson being that someone said that it would be of no interest to use the Teensy 3.1 as a memory stick, so I am hoping that this extension shows some use for that function too.
Essentially, by connecting a microphone to the ADC input and an SD card for storage it allows the Teensy 3.1 to be used to record sound, speech (like a digital dictation device). Due to the large storage space it should allow recoding for almost 72 hours on a 4GByte card. To play the recording back, simply connect via USB to a PC and open the file so that the Windows Media Player (or whatever) can play it back.
This is how it works and how to use it:
- This extends the USB-MSD project to include ADC/DAC use.
- The ADC input is A12 (ADC0_DP3), which is a single ended input (0..3.3V) and the DAC output is DAC/A14 (DAC0).
- The ADC input is sampled at 8kHz and each sample saved to an internal SRAM buffer. The PDB is used as time base and DMA is used to save each sample to memory.
- The SRAM buffer is 16kBytes in size (enough for 1s of input in 16 bit ADC mode).
- The DMA transfer generates an interrupt every half buffer (500ms) to signal that half of the buffer has been filled and the second half is now being filled. The circular buffer is handled automatically by the DMA controller.
- The buffer is also copied to the DAC output, but with a 1s delay. It also uses DMA and is timed the same as the ADC (using PDB) and the result is a 1s digital delay line between ADC and DAC. This is interesting even when not using the SD card since it uses no CPU power due to the DMA operation.
- When there is an SD-card attached, the signal can be saved to the SD card. To start a recording the input PTD5 (pin 20/A6) is pulled low for an instance (falling edge interrupt - debounced) and a file called Teensy_ADC.wav is created in the root directory of the SD-card if it doesn't already exist.
- The ADC buffer is saved to this file each time that it is half-full. During the recording the LED flashes quickly (normally it blinks slowly)
- When the input PTD5 (pin 20/A6) is pulsed low again the operation stops and the file is closed (and LED blinks slowly again).
The ADC data content is given a WAV header according to the saved length and format. It is important to stop the recording and not just reset the board since the WAV header will only be updated correctly when stopped correctly...
- The Teensy can then be connected to a PC to play back the WAV file (the recording that was made) via the USB-MSD mode whereby the SD-card appears as a hard-disk.
- After listening to the sound the file can be deleted (or renamed or saved etc.). If not deleted, further recordings are added on to the file and the header updated each time to match the complete content length.
A microphone can be connected to the ADC (with some amplification to get a decent signal) to build a dictation device!
The ADC/DAC/PDB/DMA operation is explained in this document: http://www.utasker.com/docs/uTasker/uTaskerADC.pdf (chapter 2)
The FAT used is documented here: http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF
The USB stack used is documented here: http://www.utasker.com/docs/uTasker/USB_User_Guide.PDF
To get the WAVE file recoding to work I had to study the RIFF WAV format header and then add code to handle the start/stop and disk interface. This required about 40 lines of new C-code to complete. I then tested some recordings and things seemed OK. however I would use an experimental SD card (no imporant data on it) because I can't guarantee that it will really achieve 72 hours ;-)
It is to be noted that the device will appear as a hard disk when powered via USB from the PC but the PC will not see the file (or its size change) until reconnected again later. This is normal since there is no synchronisation mechanism between the PC using the SD card and the internal application using it.
The use of USB-MSD is mainly to retrieve data from such a device after it has been used in a standalone environment. It may also be an idea to avoid recording when the PC has just been connected to - or is using the SD card since it may be using up some of the SD card read/write bandwidth and in the worst case could cause a buffer save to be missed since it couldn't be saved in time.
Hope you like the software.
Regards
Mark
I have updated the USB-MSD demo that I posted here: http://forum.pjrc.com/threads/25367-USB-MSD-with-SD-card-(Teensy-3-1)
One reson being that someone said that it would be of no interest to use the Teensy 3.1 as a memory stick, so I am hoping that this extension shows some use for that function too.
Essentially, by connecting a microphone to the ADC input and an SD card for storage it allows the Teensy 3.1 to be used to record sound, speech (like a digital dictation device). Due to the large storage space it should allow recoding for almost 72 hours on a 4GByte card. To play the recording back, simply connect via USB to a PC and open the file so that the Windows Media Player (or whatever) can play it back.
This is how it works and how to use it:
- This extends the USB-MSD project to include ADC/DAC use.
- The ADC input is A12 (ADC0_DP3), which is a single ended input (0..3.3V) and the DAC output is DAC/A14 (DAC0).
- The ADC input is sampled at 8kHz and each sample saved to an internal SRAM buffer. The PDB is used as time base and DMA is used to save each sample to memory.
- The SRAM buffer is 16kBytes in size (enough for 1s of input in 16 bit ADC mode).
- The DMA transfer generates an interrupt every half buffer (500ms) to signal that half of the buffer has been filled and the second half is now being filled. The circular buffer is handled automatically by the DMA controller.
- The buffer is also copied to the DAC output, but with a 1s delay. It also uses DMA and is timed the same as the ADC (using PDB) and the result is a 1s digital delay line between ADC and DAC. This is interesting even when not using the SD card since it uses no CPU power due to the DMA operation.
- When there is an SD-card attached, the signal can be saved to the SD card. To start a recording the input PTD5 (pin 20/A6) is pulled low for an instance (falling edge interrupt - debounced) and a file called Teensy_ADC.wav is created in the root directory of the SD-card if it doesn't already exist.
- The ADC buffer is saved to this file each time that it is half-full. During the recording the LED flashes quickly (normally it blinks slowly)
- When the input PTD5 (pin 20/A6) is pulsed low again the operation stops and the file is closed (and LED blinks slowly again).
The ADC data content is given a WAV header according to the saved length and format. It is important to stop the recording and not just reset the board since the WAV header will only be updated correctly when stopped correctly...
- The Teensy can then be connected to a PC to play back the WAV file (the recording that was made) via the USB-MSD mode whereby the SD-card appears as a hard-disk.
- After listening to the sound the file can be deleted (or renamed or saved etc.). If not deleted, further recordings are added on to the file and the header updated each time to match the complete content length.
A microphone can be connected to the ADC (with some amplification to get a decent signal) to build a dictation device!
The ADC/DAC/PDB/DMA operation is explained in this document: http://www.utasker.com/docs/uTasker/uTaskerADC.pdf (chapter 2)
The FAT used is documented here: http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF
The USB stack used is documented here: http://www.utasker.com/docs/uTasker/USB_User_Guide.PDF
To get the WAVE file recoding to work I had to study the RIFF WAV format header and then add code to handle the start/stop and disk interface. This required about 40 lines of new C-code to complete. I then tested some recordings and things seemed OK. however I would use an experimental SD card (no imporant data on it) because I can't guarantee that it will really achieve 72 hours ;-)
It is to be noted that the device will appear as a hard disk when powered via USB from the PC but the PC will not see the file (or its size change) until reconnected again later. This is normal since there is no synchronisation mechanism between the PC using the SD card and the internal application using it.
The use of USB-MSD is mainly to retrieve data from such a device after it has been used in a standalone environment. It may also be an idea to avoid recording when the PC has just been connected to - or is using the SD card since it may be using up some of the SD card read/write bandwidth and in the worst case could cause a buffer save to be missed since it couldn't be saved in time.
Hope you like the software.
Regards
Mark