hoanglocmdc
Newbie
- Joined
- Sep 30, 2014
- Messages
- 5
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Location
- Hanoi, Vietnam, Vietnam
- Activity points
- 30
Hello everybody
I'm trying to implement a sine wave inverter at 50hz.
here is my code :
here is results from proteus simulate :
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
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;
}
}
}
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