ürettiğim sinüs dalganın 1 periyodunun yarısı var yarısı yok sorun nerde olabilir
Ürettiğim sinüs dalganın 1 periyotunun yarısı var yarısı yok sorun nerede olabilir?
#include <16F877A.h>
#fuses HS,NOWDT,PROTECT,NOLVP // if fuses WDT, program will reset every 2034ms
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7) //
// the following sin data gotten according to the formula : Int((PR2+1)*sin(3.14159265*N/50)+0.5) in attahed excel file
// which named "sine data points.xls"
BYTE const SPWM_DATA[25]=
{16,31,47,62,77,92,106,120,134,147,159,171,182,193,202,211,219,226,232,238,242,246,248,250,250};
int8 period = 249;
int8 postscale = 4;
int16 duty; // duty for CCPx. it will be changed in Interrupt function. no need to be inintialized
int8 array_index = 0; // Index for adjust wave - no beautiful but power
int8 sin_case = 0; // sin_case=0 -- the first 1/4 period
// sin_case=1 -- the second 1/4 period
// sin_case=2 -- the third 1/4 period
// sin_case=3 -- the last 1/4 period
#INT_TIMER2 // This function is called every time the RTCC (timer2) overflows (255->0).
void clock2_isr() {
// for 60hz ac signals
switch (sin_case)
{
// double signal
case 0: // for the first period - 1/4 period
duty =SPWM_DATA[array_index];
set_pwm1_duty(duty<<2); // (duty<<2) is the same as 4*duty, but it operates more fast.
set_pwm2_duty(0);
array_index++;
if(array_index==25)
{
array_index = 24;
sin_case = 1;
}
break;
case 1: // for the second period - 2/4 period
duty = SPWM_DATA[array_index];
set_pwm1_duty(duty<<2);
set_pwm2_duty(0);
if(array_index==0) sin_case = 2;
else array_index--;
break;
case 2: // for the third period - 3/4 period
duty = SPWM_DATA[array_index];
set_pwm2_duty(duty<<2);
set_pwm1_duty(0);
array_index++;
if(array_index==25)
{
array_index = 24;
sin_case = 3;
}
break;
case 3: // for the fourth period - 4/4 period
duty = SPWM_DATA[array_index];
set_pwm2_duty(duty<<2);
set_pwm1_duty(0);
if(array_index==0) sin_case = 0;
else array_index--;
break;
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void main()
{
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
//***************************************************************************
setup_timer_2(T2_DIV_BY_1, period, postscale); // Setup Timer2 interrupt
enable_interrupts(INT_TIMER2); // Enables the interrupt Timer2.
enable_interrupts(global); // enabled all interruptions.
//***************************************************************************
while(TRUE)
{
}
}