CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Absolute value with 10bit ADC readings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

Absolute value with 10bit ADC readings
PostPosted: Tue Feb 19, 2008 1:15 pm     Reply with quote

Hello All,

I would like to take the absolute value of 2 unsigned 10bit adc readings. All I want is to see if the difference between these 2 10bit ADC readings is greater than 10.

I know about underflowing with subtraction, and that apparently you cannot use Abs() with unsigned variables.

IS THERE ANY WAY TO DO THIS IN A LESS CONVOLUTED MANNER?

So to find out if Delta ADC1-ADC2 is > 10. I am going to use the
following code:

unsigned long int adcvalue1;
unsigned long int adcvalue2;
unsigned long int result;
unsigned int holdingvariable_a;
unsigned int holdingvariable_b;

if (adcvalue1 > adcvalue2)
{
holdingvariable_a = adcvalue1;
holdingvariable_b = adcvalue2;
}

else
{
holdingvariable_a = adcvalue2;
holdingvariable_b = adcvalue1;
}

result = holdingvariable_a - holdingvariable_b;

if (result > 10)
{
perform an event.
}

else
{
perform a different event.
}
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Tue Feb 19, 2008 2:42 pm     Reply with quote

if ( a > b )
delta = a - b;
else delta = b - a;

Ken
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group