CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sine wave generation problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hisham.i



Joined: 22 Aug 2010
Posts: 43

View user's profile Send private message

Sine wave generation problem
PostPosted: Sun Jan 29, 2012 5:01 am     Reply with quote

Hello,
I am designing sine wave inverter with pic18f2331, so am producing sine wave over 180degree using a predetermined sine wave table, and i update duty cycle each timebase interrupt period which is 1/10khz where 10khz is the switching frequency.
But i got this result on my scope after filtering the output signal.
The output stays sinusoidal with the correct amplitude for some number of cycles then it drops and starts increasing again sinusoidally, and so on.
I want to attach a picture for the output wave form but it seems it is not possible to attach a picture from my pc.
I don't know if the problem is hardware or software, so please if you can help me to find any problem in my code.
This is the code
Code:

#include<18F2331.h>
#fuses H4, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP
#use delay(clock=10MHZ)

#define POWER_PWM_PERIOD 999  // 10 KHz pwm freq with 40 MHz osc.

// Sine Wave Lookup Table

long duty[100] =
{120,240,360,519,639,759,879,999,1118,1238,
1359,1479,1598,1718,1798,1918,2038,2158,2238,2358,
2438,2557,2637,2717,2837,2917,2997,3077,3157,3237,
3317,3357,3437,3516,3556,3596,3676,3716,3756,3796,
3836,3876,3916,3916,3916,3916,3916,3916,3916,3916,
3916,3916,3916,3916,3916,3916,3916,3876,3836,3796,
3756,3716,3676,3596,3556,3516,3437,3357,3317,3237,
3157,3077,2997,2917,2837,2717,2637,2557,2438,2358,
2238,2158,2038,1918,1798,1718,1598,1479,1359,1239,
1119,999,879,759,639,519,360,240,120,120
};

/***H2110112***Out*/
long i,d0,d1,d2,j,k;

//The Program takes a value from the lookup table each 0.1ms, and put this number in the duty
//cycle of the power pwm...
//The duty cycle is changed according to interrupt service routine, which is PWM_TB

#INT_PWMTB
void duty_int()
{   //ELEMINATE EVERY THING CONCERNIG J AND K IF YOU HAVE TO MAKE MONOPHASE SYSTEM.//

if(i>99){
   if(j>99) {
      
      d1 = 120;
      i =0;
   } else {
      
      d1 = duty[j];
      j++;
      d0 = 120;
      
   }
   
} else {


   d0 = duty[i];
   i++;
   d1 = 120;   
   j = 0;
}
set_power_pwm0_duty(d0);
set_power_pwm2_duty(d1);
}

void main()
{ float v;
int d3 = 50;   
   i=0;
   j=100;
   k=132;


d0 = 120;
d1 = 120;

// Setup the 4 Power PWM channels as ordinary pwm channels.
setup_power_pwm_pins(PWM_COMPLEMENTARY, PWM_COMPLEMENTARY, PWM_OFF, PWM_OFF);

// Mode = Free Run 
// Postscale = 1   (1-16) Timebase output postscaler
// TimeBase = 0   (0-65355) Initial value of PWM Timebase
// Period = 999  (0-4095) Max value of PWM TimeBase
// Compare = 0     (Timebase value for special event trigger)
// Compare Postscale = 1 (Postscaler for Compare value)
// Dead Time =3 which correspond to >120ns real time value


/*******************************************
dead time = deadtime value/(Fosc/prescalar)*
********************************************/

setup_power_pwm(PWM_FREE_RUN|PWM_DEAD_CLOCK_DIV_2, 1, 0, POWER_PWM_PERIOD, 0, 1,4); 
ENABLE_INTERRUPTS(GLOBAL);
ENABLE_INTERRUPTS(INT_PWMTB);
   

while(1){






}

}


stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Jan 29, 2012 5:53 am     Reply with quote

If the problem is in the hardware it can be a restarting of your controller.
If you have a load after your invertor it can cause dropdown of the supply voltage.
Do you have big capacitators in the filter of the power supply???
Have you put 2 caps near by the controller - 1 electrolite(100uF) and 1 non-electrolite(150nF). The extra caps with big one in the filter should prevent any restarts.
If you have a load ofter your invertor it can cause dropdown of the supply voltage.
Another thing! If you structurise well your program it won`t be nesseccary to use interrupts!
hisham.i



Joined: 22 Aug 2010
Posts: 43

View user's profile Send private message

PostPosted: Sun Jan 29, 2012 6:06 am     Reply with quote

No i didn't put a load at the output, and yes i filtered the input, and for every supply pin of the controller i put 0.1uF capacitor.

I don't think that the controller is restarting, if it is so why it will start making a sine wave with a small amplitude until it reaches its correct amplitude, and then it drops again?

Is there any thing in the configuration bits that may cause the controller to restart?
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 29, 2012 7:08 am     Reply with quote

software ??
Normally for debugging purposes, you'ld printout the variables to 'see' what's going on.In your case I,J,D0,D1,duty[i],duty[j].
One of your counters could be corrupted, your 'IF' logic might be wrong,array pointer might be bad, any number of possibilties.
I'd slow down the ISR to allow sending the data to a PC with a 'file capture' program running, then after say 5 minutes, stop the program and look at the captured data.Compare the numbers to what you think should be happening to what is shown...

hardware??
Yes, one of the config fuses might be incorrect...there are a few !!!

Perhaps coding a 'Hello World' program and running it ( without any PWM of course) will confirm this. If it runs fine, then fuses and PIC is OK...problem lies in the PWM code. If it fails...probably a 'fuse' is incorrect or other setup.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group