使用 TI 的 MSP430 FF22x4 读取电压

发布于 2024-11-01 05:24:56 字数 867 浏览 4 评论 0原文

我正在尝试使用 TI 的 MSP430 测量功率器件的电压。电压源连接到目标板上的A1(即P4)和地(即P1)。

这是相关代码:

ADC10CTL1 = INCH_1 + CONSEQ_0; //A1, single measurement
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR; //same as sample temperature sensor code
ADC10CTL1 &= ~ADC10DF; //setting binary format for ADC10MEM
ADC10CTL0 |= ENC + ADC10SC; //Sampling and conversion start
 __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
//read result

我遇到以下问题:

  1. 我在AP上打印ADC10MEM内容,我看到ADC10MEM的前6位都是1,而不是0。我无法得到原因

  2. 如果我只考虑 ADC10MEM 的最后 10 位,我可以看到该值随着电压的上升和下降而增加和减少,但如果我使用以下公式获得 Vin:

N = 1023 * ((Vin - VR- ) / (VR+ - VR-)),我没有得到正确的值。 (VR+ = 1.5V,VR- = 0V,因为电池为目标板供电) N:ADC10MEM 中的值,以十进制表示,

我无法找到哪里出错了。我是否必须启用模拟输入引脚 (ADC10AE0 |= 0x10),并设置方向 (P4DIR |= 0x01)?

谢谢!

I am trying to measure a power device's voltage using TI's MSP430. The voltage source is connected to A1 (i.e. P4) and ground (i.e. P1) on the target board.

Here is the relevant code:

ADC10CTL1 = INCH_1 + CONSEQ_0; //A1, single measurement
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR; //same as sample temperature sensor code
ADC10CTL1 &= ~ADC10DF; //setting binary format for ADC10MEM
ADC10CTL0 |= ENC + ADC10SC; //Sampling and conversion start
 __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
//read result

I am having following problems:

  1. I am printing the ADC10MEM contents on the AP, and I see that the leading 6 bits of ADC10MEM are all 1, instead of 0. I am unable to get the reason for the same.

  2. If I consider only the last 10 bits of ADC10MEM, I can see that the value increases and decreases with rise and fall in voltage, but if I obtain Vin using the formula:

N = 1023 * ((Vin - VR- ) / (VR+ - VR-)), I do not get the correct value. (VR+ = 1.5V, VR- = 0V, as batteries power the target board)
N: the value in ADC10MEM, in decimal

I am unable to find where I am going wrong. Do I have to enable the pin for analog input (ADC10AE0 |= 0x10), and set direction (P4DIR |= 0x01) as well?

Thanks!

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

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

发布评论

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

评论(1

梦纸 2024-11-08 05:24:56

TI 在这里为这些 MSP430 提供了很好的示例代码:

http://www.ti.com/litv/zip/slac123d

其中一个还读取电压,您应该使用它来与您正在做的事情进行比较。我不记得 ADC10DF,但这似乎是一件可疑的事情(因为您的错误与数据输出有关)。

另外,你说你读了结果。如果您等待时间不够,结果无效。您没有显示任何中断例程,因此可能发生了一些事情。

TI provides nice example code for those MSP430 here:

http://www.ti.com/litv/zip/slac123d

One of them also reads the voltage and you should use it to compare to what you're doing. I don't remember about the ADC10DF, but it would seem to be a suspicious thing to do (since your error is related to the data out).

Also, you say that you read the result. If you don't wait enough, the result isn't valid. You didn't show any interrupt routine so perhaps there something there going on.

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