AnsweredHot!Is it possible to obtain an unsigned result of the difference of two unsigned numbers?

Page: < 123 Showing page 3 of 3 - Powered by APG vNext Trial
Author
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2614
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: online
Re: Is it possible to obtain an unsigned result of the difference of two unsigned numbers? 2018/06/14 02:55:51 (permalink)
0
No, you probably like prog rock music.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#41
DarioG
Allmächtig.
  • Total Posts : 53432
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: online
Re: Is it possible to obtain an unsigned result of the difference of two unsigned numbers? 2018/06/14 03:11:20 (permalink)
0
I feel so extraordinary / something's got a hold on me

DEUTSCHLAND TOOOOOR!!! Brandenburger springt :D

#42
du00000001
Just Some Member
  • Total Posts : 1893
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Is it possible to obtain an unsigned result of the difference of two unsigned numbers? 2018/06/14 03:25:41 (permalink)
+1 (1)
OK - given the context ELP is certainly not https://en.wikipedia.org/...ered_Languages_Project

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#43
rpg7
Super Member
  • Total Posts : 1355
  • Reward points : 0
  • Joined: 2003/11/07 12:47:35
  • Status: offline
Re: Is it possible to obtain an unsigned result of the difference of two unsigned numbers? 2018/06/14 04:25:41 (permalink)
0
To go back to the OP's problem.
1and0
DominusT
First capture the initial value:
app_uart2.instantValueTMR = getValueTemp();
+

Then I calculate if the elapsed time is greater than the desired  
 </p>
<p>if(abval(getValueTemp() - app_uart2.instantValueTMR)> _300ms){
     sendComm(WAKE_NFC);
}
 Where app_uart2.instantValueTMR and the value returned by getValueTemp () are unsigned int   To avoid negative values, I use the function that obtains the absolute value (abval)

Subtracting two unsigned int's will result in an unsigned int; i.e. there's no negative values. Neither absolute value nor casting is needed. What is _300ms?

Agreed that if 16 bit timer used then the variables shold be uint16_t.
I use the core timer for determining timeouts. It has the advantage that it is a 32bit timer, so using uint32_t just works.
 
edit: Somehow lost the bit of quote where 1and0 says to use 16bit variables....
post edited by rpg7 - 2018/06/14 04:28:10
#44
1and0
Access is Denied
  • Total Posts : 8009
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is it possible to obtain an unsigned result of the difference of two unsigned numbers? 2018/06/14 09:17:43 (permalink)
0
rpg7
I use the core timer for determining timeouts. It has the advantage that it is a 32bit timer, so using uint32_t just works.

OP said he's using the core timer in Post #16.
 
#45
Page: < 123 Showing page 3 of 3 - Powered by APG vNext Trial
Jump to:
© 2018 APG vNext Trial Version 4.5