Fri, 15 Apr 2005 17:05:31 +0200
|
This may not have the merit of anything new, but I
do not want to resist showing you the following from
HTTP://Lists.GNU.org/archive/html/avr-gcc-list/2005-03/msg00228.html :
"[..]
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..
[..]"
|
|
|