PDA

View Full Version : */ Overflow


GATJR
04-08-07, 12:27 PM
I use */ (star-slash) in my PID loop as a scaler. How do I detect when the result is an overflow. First thought is to just undo the */ and do the whole thing by hand but that gets bigger and slower.

I was hoping that one of FORTH gurus would know how to handle this.

This wasn't a problem when we ran our steering system ATVs with +-22 degree steering, but we see an overflow everynow and then on our Jeep with +-450 degree steering.

The result of the */ is greater than 32767 very rarely, but it does occur and I'd like to be able to detect it and manage it. The signs of the results of */MOD are different when the overflow occurs except for the zero case, so */MOD almost works.

RMDumse
04-10-07, 04:06 PM
Well, while we wait for some other idea to jump to mind, although none may, how would you feel if I said floating point?

Since the floating point module was written in assembler, and is optimized for the DSP, I bet it's much faster than you expect. Remember many of the higher level Forth math words are not primatives, but calls, so they get longer than you think.

Take it or leave it, I've made friends with the floating point, much to my suprise.

RMDumse
04-10-07, 04:10 PM
Have you looked at any of the later added double words?

[code]
388E UD* 1730 DMOD 172F D/ 172E D*
1575 DOVER 156F DSWAP 1130 DDUP 157B DROT
112F DDROP 1565 D@ 1561 D!
[\code]

Might be something useful in there for you. Particularly D/ which is a double divided into a double with a double result.

GATJR
04-10-07, 05:35 PM
Thanks for the help. I was just wanting to make sure that there wasn't some Forthy way to properly handle this that I didn't know about.

What I will do is pre-calculate the maximum input value that can be handled by a particular scaler set and then just do a pre-limit compare, still pretty fast, just adding a "DUP lim @ > IF" to the processing stream.