4-20ma 电流环压力传感器,-1mbar 至 1 mbar 值,?汇编代码用户

发布于 2024-12-03 20:53:19 字数 296 浏览 1 评论 0原文

我正在对 pic 18f 进行编程以拉德压力传感器,从 +1mbar 摆动到 -1mbar (4-2-ma)

此时一切正常重新编码,现在需要将我的 8 位转换为更可读的格式。

转换方程为 Mbar=Vin*0.5 -1.5 ,确认。

如您所见,1 伏特为 -1mbar,3 伏特 = 0mbar,5 伏特 = +1mbar,,,,

任何人都可以告诉我在哪里可以对此进行攻击。尝试以十六进制展开方程式,然后是 rlcf 等,我变得混乱。

这里张开双臂接受所有帮助/见解和建议!

史蒂夫

im programming a pic 18f to rad an press sensor, swings from +1mbar to -1mbar (4-2-ma)

All ok at this point re code, now in need to shift my 8 bits to a more readable format.

the equation for conversion is Mbar=Vin*0.5 -1.5 , confrimed.

as you can see 1 volt is -1mbar, 3 volts = 0mbar, 5 volts = +1mbar,,,,

Anyone show me where to swat up on this. Tried to expand equation in hex, then rlcf etc, im getting messy.

all assistance/insight and suggestions accepted with open arms here!

Steve

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

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

发布评论

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

评论(1

旧话新听 2024-12-10 20:53:19

最好的办法是用伪代码表达问题,然后将其转换为 PIC 汇编。

// Input value, x, is 8 bit unsigned, 0..255 = 0..5v = 0..20 mA = -1.5..+1.0 mbar
// Output value, y, is 8 bit signed (two's complement), -127..127 = -1..+1 mbar
// Temp value, temp, is 16 bit signed

temp = x - 51;        // subtract 4 mA (= 1V = 0.5 mbar) offset = 255 / 5 = 51
temp = temp * 5;      // scale by 5 / 4 (NB: can do * 5 with 2 bit left shift and add)
temp = temp / 4;      // (NB: can do / 4 with a 2 bit right shift)
temp = temp - 128;    // convert to 8 bit signed
y = temp;             // return 8 bit signed value

The best thing to do is express the problem in pseudo code then convert that to PIC assembly.

// Input value, x, is 8 bit unsigned, 0..255 = 0..5v = 0..20 mA = -1.5..+1.0 mbar
// Output value, y, is 8 bit signed (two's complement), -127..127 = -1..+1 mbar
// Temp value, temp, is 16 bit signed

temp = x - 51;        // subtract 4 mA (= 1V = 0.5 mbar) offset = 255 / 5 = 51
temp = temp * 5;      // scale by 5 / 4 (NB: can do * 5 with 2 bit left shift and add)
temp = temp / 4;      // (NB: can do / 4 with a 2 bit right shift)
temp = temp - 128;    // convert to 8 bit signed
y = temp;             // return 8 bit signed value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文