In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Beau Schwabe wrote: Matthias09, Here is an example of something I'm working on right now written in SPIN using a derivative of this algorithm. The code eventually plays out to displaying 6 digits to the right of the decimal and is intended to capture the fractional difference and determine a bias on the LSB (least significant bit). [code] VAR long RawValue,DataBase, Average, Samples PUB MainProgram ADC.Start '' Initialize ADC Term.start(31, 30, 0, 38400) '' Initialize serial communication to the PC SerialDisplay PUB SerialDisplay Samples := 100 Average := ADC.Raw Average := ADC.Raw 'Read value twice the first time DataBase := Average * Samples repeat Samples Calibration Samples *= 100 DataBase *= 100 repeat Samples Calibration Samples *= 100 DataBase *= 100 repeat Calibration PUB Calibration RawValue := ADC.Raw ' Read RAW 10-bit Adc value DataBase := DataBase - Average + RawValue Average := DataBase / Samples DisplayData PUB DisplayData Term.tx(1) ' Position cursor at the Home position Term.dec(RawValue) Term.tx(13) Term.dec(DataBase) [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=175860#m382635 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)