Absolute ABS Function for Integers?

Use this section to discuss your embedded Flowcode projects.
Post Reply
jay_dee
Posts: 219
http://meble-kuchenne.info.pl
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 82 times
Been thanked: 58 times

Absolute ABS Function for Integers?

Post by jay_dee »

Hi,
Does FC have an ABS ( Absolute ) function?

I have a current sensor and get both positive and Negative Values.
Is there a Calculation Function that will always return positive Value. I thought C had an ABS function.

If the Float Abs function is used, the compiler throws an error.
thanks, J.

chipfryer27
Valued Contributor
Posts: 1608
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Absolute ABS Function for Integers?

Post by chipfryer27 »

Hi

Are you supposed to be getting negative values, which would suggest a reversal of flow?

Regards

jay_dee
Posts: 219
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 82 times
Been thanked: 58 times

Re: Absolute ABS Function for Integers?

Post by jay_dee »

Hi, Yeah absolutly. It is a H Bridge driven DC motor. I use the current to define the 'Clamping' force and hard limits of the driven assembly. J.

chipfryer27
Valued Contributor
Posts: 1608
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Absolute ABS Function for Integers?

Post by chipfryer27 »

Hi

OK, just curious.

I assume you are getting a 2's compliment return?

If for example x = -27 could you not use x = fabs(x) to give 27 ?

Regards

PS
The above simulates but can't try compiling to hex yet as I need to install the compilers on this little machine I'm using

jay_dee
Posts: 219
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 82 times
Been thanked: 58 times

Re: Absolute ABS Function for Integers?

Post by jay_dee »

Hi,
Ahhh.... Fabs(Value) this will not pass
but fabs(value) will pass the compiler.

it was not a problem with the function but with my capitalisation! doh!

FC usually lets me play fast and loose with capitalisation but not in this case!
Thanks. :)

OK...back to fixing the bigger project!!

chipfryer27
Valued Contributor
Posts: 1608
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Absolute ABS Function for Integers?

Post by chipfryer27 »

Haha

Many times I have been caught out similarly and spent way, way too long chasing..... :)

Glad it is working now

Regards

jay_dee
Posts: 219
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 82 times
Been thanked: 58 times

Re: Absolute ABS Function for Integers?

Post by jay_dee »

appologies to the FC team, I think it might have been a even more basic mistake and not the capitialisation....
REVERSE...REVERSE...back away from the situation!!! haha!

chipfryer27
Valued Contributor
Posts: 1608
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Absolute ABS Function for Integers?

Post by chipfryer27 »

Disengaging Panic Circuits...???

Post Reply