adnan012
Advanced Member level 1
- Joined
- Oct 6, 2006
- Messages
- 468
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,298
- Activity points
- 4,923
for i = 0 to n-1
pwm(i) = 0.5 + 0.4 * sin(360° * i / n)
next i
What is the peak voltage with respect to dc bus ground?
max: 200V x 90% = 180V
sorry, I can´t find sine table nor your program. So it´s impossible to verify.Or i am making some mistake.
/ 16bit DDS algorithm to make one sinewave of accurate freq using
// 16 MHz xtal (4 MIPS on PIC 16F)
#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
}
*******************Modified code for Dspic33*********************************
//Code for dspi33FJ64GS610
unsigned long long int Wave1;
unsigned char Wave_1;
#define SyS_Clock 961000000 // pwm factor
#define PWM_PERIOD 20000 // 20khz
#define Fout 50
#define Fpwm (SyS_Clock/PWM_PERIOD) // 48076 period register vaalue
#define BDA_Period (((Fout)*(64)*(256))/(Fpwm))
unsigned char sine[64] =
{
0,0,0,1,2,4,6,8,11,14,18,22,26,31,
35,40,45,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,45,
40,35,31,26,22,18,14,11,8,6,4,2,1,
};
50usec interrupt
// to get 90 percent of duty 99*450 is the maximum value for duty register
{
Wave1 = Wave1 + BDA_Period;
Wave_1 = (Wave1>>7 & 0x3F);
DutyCyclePWM1(sine[Wave_1]*450);
}
This you defined twice. Why?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};
Means 100% is a value of 99*450/0.9 = 49500.// to get 90 percent of duty 99*450 is the maximum value for duty register
It seems not correct to me.#define SyS_Clock 961000000 // pwm factor
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?