Hitachi H48C 3-Axis Accelerometer spin code??
TyreBiter
Posts: 40
Before I dive into coding for this sensor, has anyone developed any spin code for it yet???
AuburnSky
AuburnSky
Comments
Possible addition to the spec sheet? Spacing between rows of pins.
This was on my list of things to do, but feel free if you want to try it out. Next on my list is the compass module which also requires SPI I/O.
My goal is to create the objects in pure assembly and encapsulate them in such a way that they could be used with Spin or Assembly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
That's spooky. My next project after the acceleromenter was also the compass module...
AuburnSky
That makes three of us. Are we all building the same project? [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I am attempting to use your "SPI Engine" from "Assembly Code Examples for the Beginner" thread
to produce a spin object for the h48c.
Starting with the BS2 code example below, I wrote a spin version (also below)
Iam getting zeros for the reference voltage and the voltages on the three axis.
Is there something wrong with my code or is the problem more likely with the hardware?
Thanks for you help.
AuburnSky
Get_H48C:
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [noparse][[/noparse]%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]rvCount\13] ' read ref voltage counts
HIGH CS
PAUSE 1
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [noparse][[/noparse]%11\2, axis\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]axCount\13] ' read axis voltage counts
HIGH CS
RETURN
pri _sample ( axis ) | val
dira [noparse][[/noparse] _csPin ] := Out
outa [noparse][[/noparse] _csPin ] := Low
spi.shiftout ( _dioPin, _clkPin, MSBFIRST, 2, vRef )
Ref := spi.shiftin ( _dioPin, _clkPin, MSBPOST, 13 )
outa [noparse][[/noparse] _csPin ] := High
waitcnt ( clkfreq / 5 + cnt )
outa [noparse][[/noparse] _csPin ] := Low
spi.shiftout ( _dioPin, _clkPin, MSBFIRST, 2, axis )
val := spi.shiftin ( _dioPin, _clkPin, MSBPOST, 13 ) 'Measure
outa [noparse][[/noparse] _csPin ] := High
return val
You have gotten further than I... There are a few building blocks. i.e. SPI,I2C, etc that I have been putting together
while waiting for my "Hitachi H48C 3-Axis Accelerometer" and other goodies to catch up with me after shipping them
to myself (Not sure it would have been wise to take them as a cary-on item on the plane these days).
Are you at least getting the same results from your BS2 version vs. your Spin version?
I think the line that reads .....
...should read...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for the feedback. I made the suggested mods and there was no change in the values.
They are all still zero.
I will try my BS2 system when I get home tonight to verify the hardware. When I get all caught
up in a problem, I sometimes foget the obvious...
AuburnSky
Are you passing the argument values correctly in Spin? i.e. _dioPin, _clkPin, MSBFIRST, vRef, MSBPOST
Can you post your code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
The BS2 code functions properly .ie. the axis and reference voltages are not zero
The Spin code functions fail .ie. the axis and reference voltages are zero.
The spin code is in the attached zip file
Thanks again
I updated the SPI engine... I found a problem with the SHIFTOUT --> MSBFIRST that was causing
the wrong data to be shifted out. In addition, I found a small problem with the Argument allocation
within the main loop of the SPI Engine.
I updated the post... SPI engine
Please test this and let me know, there might be some other necessary changes. Hopefully not though.
FYI) I noticed in your code you were calling the 'start' for the SPI engine. Although it won't/shuldn't hurt anything it is not
necessary. When you call SHIFTIN or SHIFTOUT, the 'start' gets called automatically.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/24/2006 4:54:50 AM GMT
That did it!!!
By the by, the start method for spi was called in the start method for the h48c object.
An extra pair of eyes are always helpful....
Again thanks.
Glad that worked. It's hard to test every single scenario, and I think when I was writing the code I wrote
the LSBFIRST first, made a copy of it for most of the MSBFIRST code and changed the obvious differences.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I would never have found the problem let alone solved it. Thank the gods for gurus.
AuburnSky
How is the "Hitachi H48C Tri-Axis Accelerometer Module" code coming along?
Just thought I'd ask since I'm just getting to it right now, and I haven't seen anything from you in this thread.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
The attachment contains a whack at the H48C and the memsic 2125. The scaling factors are purely arbitrary.
Most of the code is a learning exercise used to understand SPIN/ ASM, Float32 and memory addressing
The code is in no way optimal.
Let me know if I have done anything totaly off the wall with SPIN or ASM....
Regards,
AuburnSky
Here is a link to an assembly version of the "Hitachi H48C Tri-Axis Accelerometer Module"
http://forums.parallax.com/showthread.php?p=605279
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.