Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

delay time is not reliable

delay time is not reliable

2012-08-31 by englsprogeny1

I'm doing a simple routine here.

Output goes high
output goes low for 5 ms 
output goes back to high.


Problem is that when I scope the signal it is not low for exactly 5ms.


It's 1.925 or 1.426 or 1.003ms  (approximate times)(always less than 5 ms)


Details:
ATMeg16
JTAG interface to AVR Studio 4.18
GCC coded
delay.h


I've read about this and verified that I am good with the following:

1.  I am optimized correctly in the makefile
        CPFLAGS	= -g -Os -Wall -Wstrict-prototypes-I$(AVRLIB)               -Wa,-ahlms=$(<:.c=.lst)





2.  F_CPU is set correctly
#define F_CPU          7372800

3.  Fuse Settings are set correctly (External Crystal/ Res; High Freq)
				Stertup Time 16K CK+64ms

4.  All interrupts are disabled

// disable interrupts
	cli();



Any other ideas?

Many thanks guys!

Re: [AVR-Chat] delay time is not reliable

2012-08-31 by John Samperi

At 03:26 PM 31/08/2012, you wrote:
>2.  F_CPU is set correctly
>#define F_CPU          7372800

But is this what you have in the project settings? _delay_ms is pretty
accurate if it has the correct information.

Are you using your own makefile or the Studio generated one?



Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: delay time is not reliable

2012-08-31 by englsprogeny1

Hi John,

I'm using an external makefile  (my own).
This means that I don't need to set processor speed in Project|Config Options
Right?

I see that processor speed is greyed out (in Config Options|General)

Also, I see in Project Properties|Config Options|custom Options: [all files] that it shows DF_CPU=7372800UL

This processor speed is defined in a file called global.h
#define F_CPU          7372800 


Yes, the delay function call is:

_delay_ms(5);


This is a new board and a new way of building for me.

Today I'm going to try rebuilding (using the make command as I have always done) and run on my (known working) ATMega8 board.  I will program it using ISP, run and measure the timing.


I may also try this on my ATMega128 board.

Thanks John
David


--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
Show quoted textHide quoted text
>
> At 03:26 PM 31/08/2012, you wrote:
> >2.  F_CPU is set correctly
> >#define F_CPU          7372800
> 
> But is this what you have in the project settings? _delay_ms is pretty
> accurate if it has the correct information.
> 
> Are you using your own makefile or the Studio generated one?
> 
> 
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>

Re: delay time is not reliable

2012-08-31 by englsprogeny1

I have the same issue with a different board and build process.


I've done this on my ATMega8 board now, building the HEX file using make.

crystal 8Mhz


I put the F_CPU value in the makefile as well as the global.h file.

I program the ATMega8 board by way of ISP then unplug the programmer from the ISP header.

When I look at the signal, I get between 0.9 and 2.1ms (about)for a call for 5ms.

When I try 10ms delay, I get between 2 and 4ms delay.




An interesting note: 

When I call the microsecond delay I am solid!

_delay_us(333);

Whatever value I tell it to wait, it is exact!

:)



So milliseconds does not work but microseconds does....






--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
Show quoted textHide quoted text
>
> At 03:26 PM 31/08/2012, you wrote:
> >2.  F_CPU is set correctly
> >#define F_CPU          7372800
> 
> But is this what you have in the project settings? _delay_ms is pretty
> accurate if it has the correct information.
> 
> Are you using your own makefile or the Studio generated one?
> 
> 
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>

Re: delay time is not reliable

2012-08-31 by englsprogeny1

Fuse Settings:

LOW Byte
FF

High Byte
D9


I looked at an online fuse calculator:

http://www.engbedded.com/fusecalc/

Everything looks ok.





--- In AVR-Chat@yahoogroups.com, STEVEN HOLDER <s.holder123@...> wrote:
Show quoted textHide quoted text
>
> What are your fuse settings ?
> 
> Regards
> 
> 
> 
> ________________________________
>  From: englsprogeny1 <englsprogeny1@...>
> To: AVR-Chat@yahoogroups.com 
> Sent: Friday, 31 August 2012, 15:00
> Subject: [AVR-Chat] Re: delay time is not reliable
>  
> 
> Â  
> I have the same issue with a different board and build process.
> 
> I've done this on my ATMega8 board now, building the HEX file using make.
> 
> crystal 8Mhz
> 
> I put the F_CPU value in the makefile as well as the global.h file.
> 
> I program the ATMega8 board by way of ISP then unplug the programmer from the ISP header.
> 
> When I look at the signal, I get between 0.9 and 2.1ms (about)for a call for 5ms.
> 
> When I try 10ms delay, I get between 2 and 4ms delay.
> 
> An interesting note: 
> 
> When I call the microsecond delay I am solid!
> 
> _delay_us(333);
> 
> Whatever value I tell it to wait, it is exact!
> 
> :)
> 
> So milliseconds does not work but microseconds does....
> 
> --- In AVR-Chat@yahoogroups.com, John Samperi <samperi@> wrote:
> >
> > At 03:26 PM 31/08/2012, you wrote:
> > >2.  F_CPU is set correctly
> > >#define F_CPU          7372800
> > 
> > But is this what you have in the project settings? _delay_ms is pretty
> > accurate if it has the correct information.
> > 
> > Are you using your own makefile or the Studio generated one?
> > 
> > 
> > 
> > Regards
> > 
> > John Samperi
> > 
> > ********************************************************
> > Ampertronics Pty. Ltd.
> > 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> > Tel. (02) 9674-6495
> > Website http://www.ampertronics.com.au
> > *Electronic Design * Custom Products * Contract Assembly
> > ********************************************************
> >
> 
> 
>  
> 
> [Non-text portions of this message have been removed]
>

Re: [AVR-Chat] Re: delay time is not reliable

2012-08-31 by STEVEN HOLDER

What are your fuse settings ?

Regards



________________________________
Show quoted textHide quoted text
 From: englsprogeny1 <englsprogeny1@yahoo.com>
To: AVR-Chat@yahoogroups.com 
Sent: Friday, 31 August 2012, 15:00
Subject: [AVR-Chat] Re: delay time is not reliable
 

  
I have the same issue with a different board and build process.

I've done this on my ATMega8 board now, building the HEX file using make.

crystal 8Mhz

I put the F_CPU value in the makefile as well as the global.h file.

I program the ATMega8 board by way of ISP then unplug the programmer from the ISP header.

When I look at the signal, I get between 0.9 and 2.1ms (about)for a call for 5ms.

When I try 10ms delay, I get between 2 and 4ms delay.

An interesting note: 

When I call the microsecond delay I am solid!

_delay_us(333);

Whatever value I tell it to wait, it is exact!

:)

So milliseconds does not work but microseconds does....

--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
>
> At 03:26 PM 31/08/2012, you wrote:
> >2.  F_CPU is set correctly
> >#define F_CPU          7372800
> 
> But is this what you have in the project settings? _delay_ms is pretty
> accurate if it has the correct information.
> 
> Are you using your own makefile or the Studio generated one?
> 
> 
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495
> Website http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>


 

[Non-text portions of this message have been removed]

Re: delay time is not reliable

2012-08-31 by englsprogeny1

Steven,

The previous Fuse values were from my ATMega8

Fuse settings for my ATMega16 board are:

Low Byte:
0xFF

High byte:
0x09


--- In AVR-Chat@yahoogroups.com, STEVEN HOLDER <s.holder123@...> wrote:
Show quoted textHide quoted text
>
> What are your fuse settings ?
> 
> Regards
> 
> 
> 
> ________________________________
>  From: englsprogeny1 <englsprogeny1@...>
> To: AVR-Chat@yahoogroups.com 
> Sent: Friday, 31 August 2012, 15:00
> Subject: [AVR-Chat] Re: delay time is not reliable
>  
> 
> Â  
> I have the same issue with a different board and build process.
> 
> I've done this on my ATMega8 board now, building the HEX file using make.
> 
> crystal 8Mhz
> 
> I put the F_CPU value in the makefile as well as the global.h file.
> 
> I program the ATMega8 board by way of ISP then unplug the programmer from the ISP header.
> 
> When I look at the signal, I get between 0.9 and 2.1ms (about)for a call for 5ms.
> 
> When I try 10ms delay, I get between 2 and 4ms delay.
> 
> An interesting note: 
> 
> When I call the microsecond delay I am solid!
> 
> _delay_us(333);
> 
> Whatever value I tell it to wait, it is exact!
> 
> :)
> 
> So milliseconds does not work but microseconds does....
> 
> --- In AVR-Chat@yahoogroups.com, John Samperi <samperi@> wrote:
> >
> > At 03:26 PM 31/08/2012, you wrote:
> > >2.  F_CPU is set correctly
> > >#define F_CPU          7372800
> > 
> > But is this what you have in the project settings? _delay_ms is pretty
> > accurate if it has the correct information.
> > 
> > Are you using your own makefile or the Studio generated one?
> > 
> > 
> > 
> > Regards
> > 
> > John Samperi
> > 
> > ********************************************************
> > Ampertronics Pty. Ltd.
> > 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> > Tel. (02) 9674-6495
> > Website http://www.ampertronics.com.au
> > *Electronic Design * Custom Products * Contract Assembly
> > ********************************************************
> >
> 
> 
>  
> 
> [Non-text portions of this message have been removed]
>

Re: [AVR-Chat] Re: delay time is not reliable

2012-08-31 by John Samperi

At 12:00 AM 1/09/2012, you wrote:
>When I look at the signal, I get between 0.9 and 2.1ms (about)for a 
>call for 5ms.
>
>When I try 10ms delay, I get between 2 and 4ms delay.

hmm something is fishy, maybe your test equipment? :-)

As you have tried different boards and they were working ok
before that seems to be the most likely problem.

I'm assuming here that your boards are reasonably made with proper
supply bypass and steady supply.

The project I'm currently working on has a 70ms and a 50ms delay and
it is very accurate.

Not trying to teach you anything of course but something like this
could be handy to check your setup.
I have never used anything but the Studio generated makefile so the
F_CPU is entered in the project settings.

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
         DDRD |= (1 << PD4);

         for( ;; )
         {

     PORTD |= (1 << PD4);
     _delay_ms(500);             //Max 65.535 seconds with latest winAvr
         PORTD &= ~(1 << PD4);
     _delay_ms(500);
         }
}




Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: delay time is not reliable

2012-08-31 by englsprogeny1

John, you said "Not trying to teach you anything of course"

I've been watching you in this group for years.  You could teach me a lot! AND I would willingly learn!

:)

Anyways, I must have something wrong with my test equipment.

I will try my (non-PC-based scope) tomorrow.

Many thanks!





--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
Show quoted textHide quoted text
>
> At 12:00 AM 1/09/2012, you wrote:
> >When I look at the signal, I get between 0.9 and 2.1ms (about)for a 
> >call for 5ms.
> >
> >When I try 10ms delay, I get between 2 and 4ms delay.
> 
> hmm something is fishy, maybe your test equipment? :-)
> 
> As you have tried different boards and they were working ok
> before that seems to be the most likely problem.
> 
> I'm assuming here that your boards are reasonably made with proper
> supply bypass and steady supply.
> 
> The project I'm currently working on has a 70ms and a 50ms delay and
> it is very accurate.
> 
> Not trying to teach you anything of course but something like this
> could be handy to check your setup.
> I have never used anything but the Studio generated makefile so the
> F_CPU is entered in the project settings.
> 
> #include <avr/io.h>
> #include <util/delay.h>
> 
> int main(void)
> {
>          DDRD |= (1 << PD4);
> 
>          for( ;; )
>          {
> 
>      PORTD |= (1 << PD4);
>      _delay_ms(500);             //Max 65.535 seconds with latest winAvr
>          PORTD &= ~(1 << PD4);
>      _delay_ms(500);
>          }
> }
> 
> 
> 
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>

Re: delay time is not reliable

2012-09-01 by englsprogeny1

My good old Tektronix 2232 proved your theory correct!

And to think that was going to get rid of it...

I guess that I need to be careful with PC based test equipment.


Thanks again, John!



--- In AVR-Chat@yahoogroups.com, "englsprogeny1" <englsprogeny1@...> wrote:
Show quoted textHide quoted text
>
> 
> John, you said "Not trying to teach you anything of course"
> 
> I've been watching you in this group for years.  You could teach me a lot! AND I would willingly learn!
> 
> :)
> 
> Anyways, I must have something wrong with my test equipment.
> 
> I will try my (non-PC-based scope) tomorrow.
> 
> Many thanks!
> 
> 
> 
> 
> 
> --- In AVR-Chat@yahoogroups.com, John Samperi <samperi@> wrote:
> >
> > At 12:00 AM 1/09/2012, you wrote:
> > >When I look at the signal, I get between 0.9 and 2.1ms (about)for a 
> > >call for 5ms.
> > >
> > >When I try 10ms delay, I get between 2 and 4ms delay.
> > 
> > hmm something is fishy, maybe your test equipment? :-)
> > 
> > As you have tried different boards and they were working ok
> > before that seems to be the most likely problem.
> > 
> > I'm assuming here that your boards are reasonably made with proper
> > supply bypass and steady supply.
> > 
> > The project I'm currently working on has a 70ms and a 50ms delay and
> > it is very accurate.
> > 
> > Not trying to teach you anything of course but something like this
> > could be handy to check your setup.
> > I have never used anything but the Studio generated makefile so the
> > F_CPU is entered in the project settings.
> > 
> > #include <avr/io.h>
> > #include <util/delay.h>
> > 
> > int main(void)
> > {
> >          DDRD |= (1 << PD4);
> > 
> >          for( ;; )
> >          {
> > 
> >      PORTD |= (1 << PD4);
> >      _delay_ms(500);             //Max 65.535 seconds with latest winAvr
> >          PORTD &= ~(1 << PD4);
> >      _delay_ms(500);
> >          }
> > }
> > 
> > 
> > 
> > 
> > Regards
> > 
> > John Samperi
> > 
> > ********************************************************
> > Ampertronics Pty. Ltd.
> > 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> > Tel. (02) 9674-6495
> > Website  http://www.ampertronics.com.au
> > *Electronic Design * Custom Products * Contract Assembly
> > ********************************************************
> >
>

Re: [AVR-Chat] Re: delay time is not reliable

2012-09-01 by John Samperi

At 12:24 PM 1/09/2012, you wrote:
>My good old Tektronix 2232 proved your theory correct!

Great. :-)


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.