Neil Pate Posted September 6, 2016 Report Share Posted September 6, 2016 Almost totally unrelated to LabVIEW, and is not really just a question more of just a ramble. I have dusted off a PIC microcontroller that I have had lying around in my drawer for years, and am attempting to stop old-age brain rot my making it do stuff, but purposely limiting myself to assembler. So far I have the (12-bit) ADC working, and sending the upper 8 bits back to the PC over RS-232 as an ASCII character. Now all I want to do is display the analogue voltage on the PC. Should be simple. I am using the 5V supply as the reference, so a 12-bit ADC has a step size of 1.22 mV. Conversion from 12-bit hex value to human readable value should be reasonably straightforward: scale the ADC value by 1.22 mV, convert to say 5 digit BCD and chuck out over the serial port one character at a time. I figure the first step is to implement a fixed point multiplication, keeping things simple I can have the ADC reading as <+,16,0> and the scaling factor as <+16, 3>. This is the bit that is making my brain hurt... I have done some reasearch and it turns out that fixed point multiplication does not really care about the format of the number, only the bit-width. So you can use exactly the same algorithm to scale <+16,0> and <+16,3>. Anybody know if this is correct? Now, I know I can take all sorts of shortcuts to get the ADC value in human readable format, I have decided for the purpose of the exercise I really want to figure this out using fixed point maths (I have no actual application in mind other than curiosity). Quote Link to comment
JKSH Posted September 6, 2016 Report Share Posted September 6, 2016 (edited) 6 hours ago, Neil Pate said: This is the bit that is making my brain hurt... I have done some reasearch and it turns out that fixed point multiplication does not really care about the format of the number, only the bit-width. So you can use exactly the same algorithm to scale <+16,0> and <+16,3>. Anybody know if this is correct? Correct A few useful notes: Your 16-bit fixed point number is stored in memory exactly like a 16-bit integer*. Fixed point multiplication == Integer multiplication. The same algorithms apply to both. The algorithms for integer multiplication don't depend on the value of the number. By extension, they don't depend on the representation of the number either. e.g. Multiplying by 2 is always equivalent to shifting the bits to the left (assuming no overflow) (* LabVIEW actually pads fixed point numbers to 64 or 72 bits, but I digress) Anyway, to illustrate: Bit Pattern (MSB first) | Representation | Value (decimal) =========================|===============================|================= 0000 0010 | <+,8,8> (or equivalently, U8) | 2 0000 0010 | <+,8,7> | 1 0000 0010 | <+,8,6> | 0.5 -------------------------|-------------------------------|----------------- 0000 0100 | <+,8,8> (or equivalently, U8) | 4 0000 0100 | <+,8,7> | 2 0000 0100 | <+,8,6> | 1 6 hours ago, Neil Pate said: Almost totally unrelated to LabVIEW, and is not really just a question more of just a ramble. That's borderline blasphemy... You can redeem yourself by getting LabVIEW involved: Edited September 6, 2016 by JKSH Quote Link to comment
Neil Pate Posted September 6, 2016 Author Report Share Posted September 6, 2016 (edited) I did say "almost" :-) This is the VI I knocked up just to test things out.. Thanks for the info, I will digest slowly tomorrow evening. Edited September 6, 2016 by Neil Pate Quote Link to comment
Neil Pate Posted September 10, 2016 Author Report Share Posted September 10, 2016 (edited) Getting there slowly.. :-) I have the 16-bit x 16-bit multiplication working using the 8-bit hardware multiplier. Also I have fleshed out my LabVIEW demo to show how to solve the rest of my problem. Convert (+,16,4) Fixed Point Number To String.vi Convert First Decimal Place Of (+,16,4) Fixed Point Number To String.vi Fixed Point Maths.vi Edited September 10, 2016 by Neil Pate Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.