Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSP 430 wrong values being displayed

Tags:

c

embedded

msp430

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.


2 Answers

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;
like image 102
Rex Logan Avatar answered Dec 16 '25 09:12

Rex Logan


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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!