This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

need help to understand sgen module

In the program given below what is meaning of maximum frequency and how it is decided. what will happen if i substitute max freq also as freq. will it have any effects on code???

The following pseudo code exemplifies, 50Hz single channel digital SIN signal generation
using SGENT_1 module.
#include <sgen.h>
SGENT_1 sgen=SGENT_1_DEFAULTS;
int x1;
main ( )
{
sgen.offset=0;
sgen.gain=0x7fff; /* gain=1 in Q15 */
sgen.freq=5369; /* freq = (Required Freq/Max Freq)*2^15 */
/* = (50/305.17)*2^15 = 5369 */
sgen.step_max=1000; /* Max Freq= (step_max * sampling freq)/65536 */
/* Max Freq = (1000*20k)/65536 = 305.17 */
}
void interrupt isr_20khz()
{
sgen.calc(&sgen);
x1=sgen.out;
}

waiting for reply

Regards

Aditya

  • You set the step_max value and that determines your Max frequency. Since the frequency variable is a 16-bit value the max frequency is the max 16-bit value you can use that wont result in multiplication overflow. You pick the step_max and sampling frequency and that sets the limit on the maximum useable frequecy. So if you were to replace the freq variable with the max i.e.

    sgen.freq=1 << 15; /* freq = (Max Freq/Max Freq)*2^15 */

    and then run it in the 20KHz ISR you would get a signal 305.17Hz