why this is not working ?

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

hello, i'm a little bit of shame, because i have already ask a question for the third time in a short period.

but i really appreciate your help. yes

 

i see some very strange things, what i don,t understand. in my eyes it looks verry simple,....but its not.

i tested whit the simmulator.

why is the first "if" not working whyle the second one is OK.

#define F_CPU 1000000UL

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

int counter;

int main(void)
{
	for(;;)
	{
		DDRC = 0b11111111;
		for (counter=0; counter<8; counter++)
		{
			if (counter == 1)  //THIS ONE IS NOT WORKING ?????????????????????????
			{
				PORTC |= (1 << PINC0); // bit uit = 1
			}
			if (counter == 7) // THIS IS WORKING ???????????????????????????
			{
				PORTC &= ~(1 << PINC0); // bit uit = 0
			}
		
		}
	}
	
}




 


 
Last Edited: Sat. Jun 1, 2019 - 09:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do you KNOW it is not working? That code is going to be switching bit 0 of PORTC on and off 10,000's of times per second.  That is so fast that it'll just look like it is half on all the time? Or were you observing using a scope or logic analyser? (Which would be the only way to catch activity) 

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

i only checked in the simulator, and there i did not see the pointer jump into the "if (counter == 1) routine.

so you think the speed is to high ? i have the speed bring down anyway. i'm gonna test that.


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

Simulator operation will not depend on the speed.

 

Guess: Maybe it has been implemented as

 

if (counter == 1)  PORTC |= (1 << PINC0);

so there is no second line to step into? 

 

Try looking at the disassembed view. You can also put a breakpoint on the second if() statement, then look at the state of the pin in I/O view. A break there shows you the state of things BEFORE the the line with the break is executed. Bet it shows HIGH.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sat. Jun 1, 2019 - 08:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes that is working, i'm gonna test more tomorrow.

thanks a lot.

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

Again guessing it's an AVR, nothing to do with Studio, moving to AVR forum.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

John  he most recently said the issue was in the simulator so personally I'd have said this possibly was about Studio

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

OK sorry, back to Studio then.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

i did some testing,.....en of course it was working in the original prog in my first post.

the mistake i made was that i only watched to the steps of the pointer, and their i did not see the pointer past the "(if counter == 1)"

but now i watched in de I/O screen (debug -> windows -> I/O) and see the pin toggling.

 

thanks again.

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

Perhaps have a read of this tutorial I wrote...

 

https://www.avrfreaks.net/forum/...

 

Among other things it explains about the yellow arrow jumping about.

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

i read this, its a little bit complicate for me. so i have to read it more than once.

but it explains why the yellow pointer not always make the moves that i expected.

 

i appreciate it a lot, that you take the time to wrote this turtorial. it helps people like me (starters) to understand how things work.

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

f

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Mon. Jun 24, 2019 - 09:13 AM