How can I skip delay and see stopwatch ?

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

On debugging, how can I skip _delay(2000); and check the stopwatch ?

Put a break or Step out ?

PORTF = 0xFF;
_delay_ms(2000);
PORTF = 0;

it stops until here :

__builtin_avr_delay_cycles(__ticks_dc);

and I can't continue...

The point is, I want to fast forward the code and passing between function, is that possible ? how to do it ?

Thanks

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

No, it does not stop. It just takes a very LONG time.

The trick is to compile conditionally. e.g.

#if defined(SIMULATING)
#define DELAY_MS(n)    NOP()
#else
#define DELAY_MS(n)    _delay_ms(n)
#endif

You often do this sort of thing with diagnostic PRINTF() statements.

Obviously the cycle counting goes wrong because you have deliberately avoided the delay cycles.

David.

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

after that I use "Step Into" F11 ?
I can see the cycle counter is running but only on micro seconds, will take me ages to wait for 2000 ms..
I put the code you gave me on top, I didn't see a response ?

thanks

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

I put

#if defined(SIMULATING)
#define DELAY_MS(n)    NOP()
#else
#define DELAY_MS(n)    _delay_ms(n)
#endif

after or before :

#define F_CPU 16000000UL  // 16 MHz
#include 
#include 

?

I tried to use breakpoint, take me so long for_delay_ms(2000)

thank you

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

You can put it wherever you want.

Just imagine you are the preprocessor/compiler and trace it with pencil and paper. Remember that both preprocess and compile are single-pass operations.

So you need to #define SIMULATING before you #define DELAY_MS()

and any references to DELAY_MS() must come after this.

Seriously. Try things for yourself. Then ask questions.

David.

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

I tried it already, but it's not "nop()" for _delay_ms()....
do I miss something here ?

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

here's a complete example:

#include 
#include 

//#define SIMULATING
#ifdef SIMULATING
#define _delay_ms(n) (void)0
#else
#define _delay_ms(n) _delay_ms(n)
#endif

int main(void) {
	DDRB = 0xFF;
	while(1) {
		PORTB ^= 0xFF;
		_delay_ms(100);
	}
}

Remove the "//" from the SIMULATING definition when building for simulation.

If you are real clever you'll work out how to use AS6's ability to define build configurations and to pass -D's in order to be able to have "Debug", "Release" and "Simulation" builds. The latter passing a -DSIMULATING.

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

Try this then:

#if defined(SIMULATING) 
#define DELAY_MS(n)    do {} while (0)
#else 
#define DELAY_MS(n)    _delay_ms(n) 
#endif 

The stopwatch will not reflect time for the _delay_ms() calls, but that is something you will just have to accept.

EITHER simulated times for _delay_xx() calls will be reflected in the stopwatch but the code takes ages to execute.

OR wrong and much too short times for _delay_xx() calls will be reflected in the stopwatch but the code executes reasonably fast.

No other combinations exists. Specifically you can NOT get accurate stopwatch data AND bearable _delay_xx() calls. You are between a brick and a hard place. Pick the one that hurts least.

[I will not answer any follow up questions in this thread for 24 hours, unless it for once is a well contemplated and thoroughly worked through follow up.]

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Just in passing, another possible solution:

void delay_ms(int n) {
#ifndef SIMULATING
  while(n--) {
   _delay_ms(1);
  }
#endif
}

now use delay_ms() in place of _delay_ms(). This has the added benefit that you can also delay_ms(some_variable).

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

it works clawson, thank you very much for helping...
so if I want to burn the chip I need to put comment on

#define SIMULATING
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how can I display two ports for example PORTA and PORTB at once on debugging ? thanks

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

What have YOU tried? A read of the help?

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

Ok, I'll have a look..
thanks kartman

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

Quote:

how can I display two ports for example PORTA and PORTB at once on debugging ?

For once that's a very good question! In their wisdom it seems Atmel have made yet another retrograde step going from AS4 to AS6. In AS4 it was easy to see multiple peripheral registers at once but unless I'm missing something it seems that in AS6 there is only one "register pane" and it only shows the registers of one peripheral at a time (PORTA and PORTB are two separate peripherals).

AS4 even had a number of "views" you could cycle through. AS6 has lost that too.

Attachment(s): 

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

clawson wrote:
In AS4 it was easy to see multiple peripheral registers at once but unless I'm missing something it seems that in AS6 there is only one "register pane" and it only shows the registers of one peripheral at a time (PORTA and PORTB are two separate peripherals).
You can select multiple peripherals in the upper pane in the usual Windows ways (e.g. by holding CTRL).

Stefan Ernst

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

Oh right - I love "intuitive" interfaces!

I really think Atmel would benefit from adding something like "Ctrl/Shift click to select multiple" to the top of that dialog.

EDIT: OK not "Shift" then - it doesn't even conform to CUA. You can Ctrl-click for multiple but Shift-click does not work there - Ye Gods!

EDIT2 And before anyone asks: The manual page for "I/O View" in AS6(*) makes no mention of Ctrl_click for multiple selection.

(*) http://www.atmel.no/webdoc/atmel...