khaja_minhaj
Junior Member level 3
- Joined
- Sep 22, 2011
- Messages
- 27
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,474
Sorry Venkatesh. I didn't get you.
Actually I modified the Clock freq to 11.095 Mhz.
Here is the output waveform when I remove 1000uF electrolytic capacitor. The freq jumps to 55.55hz with one spike .
Actually I modified the Clock freq to 11.095 Mhz.
Code:
#include <REG52.H>
#include <math.h>
void pwm_setup(unsigned char);
void io_init();
sbit PWMPIN1=P2^0;
sbit PWMPIN2=P2^1;
#define HALF_SINE_TABLE_SIZE 128
#define MAX_SINE_VALUE 0xFF
#define TIMER_CLK_FREQ 11095000
unsigned int Timer_period;
unsigned short sine_table[];
int i,j,b;
unsigned int table = 64;
unsigned int clk = 11095000;
unsigned int freq = 60;
//unsigned int ISR_freq = freq * table * 2;
unsigned int ISR_freq = 7680;
//unsigned int timer_period = clk / ISR_freq;
unsigned int timer_per = 130;
unsigned int a = 0;
void main()
{
io_init();
pwm_setup(60);
for(i= 0; i < (table / 8); i++)
{
for(j = 0; j < 8; j++)
{
sine_table[b]=65535 - (unsigned int)(timer_per * sin(3.14 * a++/ table) ) ;
b++;
}
b++;
}
a = 0;
for(i= 0; i < table / 8; i++)
{
for(j= 0; j<8; j++)
{
sine_table[b]=65535 - (unsigned int)(timer_per - (timer_per * sin(3.14 * a++/ table) ) ) ;
b++;
}
b++;
}
while(1)
{
}
}
void io_init(){
PWMPIN1 = 0;
PWMPIN2 = 0;
}
void load_timer(unsigned int Time) {
TH0 = (Time & 0xFF00) >> 8;
TL0 = (Time & 0xFF);
}
void pwm_setup(unsigned char freq){
unsigned int ISR_freq1;
ISR_freq1 = 2 * HALF_SINE_TABLE_SIZE * freq;
//Timer_period = TIMER_CLK_FREQ / ISR_freq;*/
load_timer(timer_per);
TMOD = 0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void timer0() interrupt 1 {
static int sample = 0;
static char sign_flag = 0, PWM_out_high = 0 ;
unsigned int Time_to_load;
TF0 = 0;
if( ++sample >= HALF_SINE_TABLE_SIZE ) {
sample = 0;
sign_flag = !sign_flag;
}
++sample;
if(PWM_out_high)
Time_to_load = timer_per - ( sine_table[sample] * timer_per / MAX_SINE_VALUE );
else
Time_to_load = ( sine_table[sample] * timer_per / MAX_SINE_VALUE );
load_timer(Time_to_load);
if(sign_flag)
{
PWMPIN2 = 0;
if(PWM_out_high)
PWMPIN1 = 1;
else
PWMPIN1 = 0;
}
else
{
PWMPIN1 = 0;
if(PWM_out_high)
PWMPIN2 = 1;
else
PWMPIN2 = 0;
}
PWM_out_high = !PWM_out_high;
}
Here is the output waveform when I remove 1000uF electrolytic capacitor. The freq jumps to 55.55hz with one spike .
Last edited: