The reason why im sharing these wave table generators is because of the fact that some of the ones i found didnt comply with the symmetry of waveforms ( Take the above graph as the correct reference of how they should relate !).
Why is this so important ?! Hmmm, try a guess ?! * Ill leave it to the reader to guess why, as an exercise, as its quite obvious !
Instead they have the period of the Sawtooth wave starting as 0, when it should be starting at the DC-offset value ( 2047 for a 12-bits DAC, for example).
So, it was starting at PI, instead of zero. Triangle wave were starting at 1.5 PI( which both differences are easy and dirty ways of doing it, but this time didnt satisfy my needs, where i need something correct according to the symmetry for interaction and calculation purposes.
So this was my quick solution to it. I hope to maybe improve on this as soon as i can spare a moment.
Also intend to do a see-sawtooth ( with more decrement intermediate stages) generator.
// create the individual samples for our Sawtooth-wave table void createSawTable() { Serial.println(" "); Serial.println("Saw table"); for(uint32_t nIndex = 0;nIndex < WAVE_SAMPLES;nIndex++) { // normalised to 12 bit range 0-4095 nSawTable[nIndex] = nIndex * 8; // == nIndex + (4096/512 == 8);because it // never reaches 512 Serial.println(nSawTable[nIndex]); } } // create the individual samples for our triangle-wave tablevoid createTriangleTable() { //Serial.println(" "); //Serial.println("triangle table"); for (uint32_t nIndex = 0; nIndex < WAVE_SAMPLES; ++ nIndex) { if( nIndex <=128 ){ nTriangleTable[nIndex] = nIndex * 16 + 2047 ; //+offset //Serial.println(nTriangleTable[nIndex]); //Serial.println(nIndex); } else if(nIndex >128 && nIndex < 384 ) { nTriangleTable[nIndex] = 4095-((nIndex-128)*16); //Serial.println(nTriangleTable[nIndex]); //Serial.println(nIndex); } else if (nIndex == 384){ nTriangleTable[nIndex] = 0;//Serial.println(nTriangleTable[nIndex]);void createSq_WaveTable() { Serial.println(" "); Serial.println("Square Wave table"); for(uint32_t nIndex = 0;nIndex < WAVE_SAMPLES;nIndex++) { // despite using numbers directly here, keep in mind its related to // WAVE_SAMPLES as a variable // if(nIndex < (WAVE_SAMPLES/2)) if( nIndex <256 ){ nSq_WaveTable[nIndex] = 4095 ; // Serial.println(nSq_WaveTable[nIndex]); } else if(nIndex >=256 && nIndex <= WAVE_SAMPLES ) { nSq_WaveTable[nIndex] =0; Serial.println(nSq_WaveTable[nIndex]); } } }//Serial.println(nIndex);
} else if (nIndex > 384){ nTriangleTable[nIndex] = (nIndex-384)*16; //Serial.println(nTriangleTable[nIndex]); //Serial.println(nIndex); } } }
No comments:
Post a Comment
Feel free to contact me with any suggestions, doubts or requests.
Bless