[SOLVED] AVR microcontroller delay problem

Status
Not open for further replies.

irfan ahmad

Full Member level 3
Joined
Feb 17, 2012
Messages
181
Helped
54
Reputation
108
Reaction score
54
Trophy points
1,318
Location
LAHORE PAKISTAN
Visit site
Activity points
2,212
I am trying to toggle PORTC of atmega16 at rate of
100ms.
this is my code .
Code:
#define F_CPU 8000000UL
#include <avr/io.h>    
#include <util/delay.h>
//////////////////////////////
int main(void) 
{	

  DDRC=0XFF;
  PORTC=0XFF;

  while(1)
{	
  	 _delay_ms(100);
     PORTC=~PORTC;
   }
  return 0;
}
////////////////////////
these are simulation results on proteus.
it toggles after32ms.
what is problem.
 

Which pin are you measuring this on ? PORTC pins have many alternate functions, and there may be some conflict somewhere.

Try toggling just one bit, which is not too critical of its alternate functions.
 

i am measuring on C0.
if i am just toggling PORTC then i can measure from any pin.
am i right?
also i have tested this code
Code:
#define F_CPU 8000000UL
#include <avr/io.h>    
#include <util/delay.h>
//////////////////////////////
int main(void) 
{	

  DDRC=0XFF;
  PORTC=0XFF;

  while(1)
{	
  	 _delay_ms(250);
  	 _delay_ms(250);
  	 _delay_ms(250);
  	 _delay_ms(250);
  	 PORTC=~PORTC;
   }
  return 0;
}
with these fuse settings L=0XE4 , H=0XF9.
using genius programmer G540



It is flashing led very fast. less then 250ms.
please guide me .
currently i am trying to enable internal oscillator at 8Mhz.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…