The maximum PWM frequency with the currently used ledc duty resolution of 10 bits in PWM module is 78.125KHz.
The duty resolution can be lowered down to 1 bit in which case the maximum frequency is 40 MHz, but only the duty of 50% is available.
For duty resolution of 8 buts, the maximal frequency is 312.5 kHz.
The available duty levels are (2^bit_num)-1, where bit_num can be 1-15.
The maximal frequency is 80000000 / 2^bit_num
In my MicroPython implementation, I'm currently working on enabling user selectable and/or automatic duty resolution and higher maxumum frequencies.
/*
Streaming of sound data with Bluetooth to an other Bluetooth device.
We provide the complete sound data as a simple c array which
can be prepared e.g. in the following way
- Open any sound file in Audacity. Make sure that it contains 2 channels
- Select Tracks -> Resample and select 44100
- Export -> Export Audio -> Header Raw ; Signed 16 bit PCM
- Convert to c file e.g. with "xxd -i file_example_WAV_1MG.raw file_example_WAV_1MG.c"
- add the const qualifier to the array definition. E.g const unsigned char file_example_WAV_1MG_raw[] = {
Copyright (C) 2020 Phil Schatzmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BluetoothA2DPSource.h"
#include "StarWars30.h"
BluetoothA2DPSource a2dp_source;
//SoundData *data = new TwoChannelSoundData((Channels*)StarWars10_raw,StarWars10_raw_len/4);
SoundData *data = new OneChannelSoundData((int16_t*)StarWars30_raw, StarWars30_raw_len/2);
void setup() {
Serial.begin(115200);
Serial.println("Start");
a2dp_source.start("JABRA TALK");
}
void loop() {
if (a2dp_source.isConnected()==true) {
Serial.println("Connected!");
if (a2dp_source.hasSoundData()==true) {
Serial.println("Has sound!");
}
else {
Serial.println("No sound!");
a2dp_source.writeData(data);
}
}
else {
Serial.println("Not connected!");
}
delay(2000);
}