- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi to everyone! I would use some help about one assigment, and I'll be grateful if you could help me. The assigment is on two input signal, I need to calculate the efective value and I need to let the signal who has bigger effective value on the gate. My solution on this problem is the following:
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi GiGo,
I have few suggestions regarding this code.
1) suma1 is used as an accumulator for storing the square of two 16 bit ADC readings. Assuming that the ADC output occupies entire 16 bits, you'll ideally be getting a 32 bit result. You have declared suma1 as int32 which means its a signed int covering both negative and positive range.
The square of a number can never be negative, so I presume that its better that you use uint32 instead of int32. This will start counting from 0.
2) Another cause of worry is that you can't successfully accumulate in this way..!!! Thats because, just with a single reading you'll be generating a 32-bit value. You can no longer add any other successive ADC's squared reading to this. It just keeps rolling over again and again.
Solution: I think that you must be more concerned about the upper 16 bits which is more significant. Hence you can throw the lower 16 bits from every squared value by right shifting 16 times ( >> 16). Since you are adding 65536 similar such samples, it'll occupy 16 more bits. So, the tally come up to 16 + 16 bits = 32 bits. If you have declared it as uint32 the overflow is avoided.
Please let us know if this works.
Cheers,
dasg