AVR Delay routing using parameter as delay needed

Go To Last Post
65 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
sparrow2 wrote:

Point take that is only a problem on the newer once. (and we all assume that a read from undefined flash just is remapped).

 

I don't assume that.  Not only have I read about other people's tests, I've tested flash address wraparound on several tiny/mega AVRs.  It's also well documented (search for " --pmem-wrap-around ")

In the usual case with power of two flash, I believe that wraparound is implicitly guaranateed.

The datasheet spcifies what bits of Z are used: just enough to cover the entire range.

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I also read somewhere here that:

--pmem-wrap-around  

Don't always work. But I can't remember if it was a HW error or a compiler error.

Also on of the chips (I think a 16k flash version) always push a illegal return addr. for (r)call ! so that for will (has to do wrap all the time).

 

I have not seen anywhere that Atmel has guarantied wrap to work other than for 8k chips. 

 

Add

But this is about a SW delay OP for some reason want to do. 

I wanted OP to do it him self but now it's solved.

     

Last Edited: Thu. Apr 16, 2020 - 05:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
Here's how I did cycle-accurate delays in one project:

I've lost track here.  Your solution, joey, is a build-time solution, right?  Didn't OP want run-time?

robydream wrote:
 I want to write delay routine that is accepting delay time

 

I thought that the "newer" GCC facilities were cycle-accurate?

 

If there is a reasonable range of values, couldn't a Duff's device-type-thing be used?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

I thought that the "newer" GCC facilities were cycle-accurate?

In C, via __builtin_avr_delay_cycles, yes.  It's a GCC extension.

 

For my purposes, I needed assembly language, and I needed something that would use a minimum of code space via a (re)callable subroutine.  Looks like the OP wants assembly language, too.

theusch wrote:

Didn't OP want run-time?

Where did he say that, exactly?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Didn't OP want run-time?

joeymorin wrote:
Where did he say that, exactly?

Isn't that what "using parameter as delay needed" (in the title) means ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Isn't that what "using parameter as delay needed" (in the title) means ?

I don't see how 'runtime' is implied.  Macros take parameters, too.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fair point - and it's the way the 'C' delay works, too.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

Where did he say that, exactly?

I quoted, from #1.  At least that was the way I took it.

"  I want to write delay routine that is accepting delay time ..."

And the "not working" code immediately following sets a "parameter" and then jumps to the "routine".

 

So you can't use _builtin_xxx except in a C source?  [not a GCC person]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Fri. Apr 17, 2020 - 01:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

I don't see how 'runtime' is implied.  Macros take parameters, too.

C'mon; you are stretching things now, aren't you?  Are you arguing that there is, then, no difference between e.g. delay routines that are expanded at build time such as your example code, and those that pass a parameter at run-time?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Are you arguing that
Of course not.  Why be specious?  This is irrelevant to the thread.  If the OP can achieve what they're looking for by extracting from my or your or anyone else's posts, what difference does it make?

 

theusch wrote:
C'mon; you are stretching things now, aren't you?
If you say so.

 

Macros have parameters, as you well know, and as has already been established in this thread.  A suggestion was made in #41 to examine and emulate _delay_nn macros' code generation, but you don't have a problem with that.

 

theusch wrote:
So you can't use _builtin_xxx except in a C source?  [not a GCC person]
Possibly, but none that I know of.  It is a C extension.

 

theusch wrote:
I quoted, from #1.  At least that was the way I took it.

"  I want to write delay routine that is accepting delay time ..."

Have you >>looked<< at the code in #46?  It is a macro, yes, but it generates a call to a subroutine.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

Have you >>looked<< at the code in #46?  It is a macro, yes, but it generates a call to a subroutine.

 

Perhaps I'm getting too old, or the virus is affecting me.

joeymorin wrote:

Use like this:

	delay_c	46

 

is, to me, at build time.  It cannot accept a parameter at run time...let's say 8-bit (for convenience) ADCH, can it?

 

Why am I having such a hard time grasping how

 

joeymorin wrote:

Of course not.  Why be specious?  This is irrelevant to the thread.  If the OP can achieve what they're looking for by extracting from my or your or anyone else's posts, what difference does it make?

is relevent to the thread?  Are you saying that you code can take, e.g. the value in ADCH at run time after a conversion and produce a proportional delay?  I thought that is what OP was asking for in #1.  Which post can be extracted to produce this varying ADCH-proportional delay?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Why am I having such a hard time grasping how
How should I know?

 

The first (and only) mention of 'runtime' was by you.

 

The first (and only) mention of ADCH was by you.

 

theusch wrote:
Perhaps I'm getting too old, or the virus is affecting me.
Look at the macro in #46 again.  It generates two instructions.  An 'ldi' and an 'rcall'.  If you wish, you can rcall delay_loop yourself, having arranged to load tmp with whatever value you wish, perhaps with the contents of ADCH.

 

The code in #46 was offered with:

Here's how I did cycle-accurate delays in one project:

No other claims were made.

 

I fail to understand the value of this diversion.  It is not helping the OP.  Who, as you can see, hasn't been here for a while.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Fri. Apr 17, 2020 - 09:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Boy, I must have tickled your isolation bone.  OK, tell me the exact wording to distinguish between build-time and runtime?  Call them case A and case B.  I read that OP wanted case B.  Did you read that differently?

 

The answers to this might be important, as it may well be the niggle.

joeymorin wrote:

The first (and only) mention of ADCH was by you.

And that was a bad example to make it clear as an example of a runtime/dynamic/not-the-same-value-every-time ?

joeymorin wrote:

If you wish, you can rcall delay_loop yourself, having arranged to load tmp with whatever value you wish, perhaps with the contents of ADCH.

I'm very confused again -- no, you cant pass that and have your macro lines such as

.elseif \cycles > (((3 * 256) + 7) + 2)	

  work.  How?  "cycles" is ADCH at build time when the macro is expanded.  How do you know is ADCH is less than 0 or greater than a million?  Won't ou be working with the I/O address at this time?

 

joeymorin wrote:
I fail to understand the value of this diversion.  It is not helping the OP. 

Who asked for run-time delay, and you gave build-time.  And no, substituting ADCH value as "cycles" ain't gonna carry out your statements.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't quite figure out why this is a bone you can't seem to let go of, but whatever gets you through the day...

 

theusch wrote:
Who asked for run-time delay
You've failed to convince me.  But this is a fun game.

 

theusch wrote:
How?
Never said.

 

Did say:

joeymorin wrote:

If you wish, you can rcall delay_loop yourself, having arranged to load tmp with whatever value you wish

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Pages