avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] buggy variable naming with underscores


From: Jamie Morken
Subject: Re: [avr-gcc-list] buggy variable naming with underscores
Date: Mon, 14 Mar 2005 15:55:12 -0800

Hi,

----- Original Message -----
From: Parthasaradhi Nayani <address@hidden>
Date: Monday, March 14, 2005 5:11 am
Subject: Re: [avr-gcc-list] buggy variable naming with underscores

> 
> --- Jamie Morken <address@hidden> wrote:
> 
> > "volatile u08 motor_direction;"
> > 
> > So I changed it to this name:
> > 
> > "volatile u08 motorDirection;"
> > 
> > and it works now. 
> 
> I just can not understand how the compiler
> differentiates between variables with and without
> underscores!!!!!!!!!

It took me a long time to track down, and I found the error.  I was hoping to 
be able to report a snazzy bug, but it is because I wrote to an array out of 
bounds, and I must have corrupted another variable intermittently (for the last 
several years).  I guess changing the name of the variable may have moved it in 
memory!  The code is in the ADC interrupt.

SIGNAL(SIG_ADC) 
{ 
u08 lt; 
u08 ht; 
lt=inp(ADCL); 
ht=inp(ADCH)& 0x03; 
ADChannels[nNextAdc-1]=(((u16)ht)<<8)|lt;       
nNextAdc++;
if (nNextAdc==8) nNextAdc=0;
outp(nNextAdc,ADMUX); 
} 

I try to store the 8 channels into an array but all 8 channels are shifted one 
index in the array when I print them out.
ie.
printf("x: %i\r\n", (int)(ADChannels[0]);

this prints out ADC channel 1 unless I subtract 1 from nNextAdc like above.

so the index 0 is ADC channel 1 instead of ADC channel 0.  So the "solution" I 
used was to write to index -1 to 7, and somehow this corrected the problem, but 
then I was also corrupting other memory I guess! :)  Any sample code that 
continously logs all 8 ADC channels to an array? (without corrupting memory!)

I have a 1 bit offset somewhere I know, but I am not sure where..

cheers,
Jamie

> 
> The under score is not a token to be parsed by the
> compiler.
> 
> Nayani
> 
> 
> 
> 
>               
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Mail - Easier than ever with enhanced search. Learn more. 
> http://info.mail.yahoo.com/mail_250
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]