TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Proportional Font
Show HTML Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Date: Fri, 15 Apr 2005 17:05:31 +0200
Content-Disposition: inline
From: Paul Colin Gloster <[log in to unmask]>
In-Reply-To: <[log in to unmask]>
Sender: "Team Ada: Ada Programming Language Advocacy (83 & 95)" <[log in to unmask]>
Parts/Attachments: text/plain (32 lines)
This may not have the merit of anything new, but I
do not want to resist showing you the following from
HTTP:// :


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.

u08 lt; 
u08 ht; 
ht=inp(ADCH)& 0x03; 
if (nNextAdc==8) nNextAdc=0;

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.
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..