Thanks Dave!
In that case, the PIC16 should work for you Samuel. But it does need some modification to enable you to find the angle throughout 360 degrees. The PIC16 cordic only does 0 to 90 degrees. But the rest can be done pretty easily with PicBasic. I think it handles around 2000 iterations per second, but I may have been doing a few more equations when I measured that.
Here is some code that works on a Pic16F877a:
And the pic16 trig file: http://sites.picbasic.net/media/uhp2...trig_pic16.txtCode:'**************************************************************** '* Name : UNTITLED.BAS * '* Author : Walter Dunckel * '* Notice : Copyright (c) 2009 Scale Robotics Inc. * '* : All Rights Reserved * '* Date : 10/7/2009 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** DEFINE __16F877A 1 ; list directive to define processor DEFINE OSC 20 ' Define Oscillator Speed DEFINE LOADER_USED 0 include "trig-pic16.inc" ' Shutdown comparators ADCON1 = 7 ; Turn of all A/D CMCON = 7 ' Set the port directions ' 0=output 1=input TRISA=%00000011 ' Set PORTA 0-1-3 used for AD TRISB=%11011100 ' Set PortB TRISC=%10000000 TRISD=%00000000 ' Set PortC USART RX as an input porta.2 = 0 porta.3 = 0 x var word y var word z var word i var word lon_dif var word lat_dif var word angle var word angle_deg var word distance var word j var word ;---------[change these to match your hardware]------------------------------ DEFINE LCD_DREG PORTD ; Set LCD Data port B C D DEFINE LCD_DBIT 0 ; Set starting Data bit (0 or 4) 4 0 DEFINE LCD_RSREG PORTA ; Set LCD Register Select port A A DEFINE LCD_RSBIT 3 ; Set LCD Register Select bit 3 2 DEFINE LCD_EREG PORTA ; Set LCD Enable port A A DEFINE LCD_EBIT 1 ; Set LCD Enable bit 1 5 DEFINE LCD_BITS 4 ; Set LCD bus size (4 or 8 bits) 4 4 DEFINE LCD_LINES 2 ; Set number of lines on LCD 2 2 '---------------------------------------------------------------------------- clear lcdout $FE,1 ' to convert degrees to radians Z_ * 256 / 90 ' to convert radians to degrees Z_ * 90 / 256 Start: x = 0 y = 0 z = 0 Z_ = 90 'put angle in Z_ in degrees Z_ = (Z_ * 255)/90 'convert degrees to radians Call sincos 'perform sin and cos on Z_ value 'cos(Z_) = X_ :sin(Z_) = Y_ lcdout $FE,1,"cos Z=",#X_ lcdout $FE,$C0,"sin Z=",#Y_ end




Bookmarks