Wrong ADC values in every other position of the buffer array

Post discussions on projects you are working on
Martyn
Site Admin
Site Admin
Posts: 4246
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong ADC values in every other position of the buffer array

Post by Martyn »

Not sure if this is a clue but

Code: Select all

13344 is 0x3420
8244 is 0x2034
and with this pattern repeating are you walking through the buffer at 8 bits but reading 16 bits each time.
Martyn
Technical Support Manager

bennog
Advanced User
Advanced User
Posts: 153
Joined: Mon Nov 26, 2012 9:16 am
Location: Netherlands

Re: Wrong ADC values in every other position of the buffer array

Post by bennog »

Nice find I did nog look at it in hex values, it looks like you are right, although I would expect garbage on the 2nd wave checked about 40 of the sin wave values and they all have this pattren.

The OP can this probably confir.

Benno

JavaChips
Newbie
Posts: 0
Joined: Wed Jun 01, 2022 5:40 pm

Re: Wrong ADC values in every other position of the buffer array

Post by JavaChips »

Thank you! Your clue was, in fact, exactly where I went wrong. This is actually my first time using JNA, so I had overlooked the part in the documentation that specified how many bits the offset for the memory pointer is when reading an array (as I incremented the index by 1, the offset would be incremented by 8 bits, not 16 bits).

Now that I know why that is happening and what to do to fix it (increment index by 2 every time instead), I realize that this was exactly what I did in the beginning as a "workaround". Little did I know that it was an actual fix.

Also, I originally had thought that deleting those "wrong values" meant I was essentially cutting the sampling rate in half (getting out 5000 samples instead of 10000 samples), but I simply needed to increment through the buffer array differently than how I increment through the output array. So I am now getting 10000 samples as desired, all of which are values that match the inputted waveform.

Much thanks to you two, Martyn and Benno, for helping me out with this.

Best regards,
JavaChips

Post Reply