Connecting the CMPS01/03 to the BS2 using the PWM Signal 

Introduction
The compass module uses either a PWM output or the I2C bus for communications. This example uses the PWM Signal. The example provided here uses PULSIN command. The PULSIN timing varies with the type of Stamp used. The BS2 and BS2e have 2uS resolution. The BS2sx has 0.8uS and the BS2p is 0.75uS.  The example code below shows the calculation for each and is therefore suitable for use with all BS2 variants. It has been tested with the BS2 and BS2p.
The BS2 internal 5v regulator is not suitable for powering much external circuitry. I therefore recommend you use a separate 5v regulator.

Circuit Schematic for connecting the BS2 Stamp to the CMPS01/CMPS03 Compass Module using the PWM Signal

Note the switch connecting pin 6 to Ground. This is all that is needed for calibration of Rev7 Firmware.

Software
The sample code below displays the compass bearing in Degrees (0-359) in a Debug window on the PC.
It can be downloaded here

'{$STAMP BS2}

'***********************************************************
'**                                                       **
'**          PWM Routines for the Basic Stamp             **
'**         using the CMPS01/03 Compass Module            **
'**                                                       **
'**           Copyright 2002 - Devantech Ltd              **
'**     Commercial use of this software is prohibited     **
'**     Private and educational use only is permitted     **
'**                                                       **
'**         Written by Gerald Coe - January 2002          **
'**                                                       **
'**       This Code has been Tested on BS2 and BS2p       **
'**   It should work equally well on the BS2e and BS2sx   **
'**                                                       **
'***********************************************************

bearing var word

main:
  pulsin 8, 1, bearing                          ' Get reading
  bearing = (bearing-500)/50                    ' BS2(e) - Calculate Bearing in degrees
  ' bearing = (bearing-1250)/125                ' BS2sx - Calculate Bearing in degrees
  ' bearing = (bearing-1333)/133                ' BS2p - Calculate Bearing in degrees
  debug 2,1,1, "Compass Bearing ", dec3 bearing ' Display Compass Bearing
  goto main                                     ' around forever

You can find Compass Documentation Here as well as a small FAQ