View Single Post
  #8   Spotlight this post!  
Unread 27-09-2007, 19:01
jgannon's Avatar
jgannon jgannon is offline
I ᐸ3 Robots
AKA: Joey Gannon
no team
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Pittsburgh, PA
Posts: 1,467
jgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond repute
Re: Interfacing a digital compass with the RC

Quote:
Originally Posted by kE7JLM View Post
We have a Devantech CMPS03 Digital Compass I would apresiate if someone could give me some step by step instructs on hw to do this, please.
I've been wanting to publish the code for this, as well as some other code, for quite some time, but I can't get a hold of Kevin Watson to allow me to reprint parts of his code. So here's the best I can do.

Step one: Get a copy of Kevin Watson's interrupt code here.
Step two: Enable timer 1, set the prescaler to 1:8, change register operations to 8-bit accesses, and disable the timer 1 interrupt. These are all documented in Initialize_Timer_1(). Also, enable interrupt 1 in Initialize_Interrupts().
Step three: Add these declarations to the top of interrupts.c. Increasing the value of SAMPLES should decrease the noise in your readings, to an extent:
Code:
#define SAMPLES 1
unsigned char Temp_Buf;
unsigned int Timer_Snapshot;
unsigned int Readings[SAMPLES];
unsigned char p=0;
Step four: Replace the blank Int_1_Handler() with:
Code:
void Int_1_Handler(void)
{
  Temp_Buf = TMR1L;
  Timer_Snapshot = TMR1H;
  if(Temp_Buf == 0xFF)
    Timer_Snapshot--;
  Timer_Snapshot <<= 8;
  Timer_Snapshot += Temp_Buf;
  TMR1L = 0;
  TMR1H = 0;
  Readings[p++] = ((Timer_Snapshot - 0x4000) / 125) % 360;
  p %= SAMPLES;
}
Step five: Add this to the end of interrupts.c (and add the appropriate prototype to interrupts.h):
Code:
unsigned int Get_Compass(void)
{
  int i,x=0;
  for(i=0;i<SAMPLES;i++)
    x+=Readings[i];
  return x/SAMPLES;
}
Step six: Wire pin 1 on the compass to +5V on digital I/O 1 on the RC, pin 4 to signal, and pin 9 to ground.
Step seven: Call Get_Compass() to get the current reading from the compass... I can't remember right now if the value is in degrees or tenths of degrees, but you should be able to figure it out pretty quickly.

Best of luck!
__________________
Team 1743 - The Short Circuits
2010 Pittsburgh Excellence in Design & Team Spirit Awards
2009 Pittsburgh Regional Champions (thanks to 222 and 1218)
2007 Pittsburgh Website Award
2006 Pittsburgh Regional Champions (thanks to 395 and 1038)
2006 Pittsburgh Rookie Inspiration & Highest Rookie Seed

Team 1388 - Eagle Robotics
2005 Sacramento Engineering Inspiration
2004 Curie Division Champions (thanks to 1038 and 175)
2004 Sacramento Rookie All-Star

_

Last edited by jgannon : 27-09-2007 at 19:04.