Read PWM signal from CMPS03 Compass Sensor Module

The CMPS03 compass module has been specifically designed for use in robots as an aid to navigation. A PWM signal is available on pin 4. The PWM signal is a pulse width modulated signal with the positive width of the pulse representing the angle. The pulse width varies from 1mS (0°) to 36.99mS (359.9°) – in other words 100uS/° with a +1mS offset. The signal goes low for 65mS between pulses, so the cycle time is 65mS + the pulse width - i.e. 66ms-102ms. The pulse is generated by a 16 bit timer in the processor giving a 1uS resolution; however I would not recommend measuring this to anything better than 0.1° (10uS). Make sure you connect the I2C pins, SCL and SDA, to the 5v supply if you are using the PWM, as there are no pull-up resistors on these pins. 

This program will read PWM signal from CPMS03 Compass Module and convert it to an angle. The PWM signal from pin 4 of compass module fed to port C pin 2 of ATmega8535 microcontroller. Note that we use 11.0592MHz clock frequency.
This program uses timer0 to measure the positive width of PWM pulse. At the positive-going-transition of PWM signal, timer0 goes on; and at the negative-going-transition of PWM signal, timer0 goes off. With prescaler=8, the timer will need 0.72338us per step counting. The timer will count 1382.4 (0x567) if the positive width of the pulse is 1ms. This value will be represented as 0 degree. And the timer will count 51148.8 (0xc7cc) if the positive width of the pulse is 37ms. This value will be represented as 360 degree.
The angle in 16-bit hexadecimal format can be read at the address of Compass_raw_loc of SRAM. This varies from 0 (0x0000) to 360 (0x0168). And the angle in 3-characters ASCII format can be read at the address of Compass_loc of SRAM. This varies from ‘000’ to ‘360’.

Download Program

What’s next? You can send the data to PC like data logger....

click here for more information 

No comments:

Post a Comment