Shop OBEX P1 Docs P2 Docs Learn Events
Hitachi H48C 3-Axis Accelerometer spin code?? — Parallax Forums

Hitachi H48C 3-Axis Accelerometer spin code??

TyreBiterTyreBiter Posts: 40
edited 2006-09-13 22:43 in Propeller 1
Before I dive into coding for this sensor, has anyone developed any spin code for it yet???

AuburnSky smile.gif

Comments

  • SeekerSeeker Posts: 58
    edited 2006-08-15 23:43
    I just recieved mine today and was wondering the same thing. It seems to be a simple SPI I/O (BS2 Shiftin/out). Odd pin spacing though.... I'll have to carve up a socket to make it fit. Glad I hadn't commited to copper yet (PCB). That mod would be a pain.

    Possible addition to the spec sheet? Spacing between rows of pins.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-08-16 04:34
    AuburnSky,

    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.
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-16 12:40
    Beau,

    That's spooky. My next project after the acceleromenter was also the compass module...

    AuburnSky
  • SeekerSeeker Posts: 58
    edited 2006-08-16 16:56
    Wow....

    That makes three of us. Are we all building the same project? [noparse]:)[/noparse]
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-18 16:54
    By all means, each should build their own objects and then compare notes.· In the end you may all get some ideas from each other that each individual didn't think of.· This wouldn't necessarily be limited to just the raw code but also the way/approach used to achieve the goal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-23 15:16
    Beau;

    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
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-08-23 16:05
    AuburnSky,

    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 .....
    spi.shiftout ( _dioPin, _clkPin, MSBFIRST, 2, vRef )
    
    


    ...should read...
    spi.shiftout ( _dioPin, _clkPin, MSBFIRST, 2, %11 )
    spi.shiftout ( _dioPin, _clkPin, MSBFIRST, 3, vRef )
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-23 18:01
    Beau,

    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
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-08-23 18:27
    Just to get this straight.... BS2 code gives the·same results as the Spin code? or Not?

    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.
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-23 23:25
    Beau;

    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
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-08-24 03:22
    AuburnSky,

    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
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-24 12:39
    Beau,

    That did it!!! hop.gif

    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.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-08-24 15:31
    AuburnSky,

    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.
  • TyreBiterTyreBiter Posts: 40
    edited 2006-08-24 15:36
    Beau

    I would never have found the problem let alone solved it. Thank the gods for gurus.

    AuburnSky
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-09-12 19:57
    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.
  • TyreBiterTyreBiter Posts: 40
    edited 2006-09-13 12:40
    Things are proceding nicely. Thanks for asking. smile.gif

    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. shocked.gif

    Let me know if I have done anything totaly off the wall with SPIN or ASM....

    Regards,

    AuburnSky
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-09-13 22:43
    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.
Sign In or Register to comment.