View previous topic :: View next topic |
Author |
Message |
ringo
Joined: 10 Feb 2004 Posts: 8
|
Vector 2X Compass |
Posted: Mon Mar 15, 2004 1:28 pm |
|
|
Anyone ever use a Vector 2X compass? If so would you please send me your design and code?
Thanks,
Ringo
![Question](images/smiles/icon_question.gif) |
|
![](templates/subSilver/images/spacer.gif) |
dgi
Joined: 07 Jan 2004 Posts: 11 Location: Philadelphia, USA
|
|
Posted: Mon Mar 15, 2004 1:47 pm |
|
|
I used that compass, and I'd send you my code but I seem to have deleted it.
I remember the only tricky thing was the following:
I used the compiler's "spi_write" and "spi_read" except the polarity of the SPI needs to be reversed and there is no way to do this through the compiler. So get out the PIC data sheet and write to the register directly to change the polarity. (after calling "Setup_SPI" to set all the other registers except that one bit)
Use your oscilloscope to check the polarity and compare with the Vector data sheet.
-DGI. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Mar 15, 2004 2:06 pm |
|
|
dgi wrote: | I used that compass, and I'd send you my code but I seem to have deleted it.
I remember the only tricky thing was the following:
I used the compiler's "spi_write" and "spi_read" except the polarity of the SPI needs to be reversed and there is no way to do this through the compiler. So get out the PIC data sheet and write to the register directly to change the polarity. (after calling "Setup_SPI" to set all the other registers except that one bit)
Use your oscilloscope to check the polarity and compare with the Vector data sheet.
-DGI. |
The reversal can be done using the compiler. Look at:
'SPI_XMIT_L_TO_H' to reverse the transmit polarity.
This didn't exist a few (hundred!) compiler versions ago, and hence your need to go DIY if you were working some time ago. :-)
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
This might help |
Posted: Mon Mar 15, 2004 7:39 pm |
|
|
#include <16F84.h>
#FUSES HS,NOPROTECT,WDT
/* Vector 2x compass module
*/
#include <stdio.h>
#USE Delay(Clock=10000000,restart_wdt)
#USE RS232(BAUD=9600,XMIT=PIN_A3,RCV=PIN_A2,invert,restart_wdt)
#define Data_p PIN_B1 /* Pin1 */
#define SS_n PIN_B2 /* Pin 2 */
#define Data_n PIN_B1 /* Pin1 */
#define SCLK_n PIN_B6 /* Pin 6 */
#define P_C_n PIN_B3 /* Pin 3 */
#define EOC_p PIN_B4 /* Pin 4 */
#define CAL_n PIN_B5 /* Pin 5 */
#define status 3
#define carry 0
#define hi(x) (*(&x+1))
int const dev_id[8]= {0xfd,0x00,0x00,0x00,0x00,0x00,0x01,0x22}; // dow one wire id
int xmit_buff[2];
#define TOUCH_PIN pin_A4
int buff_size=2;
#include <dow.h>
signed long Vector()
{
signed long heading;
int i;
short int bitx;
/* pulse P_C_n */
OUTPUT_LOW(P_C_n);
DELAY_MS(12);
OUTPUT_HIGH(P_C_n);
/* end of pulse out */
Wait:
restart_wdt();
if (INPUT(EOC_p)==0) goto Wait;
/* EOC is now high */
DELAY_MS(10); /* pause 10 ms before bringing SS low */
OUTPUT_LOW(SS_n); /* Start this reading */
DELAY_MS(10); /* pause 10 ms before first clock pulse */
for(i=1;i<=16;i++){
OUTPUT_LOW(SCLK_n);
DELAY_US(10);
/* data is valid when the clock is low */
bitx=INPUT(Data_p);
SHIFT_LEFT(&heading,2,bitx );
OUTPUT_HIGH(SCLK_n);
DELAY_US(10);
}
OUTPUT_HIGH(SS_n); /* end this reading */
return (heading);
}
void update_buff(signed long heading)
{
xmit_buff[0]=heading;
xmit_buff[1]=hi(heading);
}
main() {
signed long int heading;
setup_counters(RTCC_INTERNAL,WDT_36MS);
output_float(TOUCH_PIN); // release line
ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
restart_wdt();
OUTPUT_HIGH(SCLK_n); /* Start clock high */
OUTPUT_HIGH(SS_n); /* Deselect initially */
OUTPUT_HIGH(P_C_n); /* Start in Poll mode */
OUTPUT_HIGH(CAL_n); /* Calibrate off */
delay_ms(500); // allow disply to warm up
putchar(254);
putchar(1);
delay_ms(100);
enable_interrupts(EXT_INT); // allow dow to interrupt
dowork:
restart_wdt();
if (dow_status==master_ready){
// master just interrupted and may have messed up LCD
putchar(254);
putchar(1);
dow_status=slave_ready;
}
heading=vector();
xmit_buff[0]=hi(heading);
xmit_buff[1]=heading;
dow_status=slave_ready;
putchar(254);
putchar(128);
printf(" %LX ",heading);
goto dowork;
} |
|
![](templates/subSilver/images/spacer.gif) |
ringo
Joined: 10 Feb 2004 Posts: 8
|
|
Posted: Tue Mar 16, 2004 9:41 am |
|
|
Thanks, for the code, that's what I was looking for.
Did you pull Y-flip, BCD, and Raw to ground?
You didn't need to use the reset line at all?
Were all other lines flaoting?
Thanks
Ringo |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Mar 16, 2004 7:34 pm |
|
|
ringo
I used this several years back for an autopilot for a boat.
I remember the vecto2x docs showed a hook up to a microprocessor it wasn't a pic but I used it as a guide.
I let
reset float
m/s float
SDI float
RAW was pulled high
I used binary so BCD was high
I used normal for the X Y flip
hope this helps. |
|
![](templates/subSilver/images/spacer.gif) |
|