Welcome in the forum.
2's complement are "normal" integers. You might need a sign expand, but usually your potentiometer values are positive.
You should convert (assign to) your 24-bit value to a 32-bit integer.
Your variable "After_Filter" is unsigned, but your selected format %i is for signed. Look here for format specifiers.
What I am not quite sure of: the filter is for filtering frequencies, but your potentiometer does not deliver one, but pure DC.
Wouldn't it be more appropriate to use a (sliding) average?
PS: Where in Germany are you located? I live near Bremen
Thanks for your comment, Bob !
I was trying different kind of input, but moved to the potentiometer in the hope of understanding the Filter output better. I know the input exactly, so I thought I could understand this 2's complement representation... not quite a success yet !
Regarding the output, it ranges from 0 to 255 (I'm starting with 8 bit values), but from 27 (around 2,5 v in potentiometer) it jumps directly to 228 ! This drives me crazy !!!
I noticed this %i after posting and changed it to %u .. no difference in my case.
PS : I live in Thuringia.. in the forest there :-)
PPS: I follow the forum since couple of weeks now. You do great help here *thump up*
Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
There are some hints in the datasheet showing that polling and DMA may not work as expected, reading off the data may clear the data ready flag etc.
You read the filter into an 8bit unsigned but the result is signed which causes the jumps in the output. To reduce noise, use the buffered reference option, afaik the required cap is already on your board at pin P0_3, please check with schematics.
Check if you run your board at 5V as you declared in the system view. This information is taken to calculate the count to mV correctly.
By using the signed data types (int8) or (int8_t) the jump is still at 2.5V , but it becomes to the most negative value (from 27 to -28). So my problems are: the jump, and the overall resolution is still much lower than 8 bit ! all the values I got at the Filter's output are between -28 to +27 !!
Another thing: when I used
I have a jump from 55 to -56 , but even Potentionsmeter (the result of ADC conversion) is jumping also at 2.5V to -2.5V , while the input range is still from Vssa to Vdda , and reference is still at Internal Vdda/4. I only changed GetResult from 32 to 8, and it doesn't accept the range 0 to 5 anymore .. but takes it as from -2.5V to +2.5V !
It seems that I missed some basics in the ADC, but I simply couldn't find the help in ADC datasheet.. or my head is simply early in the holiday !
Sorry for bothering !
Thank you for helping. It was all about the data types.
Beside that, there was a problem with the reference. After deleting the OpAmp from the Code Example, PSoC Creator kept considering it somehow; in one warning it was still showing it. I needed to start a blank project to overcome this.