GENERATING PWM in AVR studio using atmega 16 for 8 bit counter in compare mode

3 replies [Last post]
aashiqcoolguy21
User offline. Last seen 13 weeks 3 days ago. Offline
Joined: 05/31/2009
bOt Points: 3354

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;
}
 

 

<!--Session data-->

 

<!--Session data-->

aashiqcoolguy21
User offline. Last seen 13 weeks 3 days ago. Offline
Joined: 05/31/2009
bOt Points: 3354
pls someo one post and tell

pls someo one post and tell me  my mistake .... bot skool p lease help me out .. !!!

 

<!--Session data-->

 

<!--Session data-->

nataraja
User offline. Last seen 10 weeks 3 hours ago. Offline
Joined: 06/11/2009
bOt Points: 90
#include<util/delay.h> before

#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 ??

judit
User offline. Last seen 10 weeks 2 days ago. Offline
Joined: 05/19/2010
bOt Points: 54
timer

any body help for c++ code to measure time intervals of three consecutive signals?