[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RE: [avr-gcc-list] buggy variable naming with underscores
From: |
Jamie Morken |
Subject: |
Re: RE: [avr-gcc-list] buggy variable naming with underscores |
Date: |
Mon, 14 Mar 2005 17:02:21 -0800 |
Hi Ben,
----- Original Message -----
From: Ben Mann <address@hidden>
Date: Monday, March 14, 2005 4:34 pm
Subject: RE: [avr-gcc-list] buggy variable naming with underscores
> Hi Jamie,
>
> Um, the code below would indeed cause the problem you mention.
> Instead try
>
> ADChannels[nNextAdc]=(((u16)ht)<<8)|lt;
>
> And it should work properly, requiring
>
> printf("x: %i\r\n", (int)(ADChannels[0]);
>
> to print out channel 0.
That is what the code was originally, and all the channels were shifted one bit!
cheers,
Jamie
>
> If you work through your code you will see that on the next call
> to the
> signal after setting nNextAdc=0, you will be writing
> ADChannels[-1]
> which is going to scribble memory somewhere; it also explains why
> you are
> then reading index -1 to get the byte.
>
> Ben Mann
>
> --snip!--
>
> 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
> shiftedone 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!)
>
>
>
>