Hi to you all,I've another post on the forum (here's the link Process ADC data, moved by DMA, using CMSIS DSP: what's the right way? ), but since I think I made some small steps forward I felt I could be a little more specific. I hope this won't be a problem.
Actually I'm trying to extract the MAX from a q31_t (Note that: typedef int32_t q31_t) array filled by the ADCHS in my LPC4370 lpc link2 board, using the arm_max_q31 function (here for reference: Maximum). The problem is that the 12bit ADC supplies data in Two's Complement format, but the library is misunderstanding it (ora at least I think so). For instance:
111111111111
Should be
-1
but actually is read by the CMSIS Function as
4095
and therefore is always recognized as the MAX value.
Do I need to manually convert all the samples one-by-one? This seems to be extremely slow, and since I've some real-time requirements I need the fastest way to do this maths.Any help would be highly appreciated since I'm stuck here.
Thanks,Andrea
It's interesting that the fake overflow happened only whit a subset of the (maximized) samples.
It occurred for all the negative values. Those numbers were shifted up to the most significant bit (MSB), and then right shifted by the same amount. When right shifting a signed number, '1's are put in from the left if the MSB is a '1' (or '0s' if it's a '0'). In this way, the numbers you were interpreting as negative, we failing the if statement. The positive numbers shifted left, then right, and were no different than their original number.
A small example. Lets pretend you had 4 bit input numbers, and we're shifting up to 8 bit for whatever reason.
positive input example:00000100 (+4). shift left by 4, 01000000 (+64), now shift right by 4, 00000100 (+4)
negative input example00001100 (-4). shift left by 4, 11000000 (-64), now shift right by 4, 11111100 (-4).
Even though I interpreted 00001100 and 11111100 both as -4, a computer would interpret those as 12 and -4 which are clearly different.
Hope this makes sense
Ok, so now I have the whole thing pretty clear. Unfortunately yesterday I found out that I'm still too slow to process the 40msps stream in continuous mode, but this design provided a huge improve compared to the float-ing approach that i described in my previous post. Now I'm gonna update that post!
Thanks again Dan for your support,Abet