MSP 430 显示错误值

发布于 2024-07-14 09:52:05 字数 411 浏览 4 评论 0原文

我正在开发压力测量装置。 我使用了MSP430F133芯片并使用IAR嵌入式工作台。 它以 3 种不同的单位显示压力。

我采集了 32 个样本并取平均值。 P5上的单位选择,根据选择的单位计算输出值并显示在LCD上。

现在,“IN WC”单元显示输入的二进制平均值,仅供分析之用。

问题:在默认单位(MM WC)中,值显示正确,但在测试情况下,当压力释放时,它会下降,LCD 读数如下所示,

+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

正如您所见,正在显示一个错误的值,我无法弄清楚找出原因。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

囚你心 2024-07-21 09:52:05

在下面的代码中 ptiveValue = value 和 d1 = value 所以 d2 始终为 0 那么在你的循环中你有
for (i=0; i<= 3||res[i]!='\0'; i++)
应该是
for (i=0; i<= 3&&res[i]!='\0'; i++)
所以它总是打印出缓冲区中剩下的内容,而不是您想要的内容

错误代码:

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]);

    }
 }

固定代码

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]);     
    }
 }

您还覆盖了缓冲区并可能创建奇怪的行为。

unsigned short Adcinb[32];
for (i = 0; i <= 63; i++)
Adcinb[i] = 3180;

应该

unsigned short Adcinb[32];
for (i = 0; i < 32; i++)
Adcinb[i] = 3180;

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;
很快妥协 2024-07-21 09:52:05

不幸的是,源代码的两个链接都不再起作用了。
但从我看来,原因可能是这个地方预期的“正确”最后一位数字是零。
我的猜测是在计算或可视化代码中的某个地方,这个零被错误地视为停止条件,并导致在其位置显示随机数字。
(仅向输出提供“31”,但将 3 位数字发送至显示器)

“||”/“&&” 上面的问题表明代码不是很直接,如果其余部分也是如此,那么这里的错误停止条件和那里的固定长度循环可能会导致这种情况。

只是一个“疯狂的猜测”(TM),但我可以在不知道实际代码的情况下给出最好的结果。

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.

千と千尋 2024-07-21 09:52:05

这看起来很可疑,|| 可能应该是 &&:

        for (i=0; i<= 3||res[i]!='\0'; i++)

但我不明白它是如何导致你的问题的。

另外,您应该清理并简化您的代码。 事实上,它很难阅读。

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.

你与清晨阳光 2024-07-21 09:52:05

我将继续建议您可以尝试的一种 ADC 101 解决方案。 根据您使用的传感器类型,您可能需要执行自己的去抖操作以清理样本读数。 我过去曾参考过这篇文章,发现它对于学习这项技术非常有帮助:Jack G. Ganssle 的去抖指南

正如我之前所说,虽然这是假设您的硬件需要去抖动,但指南应该帮助您识别这一点。 即使您不需要它,您也会发现它很有趣!

附加:只是让你知道我建议的原因是你提到在压力释放时出现奇怪的读数。 在基于机械的开关和传感器的致动过程中,采样中的去抖误差很明显。

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.

ㄖ落Θ余辉 2024-07-21 09:52:05

查看您的代码,我没有看到您获得该值的任何特殊原因,除非它反映了所感测到的实际值。

您能否运行该程序并输出 32 个值中的每一个,然后对有问题的数字、其之前的数字和其之后的数字进行平均?

或者,每次获得样本时写出新样本并向我们提供该数据。

-亚当

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文