Reading the Tri-Axis Accelerometer using SX/B and SX28
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.· As soon as I put an external resonator on it, though, it seems to have the problem (although sometimes it works then as well).· Very strange, and it's driving me nuts!· 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.
Any ideas?
Thanks everone,
Jon
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.
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
Any ideas?
Thanks everone,
Jon
Comments
We need to see what you have on the DEVICE line for each resonator.
It's always best to post the entire code.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
When using the 4 MHz resonator:
DEVICE········· SX28, OSCXT1, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
When using the 50 MHz resonator:
DEVICE········· SX28, OSCHS1, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
I've actually tried various combinations for the external resonators, but they all seem to suffer the same problem.
Regards,
Jon
·
I see that after receiving data from the Accelerometer, the code moves it to a WORD in preparation for displaying it on the LCD. Is the data valid before moving? You might want to validate that the data arrives from the Accelerometer before attempting to display the data. In this manner, you can isolate the error to either the data transmission, or the code that does the displaying.
Joe
Post Edited (JDOhio) : 11/19/2007 2:41:26 AM GMT
I'm using an SX Tech Board for prototyping it, just so you have all the information.
I can't tell if it's valid.· If I run it to debug, it works fine.· If I hit reset (which stops the debugging), that's when the problem occurs (as well as when I disconnect the SX-Key).· It runs, just with the wrong numbers.
Thanks,
Jon
Post Edited (jbrierley) : 11/19/2007 2:41:51 AM GMT
I was looking through the reference document and it looks like it does the voltage interfacing for you. That is probably not an issue. And, my suggestion of stepping through to verify the data transfer won't work since you are seeing a difference with and without the SX Key.
If the device and the SX operate correctly with the SX key, then it would seem like the difference would be the oscillator as you suspect. That would affect all of the calculations the compiler makes for the timing of the SHIFTxx commands. Can you verify that the oscillator matches what the code says - i.e., are you installing a 4 MHz oscillator?
Joe
Thanks,
Jon
In the line where you specify options for DEVICE, have you tried using
DEVICE SX28, OSCXT1
For my SX-48 project, I used this syntax for setting the frequency:
FREQ 4000000
I know I'm starting to reach here.
Another idea is to use an oscilloscope to look at the data as it is transferred. In that way, you could compare the transfer with and without the SX Key. Without an oscilloscope, you might have to add some code to display various values of variables on the LCD. For example, is it possible to display the data before the conversions for display? Could you rotate through the bits, add $30, and display each bit? This would be another way of looking at differences with and without the SX Key.
Joe
I'll try your other suggestions. I'll try writing the bits to the display first and make sure that the byte and word variables match. If they do, I'll dig out the oscilloscope.
Thanks for trying, Joe, and I'll update once I've tried it.
Regards,
Jon
I think what's happening is that for some reason when reset it's counting the pause while the reading is being taken as a bit in the communications packet.· If I set it to read it as a communications bit (aka two null bits rather than one), it gets the expected VRef value (2048).· I guess that works and I'll go with it for now, but I hope it won't all of a sudden start doing it properly, because then it would read wrong again!
Thanks for the answers.· Any other ideas about what it might be occur to you?
Thanks,
Jon
Joe