In SX Microcontrollers, SX/B Compiler and SX-Key Tool, jbrierley wrote: Hi, everyone. I've been doing some work to do a basic g-meter using the Parallax tri-axis accelerometer and a serial LCD module. When I run the code, I get the expected reference count (around about 2048), but if I hit the reset button (sometimes a few times), I start getting a reference count around 5120, which is obviously not right. I think it might be something to do with the clock frequency, since it seems stable while it's running using the SX-Key close. As soon as I put an external resonator on it, though, it seems to have the problem. I've tried both the 4 MHz and 50 MHz resonators and the problem is the same. I've also tried the 4 MHz internal clock. Could anyone have a look at my code for reading the accelerometer and see if they can see if anything is wrong? I've extracted just the reference count code so it's clearer. In reality there's code for reading the axis counts as well. It's my first program for the SX (just got the kit last week), so it might be a bit messy. [code] Get_Acc: LOW CS ' Prod the accelerometer and select the reference voltage count register SHIFTOUT Dio, Clk, MSBFIRST, %11\2 SHIFTOUT Dio, Clk, MSBFIRST, Vef\3 ' select vref register ' Null bit and the high four bits of the ADC reading into the low nibble of the byte variable rvCount1 SHIFTIN DIO, CLK, MSBPOST, rvCount1\5 ' Get the rest of the ADC reading into rvCount2 byte variable SHIFTIN DIO, CLK, MSBPOST, rvCount2\8 HIGH CS PAUSE 1 PUT @rvCount, rvCount2, RvCount1 ' Put the 12-bit reference count value into a WORD variable (rvCount) RETURN [/code] Any ideas? Thanks everone, Jon ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=231466 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)