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 PWM inverter code not working

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



Joined: 29 Sep 2014
Posts: 4

View user's profile Send private message

sine PWM inverter code not working
PostPosted: Mon Sep 29, 2014 10:43 pm     Reply with quote

Hello everybody
I'm trying to implement a sine wave inverter at 50hz.
here is my code :
Code:
#include <nghich luu.h>
#include <stdio.h>
#include <stdlib.h>
unsigned char j=0;
unsigned char flag=0;
unsigned char  duty_cycle_up[18]= {15,30,45,60,75,90,105,120,135,120,105,90,75,60,45,30,15};
#int_TIMER2
void TIMER2_isr(void)
{

flag = 1;
clear_interrupt(INT_TIMER2);
}
void main()
{
   
  //set_tris_c(0x00);
   setup_timer_2(T2_DIV_BY_16,155,1);     

   setup_ccp1(CCP_PWM);
   setup_ccp2(CCP_PWM);
   set_pwm1_duty(0);
   set_pwm2_duty(0);
  // set_pwm1_duty(150);
   enable_interrupts(GLOBAL);
j=10;
enable_interrupts(INT_TIMER2);

   while(TRUE)
   {
      //TODO: User Code
      if(flag == 1)
      {
     //j=j-1;if(j==0)j=10;
      set_pwm1_duty(duty_cycle_up[j]);
       j=j+1;
       if(j==19){j=0;}
     
      flag=0;
      }

  }

}


here is results from proteus simulate
[img]http://s1316.photobucket.com/user/Mcu_Pro/media/Untitled_zps4f8fa910.png.html?sort=3&o=0[/img]

i don't know why it is not working as expected of me
the duty cycle no change with i >10
Help me !!!
Thanks all for reading
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Sep 30, 2014 9:00 am     Reply with quote

first you might check this

http://www.ccsinfo.com/forum/viewtopic.php?t=47549

i cant see where you declare or initialize flag and j

your timer#2 int is defective as CCS will clr the int flag for you

and really you could just POLL the timer 2 int_flag in your main and clear it
when true -just substitute the timer_int flag bit for your "flag" var ...

mostly though i can't imagine how this will produce a sine wave for you even if it was working as you hope.

lastly trusting Proteus results, especially generated waveforms is a losing game.

if this is a real project - and not schoolwork-
use real hardware and then see what you get
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 30, 2014 9:36 am     Reply with quote

And read the forum archives. Here is a 6-page thread on it with
some good answers:
http://www.ccsinfo.com/forum/viewtopic.php?t=49562
hoanglocmdc



Joined: 29 Sep 2014
Posts: 4

View user's profile Send private message

PostPosted: Tue Sep 30, 2014 9:39 am     Reply with quote

asmboy wrote:
first you might check this

http://www.ccsinfo.com/forum/viewtopic.php?t=47549

i cant see where you declare or initialize flag and j

your timer#2 int is defective as CCS will clr the int flag for you

and really you could just POLL the timer 2 int_flag in your main and clear it
when true -just substitute the timer_int flag bit for your "flag" var ...

mostly though i can't imagine how this will produce a sine wave for you even if it was working as you hope.

lastly trusting Proteus results, especially generated waveforms is a losing game.

if this is a real project - and not schoolwork-
use real hardware and then see what you get


i declared flag and j at 3rd line and 4th line
i hope that, the code is true and proteus can not be trusted,
but, i haven't real oscilloscope so i must use proteus
i don't know why when duty cycle change from 15 to 135, the system work regular, but when duty cycle down from 120 to 15 it not work ???


i very happy when you reply.
thanks you !!!
hoanglocmdc



Joined: 29 Sep 2014
Posts: 4

View user's profile Send private message

PostPosted: Tue Sep 30, 2014 9:40 am     Reply with quote

PCM programmer wrote:
And read the forum archives. Here is a 6-page thread on it with
some good answers:
http://www.ccsinfo.com/forum/viewtopic.php?t=49562

thanks you !!!
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