hi.
I want to generate sweeping sinewave from 1kHz to 10Khz using pic controller.
At this page https://www.romanblack.com/one_sec.htm under the heading
Making multiple sinewaves of highly accurate frequency New 21st Feb 2011.
#define BDA_697Hz 365 // constant to make 697 Hz
unsigned int wave absolute 0x15; // 16bit accumulator for the sinewave
unsigned char wave_1 absolute 0x16; // overload for fast access to byte 1
const unsigned char sine64[64] = {
50,54,59,64,68,73,77,81,85,88,91,93,95,97,98,99,99,99,98,97,95,93,91,88,85,81,77,73,68,64,59,54,
50,45,40,35,31,26,22,18,14,11,8,6,4,2,1,0,0,0,1,2,4,6,8,11,14,18,22,26,31,35,40,45};
// loop and generate dual sinewave DTMF tone
PR2 = (128-1); // PWM at period = 128
while(1)
{
while(!PIR1.TMR2IF); // sync to start of PWM cycle
PIR1.TMR2IF = 0;
// calc the sinewave, and load into PWM module CCPR2L
wave += BDA_697Hz; // zero error Accumulation
CCPR2L = sine64[wave_1 & 0x3F]; // Binary Divide output (/256) and keep 6 bits
}
can anyone explain the code. is isr required for the code.
I want to generate sweeping sinewave from 1kHz to 10Khz using pic controller.
At this page https://www.romanblack.com/one_sec.htm under the heading
Making multiple sinewaves of highly accurate frequency New 21st Feb 2011.
#define BDA_697Hz 365 // constant to make 697 Hz
unsigned int wave absolute 0x15; // 16bit accumulator for the sinewave
unsigned char wave_1 absolute 0x16; // overload for fast access to byte 1
const unsigned char sine64[64] = {
50,54,59,64,68,73,77,81,85,88,91,93,95,97,98,99,99,99,98,97,95,93,91,88,85,81,77,73,68,64,59,54,
50,45,40,35,31,26,22,18,14,11,8,6,4,2,1,0,0,0,1,2,4,6,8,11,14,18,22,26,31,35,40,45};
// loop and generate dual sinewave DTMF tone
PR2 = (128-1); // PWM at period = 128
while(1)
{
while(!PIR1.TMR2IF); // sync to start of PWM cycle
PIR1.TMR2IF = 0;
// calc the sinewave, and load into PWM module CCPR2L
wave += BDA_697Hz; // zero error Accumulation
CCPR2L = sine64[wave_1 & 0x3F]; // Binary Divide output (/256) and keep 6 bits
}
can anyone explain the code. is isr required for the code.
Last edited: