The output of the Filter is a signed value (+/-), but DAC accepts only uint8, for that reason the output of the Filter has to be shifted to produce only positive values in 0-255 range.
"For me, the binary should be inverted ( the 0s become 1s and the 1s become 0s) and then summed by 1."
This is perfectly right for negative numbers.
The filter component does work with negative values. The conversion was made to ensure that the result is always >= 0 because the values were sent to the DAC which does not accept negative values.
"How can I convert a non 2 complement's number to a 2 complement's number in PSoC 5LP?"
A non 2 complement number is an uint which you may always assign to an int of bigger size which then will be treated as a 2's complement number. The underlying C-compiler is GCC, so there is (regarding this point) nothing special to PSoCs, you may consult any (modern) C-manual to check for conversions.
But in the case of filter all the variables already are uint8 and they are 2 complement.
My intention is to get the signal from Channel A, made some processing ( pretty basic actually) and send It to Channel B.
I am doing It by C/C++ code, but I don't know how to pass the one way to another. Could you give some (very short) example?
Data transfer can be done using DMA or with the provided APIs for the filter.
Sorry, But when I said "pass" I was talking about converting. Let's suppose that I want to make an offset after Channel A, then It will be the input for Channel B. Is the following code correct? ( Ignore the filter effects on Channel A and Channel B in this moment, because It is not the focus now).
uint8 read = Filter_Read8(Filter_CHANNEL_A+128u) ;
uint8 offset = 50;
read = Filter_Read8(Filter_CHANNEL_B) + 128u;
I wrote another code, but this time all the operations already are made in 2 complement so It wasn't needed to convert the filter signal.
Thanks for the help!
uint8 read = Filter_Read8(Filter_CHANNEL_A+128u) ; You do not need to add 128!!!
read+=offset may lead to a false result when read was > 77
read = Filter_Read8(Filter_CHANNEL_B) + 128u; should be called only after a value has been calculated, so poll the status register of the filter. Again, why are you adding 128?? That has been done only in the DAC example to adjust the output range of the filter to the input range of the DAC.
There is no need to "convert" the 2's complement numbers, they are already valid 8-bit integers. When interpreting as int8 they are negative numbers when bit 7 is set, all calculations will go well.
Yes, that's right. After some time, tests and building a binary-decimal table for uint8(in 2 complements) I could get the correct results by making only 2 complements operations. Then only when I had to pass It to VDAC that I added 128u.
Thanks for the help!
You're always welcome, Daniel!