Anonymous

Project:HM55B: Difference between revisions

From London Hackspace Wiki
2,104 bytes added ,  12 December 2010
Line 69: Line 69:
There should now be +5v measured between HM55B pins 3 and 6.
There should now be +5v measured between HM55B pins 3 and 6.


=== Abridged command set ==  
=== Abridged menu options ===  


To cover this use case:
To cover this use case:


<pre>
<pre>
? help      
? help
   
/\ Clock H/L ~ CLK pin
/\ Clock H/L ~ CLK pin
-/_ Data H/L ~ MOSI pin
-/_ Data H/L ~ MOSI pin
! Read bit  ~ MISO pin
! Read bit  ~ MISO pin
[] CS L/H    ~ CS pin   
[] CS L/H    ~ CS pin   
& 1uS delay
 
&/% Delay us/ms
 
: Repeat  
: Repeat  
</pre>
</pre>


=== Reset===
=== Reset HM55B===


Reading in plain english, "Set clock pin to low, set CS pin to low, shift out b0000 on the rising edge of the clock, delay 1uS, repeat delay 10 times then set CS pin to high".
Reading in plain english, "Set clock pin to low, set CS pin to low, shift out %0000 on the rising edge of the clock then set CS pin to high".


Noting that CS maps to active low /EN pin.
Noting that CS maps to active low /EN pin.


  \[/_\/_\/_\/_\]
  \[/_\/_\/_\/_\]
Bus Pirate output:
<pre>
CLOCK, 0
CS ENABLED
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CS DISABLED
</pre>
=== Start measurement ===
''Start a measurement by taking /EN low again, then shift-out %1000. Leave /EN low until checking the measurement status.''
\[/-\/_\/_\/_\
Bus Pirate output:
<pre>
CLOCK, 0
CS ENABLED
CLOCK, 1
DATA OUTPUT, 1
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
</pre>
=== Checking measurement status ===
''To check the measurement status, start by sending a positive pulse to /EN. Then, shift-out %1100.''
][/-\/-\/_\/_\
Bus Pirate output:
<pre>
CS DISABLED
CS ENABLED
CLOCK, 1
DATA OUTPUT, 1
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 1
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
CLOCK, 1
DATA OUTPUT, 0
CLOCK, 0
</pre>
=== Polling ===
''Shift in the status flag, upon receipt of %1100, discontinue polling.''
!!!!
Bus Pirate output:
<pre>
READ BIT: 1
READ BIT: 1
READ BIT: 0
READ BIT: 0
</pre>


=== Take sample ===
=== Take sample ===
1100 is the response for success, 00xx is for incomplete, xx11 is error, see p9 of datasheet)


\[/-\/_\/_\/_\&&]&:10[&:10/-\/-\/_\/_\!!!!&!!!!!!!!!!!&!!!!!!!!!!!]
''Leave /EN low, and move on to shifting-in the x and y-axis values.''


READ BIT: 1
''Shifting-in the x and y-axis values is a simple matter of shifting-in 11 bits for the x-axis measurement followed by 11 more bits for the y-axis measurement. After completing the y-axis shift-in, set the /EN pin high again.''
READ BIT: 1
READ BIT: 0
READ BIT: 0
DELAY 0b00000001uS
READ BIT: 0
READ BIT: 0
READ BIT: 0
READ BIT: 0
READ BIT: 0
READ BIT: 0
READ BIT: 1
READ BIT: 0
READ BIT: 0
READ BIT: 0
READ BIT: 0
DELAY 0b00000001uS
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 0
READ BIT: 0


Note that &:50000 isn't enough of a delay, but && works, presumably because BusPirate parser adds a huge delay.  This means that we don't know how fast this module can be clocked, because each ! will be > 50ms apart.
!!!!!!!!!!!!!!!!!!!!!!]


The [http://dangerousprototypes.com/docs/SPI BusPirate wiki] suggests this will work (since we've determined that it still provides the 22 sample bits even if the reading is incomplete):
Bus Pirate output:
<pre>
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 0
READ BIT: 1
READ BIT: 1
READ BIT: 0
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 0
READ BIT: 1
READ BIT: 1
READ BIT: 1
READ BIT: 1
CS DISABLED
</pre>
 
=== Converting the reading to an angle ===
 
''The x-axis reports (field strength) × cos(θ), and the y-axis reports the (field strength) × sin(θ). To resolve θ into a clockwise angle from north, use arctan(-y/x)''
 
angle θ = arctan(-y/x)
 
In the example:
 
x = 0b11111101101
y = 0b11111101111
 
''The Hitachi HM55B chip on the Compass Module reports its x and y axis measurements in terms of microteslas (μT) in 11-bit signed values.''
 
Since both most significant bits equal one, x and y are negative and we take the two's complement:
 
11111101101
00000010010
00000010011
 
x = -19
 
11111101111
00000010000
00000010001
 
y = -17
 
angle θ = arctan(17/-19)


\[0b0000 &]
angle θ = -41.82
[0b1000 && ]&[& 0b1100 r:4]


Sample readings:
=== Sample readings: ===


0,-6
0,-6
Line 139: Line 254:


-1,-19
-1,-19
=== Combining all commands ===
A delay is required between starting the measurement and shifting in a measurement completed status flag:
\[/_\/_\/_\/_\][/-\/_\/_\/_\][/-\/-\/_\/_\&&&&&&!!!!!!!!!!!!!!!!!!!!!!!!!!]
Note that &&&&&& works but &:6 does not, even though the nominal value in both cases is the same, presumably because BusPirate parser adds a huge delay.  This means that we don't know how fast this module can be clocked, because each ! will be > 50ms apart.
The [http://dangerousprototypes.com/docs/SPI BusPirate wiki] suggests this will work (since we've determined that it still provides the 22 sample bits even if the reading is incomplete):
\[0b0000 &]
[0b1000 && ]&[& 0b1100 r:4]


=== Exiting ===
=== Exiting ===
Anonymous user