AVR Studio 4 Variable watch error

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
russ nagel
 
Posts: 18
Joined: Fri Mar 07, 2008 9:10 pm

AVR Studio 4 Variable watch error

Post by russ nagel »

I am trying to put a variable in my watch list. When I add a variable I want to watch in the Value column I get "Location not valid". This happens with two of my variables, one variable work fine though. Does anybody have any ideas on why this is happening?

Russ

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Post by Franklin97355 »

Could you post some code so someone could see what it is you are talking about. Are the variables global or part of a subroutine, etc?

User avatar
russ nagel
 
Posts: 18
Joined: Fri Mar 07, 2008 9:10 pm

Post by russ nagel »

Here's the code. I thought it would be a rather common error message. I am learning the details of debugging, in this environment, for the first time. The code isn't very elegant, I shouldn't be showing it to anybody. The code is supposed to count the number of times a button is pushed, then flash an LED for the number of pushes. I know there are plenty of ways to do this, but I am just getting reaquainted (after 15 years) with this type of programming. I am using an attiny45, I don't know if any of the pins can be configured at interrupts. I haven't looked into that yet, maybe in version 2.0!



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

int count_the_pushes (int numberofpushes);
int increment_timer (int numberoftimesegments);
void display_the_count (int numberofblinks);

int main (void)
{
int timesegments = 0;
int pushcount = 0;
int temp;
DDRB = 0b0001000;
for ( ;1==1; )
{
temp = (PINB & 0x08);
if (temp ==0)
{
pushcount = count_the_pushes (pushcount);
timesegments = 0;
}
else
{
timesegments = increment_timer (timesegments);
}
if (timesegments == 20)
{
display_the_count (pushcount);
timesegments = 0;
}
}
return 1;
}

int count_the_pushes(int pc)
{
return pc=pc+1;
}

int increment_timer (int tc)
{
_delay_ms(250);
return tc=tc+1;
}

void display_the_count (int pc)
{
for (int i=1; i<pc; i++)
{
PORTB = 0x10;
_delay_ms(500);
PORTB = 0x00;
_delay_ms(500);
}
}



The watchlist will display the variable pushcount, but it doesn't like the variables temp or timesegments for those variables under the Values column (in the watchlist) it says "Location not valid".

It's probably something that is going to be embarrasing, but i'm blind to it at the moment.

Russ
[/i]

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Post by mtbf0 »

pushcount is global and is allocated at load time.

the other two variables are local to main and will be allocated on the stack when main runs. perhaps if you add them to your watchlist after entering main.

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Post by mtbf0 »

...or make temp and timesegments global.

User avatar
russ nagel
 
Posts: 18
Joined: Fri Mar 07, 2008 9:10 pm

Post by russ nagel »

Thanks

I moved the declaration of all variables outside of main to make them global and that solved the problem. I still don't understand how pushcount seemed to work fine, but temp and timesegments didn't work when they were all declared inside main before I made the change.

I also have a compiler warning that goobers up the simulation when I run it on Studio 4. The error message is this:

c:/winavr-20071221/bin/../avr/include/util/delay.h:85:3: warning: #warning "F_CPU not defined for <util/delay.h>"

I have commented all the delays out of the program and the simulation works fine. I remember in Smileys book he said something about not using delays in the simulator. I haven't tried running the program in the circuit yet. Time to wake up the kids.

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Post by mtbf0 »

I still don't understand how pushcount seemed to work fine, but temp and timesegments didn't work when they were all declared inside main before I made the change.
oops. i misread your code. i don't get it either. lucky guess based on incorrect data. too bad that doesn't happen more often.

cybertron
 
Posts: 1
Joined: Mon Jan 12, 2009 12:19 pm

Re: AVR Studio 4 Variable watch error

Post by cybertron »

This is caused by the optimizer. Change the optimisation level of the compiler, so it will keep all variables.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”