Discussion in "AVR Discussion Forum" started by    amiicool    Jul 16, 2008.
Wed Jul 16 2008, 02:12 am
#1
Hello
i am new to avr microcontrollers. i compiled the following code using CVAVR by its make command. i also set clock speed to 4 MHz using the configure dialogue box. It runs fine when i Simulate it on Proteus, but practically after burning, controller blinks the LEDs slower than actually they should.

/*****************************************************
Project : LED Flasher
Chip type : ATmega32
Clock frequency : 4 MHz
*****************************************************/

#include<mega32.h>
#include<delay.h>
#define xtal 4000000

int i;

void main (void)
{
PORTB=0xFF;
DDRB = 0xFF;

while(1)
{

for(i = 1; i <= 128; i = i*2)
{
PORTB = ~i;
delay_ms(100);
}

for(i = 128; i > 1; i = i/2)
{
PORTB = ~i;
delay_ms(100);
}

}

}
------------------------------------------------------------------------------
i am using AVR ISP programmer with parallel interface,
i have attached the schematic of the AVR ISP programmer
Software for burning is Pony Prog.



Wed Jul 16 2008, 08:52 pm
#2
well there is lot of difference in practical and simulation, i think you know it now
Thu Jul 17 2008, 09:50 pm
#3
Thank u Sir but wats the remedy,
Please help
Thu Jul 17 2008, 11:42 pm
#4
well ami,
to match the simulation in real time, u have to keep the CPU load of the simulation lower than 100%. reducing ur uC frequency to a lower value definetely reduces the CPU load. I think it als depends upon ur system configuration because ur software ran pretty smoothly in my system ( maybe because it is an AMD athlon 4400+ 64 bit CPU+ 2B RAM ).
So do not spend time trying to speed up the simulatin. just co-ordinate ur output with the time base shown on the bottom of the simulation screen :-) and anyways, it will run smoothly in real time on hardware so why worry?
Fri Jul 18 2008, 12:24 pm
#5
do you check the fuse bit settings. other wise it will use internal oscillator and it works very slow
Fri Jul 18 2008, 03:53 pm
#6
Simulation runs fine, CPU load varies between 50% - 60%.
The problem i have is that practically after burning the AVR, The LEDs Blink slower than 0.1ms, which i have programmed it for.
i used a 4MHz Crystal.

I want to Know if have missed any register defination in my programming which selects the external clock for AVR that is 4MHz Crystal. Or is there a problem while burning the AVR, because i simply compiled the program with CodeVisionAVR and burned the Hex file to the AVR using PonyProg.
Fri Jul 18 2008, 07:20 pm
#7
Hello Amiicool,

i hope you have set the clock fuse to external Hi-freq Crystal while burning the hex in pony prog.








Arun


 amiicool like this.
Fri Jul 18 2008, 08:30 pm
#8
here are the clock fuse bits to be set for different oscillator options
(taken from the ATMEGA datasheet)


take care that checking the box implies zero and leaving it blank implies 1 in ponyprog fuse settings.
default valueof CLKSEL fuses when shipped is 0001 i.e. 1MHZ internal oscillator.
to change it to external 4mhz oscillator change it to settings highlighted in red.

Tue Jul 22 2008, 12:32 am
#9
Thanks Arun :-)
and Thanks Pdi33 :-)

I did dot set the fuse bits.

would please tell me in detail on how to set the fuze bits for 4Mhz external Xtal on ponyProg.
Tue Jul 22 2008, 08:59 am
#10
hi ami,
try the following steps for changing the fuse bits:
1. connect the uC in ISP mode.
2. open ponyprog and click on the 'securityand configuration bit' in the 'command' menu.
3. the dialogue box (as shown in previous post of arun ) will appear. here press the read button. this will read the security /configurastion bits of ur uC and update the various boxes (checked/unchecked). If ur uC is fresh(i.e. if u are changing this for the first time), then the default value of the uC is 1MHZ internal oscillator. i.e. the CLKSEL fuses will be in this order:
clksel3 ------> 0 ----- > checked
clksel2 ------> 0 ----- > checked
clksel1 ------> 0 -----> checked
clksel0 ------> 1 ----- > unchecked
SUT1.1 --------> 1 ----- > unchecked
SUT1.0 -------> 0 ------> checked

now, for external crystal of 4MHz, u need to change the bits to the following values:
clksel3...0 -----> 1111
SUT1.1-1.0 -----> 1111
CKOPT ------> 1

so, uncheck all these boxes to bring them to 1 and press write button.

that is all.
good luck.
 amiicool like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

FrankTrelm
Tue May 14 2024, 10:39 am
BillyTum
Tue May 14 2024, 09:08 am
Loganbag
Tue May 14 2024, 04:05 am
MichaelMog
Tue May 14 2024, 03:58 am
ThomasGaxaW
Mon May 13 2024, 05:33 pm
RobertInfup
Mon May 13 2024, 04:28 pm
Joshuatem
Mon May 13 2024, 08:30 am
RaymondPex
Mon May 13 2024, 03:24 am