GENERATING PWM in AVR studio using atmega 16 for 8 bit counter in compare mode
Hey guys I am trying to generate PWM in COMPARE mode using ATMEGA 16 for Simple 8 bit counter using FAST PWM...
Check out the error in the followi code .. PLease reply as soon as possible.. BOTSKOOL....!!
Hre is the code.....
#include<avr/io.h>
#include<compat/deprecated.h>
#include<util/delay.h>
#include<avr/interrupt.h>
void PWM(int a)
{
OCR0=0XFF*((1-(a/100)));
//PORTC=0XFF*(1-(a/100)));
}
int main ()
{
DDRB=0XFF;
//DDRC=0XFF;
OCR0=0X00;
TIMSK=_BV(OCIE0);
TCCR0=_BV(WGM01)|_BV(WGM00)|_BV(COM01)|_BV(COM00);
TCNT0=0X04;
for(int i=10;i<=100;i+=10)
{
PWM(i);
_delay_ms(1500);
}
return 0;
}


pls someo one post and tell me my mistake .... bot skool p lease help me out .. !!!
<!--Session data-->
<!--Session data-->
#include<util/delay.h>
before including this header file u have to define the frequency like this
#define F_CPU 4000000UL
#include <util/delay.h>
about _delay_ms
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one,
_delay_ms() provides a "decreased resolution "functionality. In this
mode _delay_ms() will work with a resolution of 1/10 ms, providing
delays up to 6.5535 seconds (independent from CPU frequency). The
user will not be informed about decreased resolution.
//this would be a better way
for(a=0;a<10;a++)
_delay_ms(150);
whats the exact problem ??
PWM o/p ??
any body help for c++ code to measure time intervals of three consecutive signals?