View Single Post
  #7   Spotlight this post!  
Unread 28-09-2007, 00:39
Phil Mack Phil Mack is offline
Registered User
FRC #0836 (RoboBees)
Team Role: Mentor
 
Join Date: May 2007
Rookie Year: 2007
Location: Maryland
Posts: 30
Phil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to behold
Re: Programming a Devantech Magnetic Compass - CMPS03

Quote:
Originally Posted by kE7JLM View Post
Can someone show me what is wrong?
This compass does not output an analog voltage. It outputs a pulse with a specific time, or byte values can be read over an I2C bus.

The timing pulse is high for 1mS to 37mS in 0.1mS increments and then low for 65mS. The rise and fall time is much faster (a few nanoseconds if i recall, but i cant find the datasheet right now). The ADC in the robot controller works fast enough that whenever it measures the voltage, the voltage will be either high or low... not in between.

You essentially have three options... use an additional micro controller, design a circuit, or write interrupt driven software.

The first option is the easiest (in my oppinion) and will give you the most accurate results. You can purchase or build an I2C master with an RS232 interface that the robot controller can communicate with. One elegant implementation of this is available at http://www.emicros.com/i2c232.htm for about $90, but one could be built for much less than that (I built a less elegant one in college using an AVR Butterfly that cost $20 and that was processing overkill.)

The second option would require a series of filters and amplifiers that would translate the pulse into a voltage. This one is a bit outside of my field of expertise, so I'll leave an explanation to someone else, because it would be a relatively complex circuit.

The third option to interface with this compass you have to measure the length of the pulse width using on board timers triggered by interrupts. You would want to scale one of the timers to use increments fairly close to but not over .1ms. The pulse out on the compass would trigger an interrupt, at which point the timer's count would be noted. The (count_at_fall - count_at_rise)/clock_scale_factor would be the width of the pulse and also your heading.

I hope this helps.
~Phil