Thanks for the information kvtal,
for the 50 Hz signal, Time Period is 20ms. According to desired system. for 75% duty cycle it is needed high for 15ms and low for 5ms. again for 70% duty cycle it is needed high for 14ms and low for 5ms.
the code was:
#include <mega8.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(1);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=0 State0=0
PORTB=0x00;
DDRB=0x03;
while (1){
if(read_adc(0)>0){PORTB.0=1; delay_ms(15); PORTB.0=0;delay_ms(5);};
if(read_adc(1)>0){PORTB.1=1; delay_ms(14); PORTB.1=0;delay_ms(6);};
};
}
Ans: for 75% duty cycle and 70% duty cycle receptively
why this is happing and how do i get exact duty cycle where frequency is constant 50H