Reputation:
I'm developing pressure measuring device. I've used MSP430F133 chip and using IAR embedded workbench. It shows pressure in 3 different units.
I'm taking 32 samples and averaging it. Unit selection on P5, according to the unit selected output value is calculated and displayed on LCD.
Now a unit "IN WC" is showing binary averaged vale of input, just for analysis.
The problem: in default units(MM WC) values are displaying correctly but in a test situation when pressure is released it goes down and LCD read as below
+31.8
+31.7
+31.6
+31.5
+31.4
+31.3
+31.2
+31.2
+31.1
+31.5 (wrong reading randomly between *.4 to *.7)
+30.9
As you can there is one wrong value is being displayed, I'm not able to figure out the reason.
Upvotes: 3
Views: 1486
Reputation: 33
I'm going to go ahead and suggest a kind of ADC 101 solution you could try. Depending on the type of sensor you are using you may need to perform your own de-bouncing to clean up your sample readings. I have referred to this article in the past and have found it very helpful for learning this technique: A Guide to De-bouncing by Jack G. Ganssle!
Like I stated before though this is assuming your hardware requires de-bouncing but the guide should help you identify this. Even if you don't require it you may find it interesting regardless!
Additional: Just so you know the reason I suggest this is you mentioned the odd readings were occurring when the pressure was being released. De-bouncing errors are evident in sampling during the actuation of mechanically based switches and sensors.
Upvotes: 1
Reputation:
Unfortunately none of the two links to the source code works anymore. But from what I can see the cause might be the fact that the expected 'correct' last digit at this place is a zero. My guess is theat somewhere in the calculation or visualisation code this zero is erroneously taken as a stop condition and causes a random digit to be shown at its place. (only a '31' is provided to the output but 3 digits are sent to the display)
The '||'/'&&' issue above shows that the code isn't very straight forward and if this is true for the rest too, a wrong stop condition here and a fixed-length loop there might cause this.
Just a 'wild guess'(TM) but the best I can give without knowning the actual code.
Upvotes: 2
Reputation: 27136
In the below code ptiveValue = value and d1 = value so d2 is always 0 then in your loop you have for (i=0; i<= 3||res[i]!='\0'; i++) which should be for (i=0; i<= 3&&res[i]!='\0'; i++) so it always prints out what was left in the buffer not what you want
Bad code:
if (cntd <= 4)
{
d2 = (unsigned int) abs((ptiveValue - d1) * 10000); // get 4 digits of real part
itoa1(d2, res, &cntreal);
for (i=0; i<= 3||res[i]!='\0'; i++)
{
wr_lcd_dr(res[i]);
}
}
Fixed code
if (cntd <= 4)
{
// get 4 digits of real part
d2 = (unsigned int) ((ptiveValue - (unsigned int)(d1)) * 10000);
itoa1(d2, res, &cntreal);
for (i=0; (i<= 3) && (res[i]!='\0'); i++)
{
wr_lcd_dr(res[i]);
}
}
You are also overwriting your buffer and possibly creating weird behavior.
unsigned short Adcinb[32];
for (i = 0; i <= 63; i++)
Adcinb[i] = 3180;
Should be
unsigned short Adcinb[32];
for (i = 0; i < 32; i++)
Adcinb[i] = 3180;
Upvotes: 4
Reputation: 93605
Looking over your code I don't see any particular reason you would be getting that value unless it reflected the actual values being sensed.
Can you run the program and output each of the 32 values before averaging for the number that has the problem, the number before it, and the number after it?
Alternately, write out the new sample each time you get a sample and give us that data.
-Adam
Upvotes: 0
Reputation: 56792
This looks fishy, the || probably should be &&:
for (i=0; i<= 3||res[i]!='\0'; i++)
But I don't see how it causes your problem.
Also, you should clean up and simplify your code. As it is it is very hard to read.
Upvotes: 1