Other Parts Discussed in Thread: C2000WARE
Hi,
This is the first time I've had this issue with C2000Ware - I am calculating an error voltage from two sensors, to be used in a controller code within the DCL Library.
However, with the simple equation (Voltage A - Voltage B) = Error Voltage, if Voltage B exceeds the value of Voltage A, and error voltage becomes negative, the unsigned 16-bit integer tends to show very close to its maximum value as opposed to what I would expect, which is 0. Here is an example:
As soon as the term that is subtracted exceeds the reference voltage, the debugger shows that the unsigned integer becomes extremely high, close to the maximum value for a 16-bit integer, completely messing up my calculations from that point forward. This does make sense because of how unsigned integers work, but I am wondering what is the best way to deal with this. For now I have an "if" condition that assigns the voltage as zero if voltage B is larger than voltage A. This actually can't happen during normal operation but it would be interesting to understand how to deal with this.
I am using uint16_T because I send the error voltage over IPC to CPU2. I suppose I could use float values to calculate the error, and cast to unsigned int before using the IPC and sending to CPU2 but would this be the most efficient way of dealing with this issue? I would just have to convert it back to a float in CPU2 anyway as the errors are then used in the CLA and the DCL Library.
Best regards,
Joel