开发者

4-20ma current loop pressure sensor, -1mbar to 1 mbar value, ? assembly code user

开发者 https://www.devze.com 2023-04-04 01:33 出处:网络
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.

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 开发者_如何学Pythonon this. Tried to expand equation in hex, then rlcf etc, im getting messy.

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

Steve


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号