Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] AVR microcontroller delay problem

Status
Not open for further replies.

irfan ahmad

Full Member level 3
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. help.JPGsaif_ul_malook_074.jpg
 

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

GeniusG540programmer.jpg


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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top