bitluni / ESP32AMRadioTransmitter

127 stars 33 forks source link

Can the radio frequency be changed? #2

Open aknik opened 6 years ago

aknik commented 6 years ago

I'd need a frequency of 77.5 khz, how can it can be done ? My project is a DCF77 radio clock transmitter, so I need this freq AM modulated. Thanks https://en.wikipedia.org/wiki/DCF77

bitluni commented 6 years ago

the current i2s freq is 13.3333Mhz and I'm using a 16 value sine table using a sine wave of 172 samples should do the trick

aknik commented 6 years ago

//sine represented in 16 values. at 13MHz sampling rate the resulting carrier is at around 77.5KHz int sintab[] = {0,5,9,14,18,23,28,32,37,41,45,50,54,58,62,66,70,74,78,81,85,88,91,95,98,101,103,106,108,111,113,115,117,119, 120,122,123,124,125,126,126,127,127,127,127,127,126,126,125,124,123,122,120,119,117,115,113,111,108,106,103,101,98,95,91,88, 85,81,78,74,70,66,62,58,54,50,45,41,37,32,28,23,18,14,9,5,0,-5,-9,-14,-18,-23,-28,-32,-37,-41,-45,-50,-54,-58,-62,-66,-70,-74, -78,-81,-85,-88,-91,-95,-98,-101,-103,-106,-108,-111,-113,-115,-117,-119,-120,-122,-123,-124,-125,-126,-126,-127,-127,-127,-127, -127,-126,-126,-125,-124,-123,-122,-120,-119,-117,-115,-113,-111,-108,-106,-103,-101,-98,-95,-91,-88,-85,-81,-78,-74,-70,-66,-62, -58,-54,-50,-45,-41,-37,-32,-28,-23,-18,-14,-9,-5};

unsigned long long pos = 0; //current position in the audio sample, using fixed point unsigned int posLow = 0; unsigned long long posInc = ((unsigned long long)sampleRate << 32) / 77500 ; //sample fixed increment

bitluni commented 6 years ago

nice... forgot about the increment. tell me if it is working :-)

aknik commented 6 years ago

Thanks, I don't need any modulated carrier, only full wave XDD Do you think this mod is ok ?

int samplesize = (sizeof(sintab)/sizeof(int)); Serial.println(13333300/samplesize); // freq in hz

//fill the sound buffer for(int i = 0; i < 2048; i+=samplesize){ //taking current sample int s = 255; //modulating that sample on the 16 values of the carrier wave (respect to I2S byte order, 16Bit/Sample) for(int j = 0; j < samplesize; j += 4) {
buff[i + j + 1] = (sintab[j + 0] s + 0x8000); buff[i + j + 0] = (sintab[j + 1] s + 0x8000); buff[i + j + 3] = (sintab[j + 2] s + 0x8000); buff[i + j + 2] = (sintab[j + 3] s + 0x8000); }

} //

detroittommy879 commented 4 years ago

I'm trying to make a DDS since it should technically be able to go up past 6mhz... aknik i had a problem when the buffer is 2048 in size.. had to make it 1024 for mine to quit glitching / turning on and off.. not sure why.