Is my H48C stuffed, or is it just that I don't know what I'm doing?
youngdave
Posts: 70
Dear All
I have an H48C accelerometer connected up to the Prop with the following code.
[noparse]/noparse
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
CS = 0
DIO = 1
CLK = 2
VAR
long vref,x,y,z,ThetaA,ThetaB,ThetaC
OBJ
H48C : "H48C Tri-Axis Accelerometer"
' VGA : "vga_text"
debug : "FullDuplexSerialPlus"
PUB DEMO_TEST
waitcnt((clkfreq*3)+cnt) 'Add a six second delay in your code. That's just the right amount of time to download, find the terminal, and click enable.
'start VGA terminal
' VGA.start(16)
debug.StartPST(115200) ' Start for Parallax Serial Terminal
'start and setup Accelerometer
H48C.start(CS,DIO,CLK)
' VGA.out($01)
' VGA.str(string("H48C Tri-Axis Accelerometer"))
debug.str(string("H48C Tri-Axis Accelerometer"))
debug.str(string(13))
waitcnt((clkfreq*1)+cnt)
repeat
'vref := (H48C.vref*825)/1024 '<-- Here's how to get vref in mV
vref := H48C.vref '<-- Here's how to get vref in RAW
'Note: The returned value for X, Y, and Z is equal to the axis - Vref
x := H48C.x '<-- Here's how to get x
y := H48C.y '<-- Here's how to get y
z := H48C.z '<-- Here's how to get z
'Note: The returned value is in Deg (0-359)
' remove the '*45)/1024' to return the 13-Bit Angle
ThetaA := (H48C.ThetaA*45)/1024 '<-- ThetaA is the angle relationship between X and Y
ThetaB := (H48C.ThetaB*45)/1024 '<-- ThetaB is the angle relationship between X and Z
ThetaC := (H48C.ThetaC*45)/1024 '<-- ThetaC is the angle relationship between Y and Z
debug.dec(Vref)
debug.str(string(" "))
debug.dec(X)
debug.str(string(" "))
debug.dec(Y)
debug.str(string(" "))
debug.dec(Z)
debug.str(string(" "))
debug.dec(ThetaA)
debug.str(string(" "))
debug.dec(ThetaB)
debug.str(string(" "))
debug.dec(ThetaC)
debug.str(string(" "))
debug.str(string(13))
DAT
[noparse][[/noparse]/]
Running this code results in the following numbers across the screen.
0 0 0 0 99 99 99, representing vref, X, Y, Z, ThetaA, ThetaB, and ThetaC in that order.
These values don’t change, no matter how much I jiggle the proto board on which the components are mounted.
The ‘H48C Tri-Axis Accelerometer’ object has not been changed in any way.
Is my H48C stuffed, or is it just that I don't know what I'm doing?
TIA David Young
I have an H48C accelerometer connected up to the Prop with the following code.
[noparse]/noparse
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
CS = 0
DIO = 1
CLK = 2
VAR
long vref,x,y,z,ThetaA,ThetaB,ThetaC
OBJ
H48C : "H48C Tri-Axis Accelerometer"
' VGA : "vga_text"
debug : "FullDuplexSerialPlus"
PUB DEMO_TEST
waitcnt((clkfreq*3)+cnt) 'Add a six second delay in your code. That's just the right amount of time to download, find the terminal, and click enable.
'start VGA terminal
' VGA.start(16)
debug.StartPST(115200) ' Start for Parallax Serial Terminal
'start and setup Accelerometer
H48C.start(CS,DIO,CLK)
' VGA.out($01)
' VGA.str(string("H48C Tri-Axis Accelerometer"))
debug.str(string("H48C Tri-Axis Accelerometer"))
debug.str(string(13))
waitcnt((clkfreq*1)+cnt)
repeat
'vref := (H48C.vref*825)/1024 '<-- Here's how to get vref in mV
vref := H48C.vref '<-- Here's how to get vref in RAW
'Note: The returned value for X, Y, and Z is equal to the axis - Vref
x := H48C.x '<-- Here's how to get x
y := H48C.y '<-- Here's how to get y
z := H48C.z '<-- Here's how to get z
'Note: The returned value is in Deg (0-359)
' remove the '*45)/1024' to return the 13-Bit Angle
ThetaA := (H48C.ThetaA*45)/1024 '<-- ThetaA is the angle relationship between X and Y
ThetaB := (H48C.ThetaB*45)/1024 '<-- ThetaB is the angle relationship between X and Z
ThetaC := (H48C.ThetaC*45)/1024 '<-- ThetaC is the angle relationship between Y and Z
debug.dec(Vref)
debug.str(string(" "))
debug.dec(X)
debug.str(string(" "))
debug.dec(Y)
debug.str(string(" "))
debug.dec(Z)
debug.str(string(" "))
debug.dec(ThetaA)
debug.str(string(" "))
debug.dec(ThetaB)
debug.str(string(" "))
debug.dec(ThetaC)
debug.str(string(" "))
debug.str(string(13))
DAT
[noparse][[/noparse]/]
Running this code results in the following numbers across the screen.
0 0 0 0 99 99 99, representing vref, X, Y, Z, ThetaA, ThetaB, and ThetaC in that order.
These values don’t change, no matter how much I jiggle the proto board on which the components are mounted.
The ‘H48C Tri-Axis Accelerometer’ object has not been changed in any way.
Is my H48C stuffed, or is it just that I don't know what I'm doing?
TIA David Young
Comments
I have an H48C accelerometer connected up to the Prop with the following code.
Running this code results in the following numbers across the screen.
0 0 0 0 99 99 99, representing vref, X, Y, Z, ThetaA, ThetaB, and ThetaC in that order.
These values don’t change, no matter how much I jiggle the proto board on which the components are mounted.
The ‘H48C Tri-Axis Accelerometer’ object has not been changed in any way.
Is my H48C stuffed, or is it just that I don't know what I'm doing?
TIA David Young
I have an H48C accelerometer connected up to the Prop with the following code.
Running this code results in the following numbers across the screen.
0 0 0 0 99 99 99, representing vref, X, Y, Z, ThetaA, ThetaB, and ThetaC in that order.
These values don’t change, no matter how much I jiggle the proto board on which the components are mounted.
The ‘H48C Tri-Axis Accelerometer’ object has not been changed in any way.
Is my H48C stuffed, or is it just that I don't know what I'm doing?
TIA David Young
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
What other connections do you have to the H48C? ... I think you baud rate is too fast 115200 ? I have a hard time at 38400 sometimes.
Can you attach your code as 'File->Archive->Project...' from the Propeller IDE so that we can see all of the associated objects?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Here’s the zip file from the Propeller Tool.
Connections are as per the diagram at the top of the H48C Tri-Axis Accelerometer DEMO file. Pin4 on the H48C is not connected to anything (and no 220Ohm resistor).
I tried 19200baud without success.
Any help appreciated.
I ran your code and connected P0,P1,P2,VSS, and +5V and everything seemed to work ok.
The only thing I can suggest is to double check your wiring, because the program will return
0 0 0 0 99 99 99 if any of the pins are not connected properly.
I did however run the baud at 19200 , the other setting of 115200 is just way too fast.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for your reply.
I’ve checked the connections, and I’m sure everything is OK.
One point – if I comment out, for example, ‘return H48C_thetaB’ in the H48C Tri-Axis Accelerometer object, the corresponding value on the screen is ‘0’. Am I correct in assuming that this means that the H48c is working?
TIA David Young
By the way, due to something akin to tunnel vision, I just recently discovered the "Edit Post" and "Delete Post" buttons myself. It's perhaps not too late to clean those posts up; however, by leaving them intact, they serve as a lesson/reminder for people like me that might want to post some code someday, for which the correct posting method is especially important considering the critical importance of indentation in SPIN.
"One point – if I comment out, for example, ‘return H48C_thetaB’ in the H48C Tri-Axis Accelerometer
object, the corresponding value on the screen is ‘0’. Am I correct in assuming that this means that the H48c
is working?"
I would say probably not, since the numbers...
0 0 0 0 99 99 99 <--- original code
0 0 0 0 99 0 99 <--- with ‘return H48C_thetaB’ remarked
... are returned even if the H48c is not present in your circuit. I would still say double check your wiring,
the first time I set my circuit up to confirm your readings I set it up wrong and got 0 0 0 0 99 99 99 as your
results indicate.
Can you take a picture of your setup so that we can see it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.