Part Number: MSP430FR2355
Good morning...
I have a timer that goes off and I capture the count register in a variable and an overflow counter as well both are declared as volatile unsigned int. After doing this twice I want to do a difference on the two numbers for each variable. I recognize that there is no guarantee which of the two numbers will be larger than the other at any given point in time hence I am diffing them with the abs function. Can some tell me how I should be declaring all my variables as I am having a hard time getting the numbers to give me correct values....
I am assuming that I will have to typecast along the way. My math looks like this: I have varied my declarations of tempA and temp and haven't found the right combo....My other declarations look like:
temp = abs(overflowHistory[0] - overflowHistory[1]);
for (j = 0; j < temp; j++)
adder +=65536;
tempA = abs(holdTime[0] - holdTime[1]);
swVolumeHoldTime = (long)tempA + (long)adder;
volatile unsigned int overflowHistory[2] = {0};
volatile unsigned int holdTime[2] = {0};
long int swVolumeHoldTime = 0, adder = 0;
I have tempA declared as an int and created a tempB as an unsigned int for testing and I cannot see any difference.....On top of all this it appears that something very strange is occuring....For instance I did one run after verifying holdTime[] = {0} on both values in array and got
holdTime[0] = 50356
holdTime[1] = 13715
and tempA and tempB failed both to show the correct subtraction values!! They showed 28895?? This subtraction error occurs even after a reset where all variables are initialized to 0.
Thanks