Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] (Newbie)2.Delay function not working as required [RSS Feed]

#1 Dec. 8, 2005 01:19:01

Sumeet P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


HiWe tried to put delay in our program but it is not that reliable,When we dofor(char i=0x00;i<100;i++)delayms(100);The output which we get is not 100*100ms but something unexpected. The
variable i is not used anywhere else in program. Is it that the
optimisation is causing problem, if yes please tell how to remive it.ThanksSumeet_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Dec. 8, 2005 02:41:24

Parthasaradhi N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


Hello,What is the code for delayms function? If you have a doubt that optimisation is causing a problem,  you could disable optimisation, recompile and check the output (delay time).RegardsNayaniSumeet Pal Singh <>wrote:HiWe tried to put delay in our program but it is not that reliable,When we dofor(char i=0x00;i<100;i++)delayms(100);The output which we get is not 100*100ms but something unexpected. The variable i is not used anywhere else in program. Is it that the optimisation is causing problem, if yes please tell how to remive it.ThanksSumeet_______________________________________________AVR-GCC-list mailing
listAVR-GCC-l***@*ongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-listYahoo! ShoppingFind Great Deals on Holiday Gifts atYahoo! Shopping_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Dec. 8, 2005 06:00:42

James W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


I think you should post your delayms() timer code here.. I'm sure someone will
be able to help,



On Wed, 7 Dec 2005 18:38:57 -0800 (PST)
Parthasaradhi Nayani <> wrote:

> Hello,
> What is the code for delayms function? If you have a doubt that
> optimisation is causing a problem, you could disable optimisation,
> recompile and check the output (delay time).
>
> Regards
> Nayani
>
>
> Sumeet Pal Singh <> wrote: Hi
> We tried to put delay in our program but it is not that reliable,
> When we do
> for(char i=0x00;i<100;i++)
> delayms(100);
>
> The output which we get is not 100*100ms but something unexpected. The
> variable i is not used anywhere else in program. Is it that the optimisation
> is causing problem, if yes please tell how to remive it.
>
> Thanks
> Sumeet
> _______________________________________________
> AVR-GCC-list mailing list
> AVR-GCC-l***@*ongnu.org
>http://lists.nongnu.org/mailman/listinfo/avr-gcc-list>
>
>
>
> ---------------------------------
> Yahoo! Shopping
> Find Great Deals on Holiday Gifts at Yahoo! Shopping


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Dec. 8, 2005 10:17:50

n.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


Hi,Why don’t you use the avr-libc
delays, _delay_ms()?I have myself used it in a for-loop to
produce long s-range delays in some project. For this long delays I guess
though you should use timers and interrupts./niklo From:
[mailto:On Behalf OfSumeet Pal SinghSent:den 8 december 2005 01:53To:avr-gcc-l***@*ongnu.orgSubject:
(Newbie)2.Delay function not working as required HiWe tried to put delay in our program but it is not that reliable,When we dofor(char i=0x00;i<100;i++)delayms(100);The output which we get is not 100*100ms but something unexpected. The variable
i is not used anywhere else in program. Is it that the optimisation is causing
problem, if yes please tell how to remive it.ThanksSumeet_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 Dec. 8, 2005 15:18:18

Sumeet P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


The delay function is the regular one from <avr/delay.h>I havce not written the delay.the thing is thatdelayma(100);delayma(100);//Write this 100 timesgives a delay of 100*100ms.butfor(char i=0;i<100;i++)delayma(100);does not, that is where the problem is coming.bbyeOn 12/8/05,Alexei Chetroi<> wrote:On Thu, Dec 08, 2005 at 09:10:26AM +0100, niklo wrote:> Date: Thu, 8 Dec 2005 09:10:26 +0100> From: niklo <>> To: 'Sumeet Pal Singh' <>,avr-gcc-l***@*ongnu.org> Subject: RE: (Newbie)2.Delay function not working as required>>    Why don't you use the avr-libc delays, _delay_ms()?>>    I have myself used it in a for-loop to produce long s-range delays in some>    project. For this long delays I guess though you should use timers and>    interrupts.  Also check application note AVR133: Long Delay Generation Using theAVR Microcontroller onhttp://www.atmel.com/dyn/products/app_notes.asp?family_id=607  Best wishes--Alexei ChetroiSmile... Tomorrow will be worse. (c) Murphy's Law_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#6 Dec. 8, 2005 15:49:20

Jahagirdar G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


Hi,The unexpected delays are basically
because of some ISR running in between, Is you delay function is just a loop
based or interrupt based? I think it is not interrupt based. Just try disabling
interrupts just before calling the delay function and enabling after the
function call. If it works better then I suggest you to write a good interrupt
based delay routine. Note that the interrupt I was talking about is timer interrupt
raised by internal timer of AVR.-GopalFrom:
[mailto:On Behalf OfSumeet Pal SinghSent:Thursday, December 08, 2005
6:23 AMTo:avr-gcc-l***@*ongnu.orgSubject:
(Newbie)2.Delay function not working as required HiWe tried to put delay in our program but it is not that reliable,When we dofor(char i=0x00;i<100;i++)delayms(100);The output which we get is not 100*100ms but something unexpected. The variable
i is not used anywhere else in program. Is it that the optimisation is causing
problem, if yes please tell how to remive it.ThanksSumeet_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#7 Dec. 8, 2005 16:51:20

Alexei C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


On Thu, Dec 08, 2005 at 12:29:56PM +0000, Sumeet Pal Singh wrote:
> Date: Thu, 8 Dec 2005 12:29:56 +0000
> From: Sumeet Pal Singh <>
> Subject: Re: (Newbie)2.Delay function not working as required
>
> The delay function is the regular one from <avr/delay.h>
> I havce not written the delay.
>
> the thing is that
> delayma(100);
> delayma(100);
> //Write this 100 times
> gives a delay of 100*100ms.
>
> but
>
> for(char i=0;i<100;i++)
> delayma(100);
>
> does not, that is where the problem is coming.

I think that compiler optimize your cycle away, since variable i is
not used in its body. Whether turn off optimization or use application
note avr133 aproach.

Try to check with "avr-objdump -h -S program.elf" to see what is actually
happening.

Best wishes

--
Alexei Chetroi

Smile... Tomorrow will be worse. (c) Murphy's Law


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#8 Dec. 8, 2005 17:25:55

Christopher X.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


On Thu, 8 Dec 2005, Sumeet Pal Singh wrote:

> We tried to put delay in our program but it is not that reliable,
> When we do
> for(char i=0x00;i<100;i++)
> delayms(100);

I've done almost all my AVR programming using AvrX, a simple real-time OS
developed by Larry Barello (Hi Larry!), and free from www.barello.net .

It may seem like overkill, but I've found especially when delays are needed,
it simplified things. It providers timers that are quite accuarte.


==========================================================
Chris Candreva -- -- (914) 967-7816
WestNet Internet Services of Westchesterhttp://www.westnet.com/_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#9 Dec. 8, 2005 17:41:07

Dave H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


Hi Sumeet,

On 12/8/05, Sumeet Pal Singh <> wrote:
> The delay function is the regular one from <avr/delay.h>
> I havce not written the delay.

Since you're not showing us the actual code that you used (since the
delay function inside <avr/delay.h> is called _delay_ms not delayma)

and since you've said that repeating the call to delay 100 times gives
the correct result, then I'd speculate that you have a semicolon at
the end of your for statement, something like this:

> for(char i=0;i<100;i++);

--
Dave Hylands
Vancouver, BC, Canadahttp://www.DaveHylands.com/_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#10 Dec. 8, 2005 17:47:11

Alex W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] (Newbie)2.Delay function not working as required


Hi,

> for(char i=0;i<100;i++)
> delayma(100);

you should try:


for(char i=0;i<100;i++)
{
delayms(100);
}





_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] (Newbie)2.Delay function not working as required [RSS Feed]

Board footer

Moderator control

Enjoy the 22nd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support