PDA

View Full Version : getting the HM55B compass module to work



nico
12-02-2009, 03:52 PM
Hi,
I have use aˇBS to get data from other BS2s and use that BS2 to sendˇall the infomationˇto my computer. relay1, relay2 and LED are the data i get from the other BS2s. However, I want to do a compass module in the BS itself so that I can send readings from the compass to my computer. However, without inserting the compass code, my vb program are able to display information from relay1, relay2 and LED. When I inserted the compass code, all readings are empty. I have try without using my vb program and uses theˇdebug command to check. It's the same too. How can I make my compass and the other readings work too ?

The code with the compass code


' {$STAMP BS2}
' {$PBASIC 2.5}
relay1 PIN 0
relay2 PIN 1
LED PIN 2
DinDout PIN 6 ' P6 transceives to/from Din/Dout
Clk PIN 5 ' P5 sends pulses to HM55B's Clk
En PIN 4 ' P4 controls HM55B's /EN(ABLE)
Reset CON %0000 ' Reset command for HM55B
Measure CON %1000 ' Start measurement command
Report CON %1100 ' Get status/axis values command
Ready CON %1100 ' 11 -> Done, 00 -> no errors
NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits
x VAR Word ' x-axis data
y VAR Word ' y-axis data
status VAR Nib ' Status flags
angle VAR Word ' Store angle measurement
reading1 VAR Word
reading2 VAR Word
reading3 VAR Word
DO
IF relay1 = 1 THEN
reading1 = 1
ELSE
reading1 = 0
ENDIF
IF relay2 = 1 THEN
reading2 = 1
ELSE
reading2 = 0
ENDIF
IF LED = 1 THEN
IF LED = 1 THEN ' Motion Detected
reading3 = reading3 + 1 ' Update Trip Counter
DO : LOOP UNTIL LED = 0 ' Wait For PIR To Clear
ENDIF
ENDIF
'DEBUG HOME, "relay1"," = ", DEC1 reading1
'DEBUG CR, "relay2", " = ", DEC1 reading2

PAUSE 100
SEROUT 16,16468,[DEC1 reading1,DEC1 reading2,DEC1 reading3,DEC3 angle]
SEROUT 16,16468,[LF]
'DEBUG HOME, DEC1 reading1
'DEBUG CR, DEC1 reading2
'DEBUG CR, DEC1 reading3
'DEBUG CR, DEC angle
GOSUB Compass_Get_Axes ' Get x, and y values
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 360 ' Convert brads to degrees
'SEROUT 16,16468,[DEC3 angle]
'SEROUT 16,16468,[LF]
'DEBUG HOME, "x-axis N(-S) = ",SDEC x, ' Display axes and degrees
'CLREOL, CR, "y-axis W(-E) = ",
'SDEC y, CLREOL, CR, CR, "angle = ",
'DEC angle, " degrees", CLREOL
PAUSE 150 ' Debug delay for slower PCs
LOOP
' -----[ Subroutines ]--------------------------------------------------------
Compass_Get_Axes: ' Compass module subroutine
HIGH En: LOW En ' Send reset command to HM55B
SHIFTOUT DinDout,clk,MSBFIRST,[Reset\4]
HIGH En: LOW En ' HM55B start measurement command
SHIFTOUT DinDout,clk,MSBFIRST,[Measure\4]
status = 0 ' Clear previous status flags
DO ' Status flag checking loop
HIGH En: LOW En ' Measurement status command
SHIFTOUT DinDout,clk,MSBFIRST,[Report\4]
SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status
LOOP UNTIL status = Ready ' Exit loop when status is ready
SHIFTIN DinDout,clk,MSBPOST,[x\11,y\11] ' Get x & y axis values
HIGH En ' Disable module
IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis
RETURN
END


The code without the compass code


' {$STAMP BS2}
' {$PBASIC 2.5}
relay1 PIN 0
relay2 PIN 1
LED PIN 2

reading1 VAR Word
reading2 VAR Word
reading3 VAR Word
DO
IF relay1 = 1 THEN
reading1 = 1
ELSE
reading1 = 0
ENDIF
IF relay2 = 1 THEN
reading2 = 1
ELSE
reading2 = 0
ENDIF
IF LED = 1 THEN
IF LED = 1 THEN ' Motion Detected
reading3 = reading3 + 1 ' Update Trip Counter
DO : LOOP UNTIL LED = 0 ' Wait For PIR To Clear
ENDIF
ENDIF

PAUSE 100
SEROUT 16,16468,[DEC1 reading1,DEC1 reading2,DEC1 reading3]
SEROUT 16,16468,[LF]
'DEBUG HOME, DEC1 reading1
'DEBUG CR, DEC1 reading2
'DEBUG CR, DEC1 reading3

LOOP

END

nico
12-04-2009, 11:15 PM
someone ?

Mike Green
12-04-2009, 11:53 PM
First use the HM55B sample code to verify that your compass works with your setup. Make sure you've copied the Compass_Get_Axes code correctly.

Remember that your SEROUT statements in your program come before the GOSUB and the angle calculations, so the first angle sent to the PC will be garbage (probably zero).