Go to Post The numbers that I gave were purely theoretical and should not be considered realistic - Karibou [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2005, 09:08
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Floats

Quote:
Originally Posted by Dave Flowerday
I think you're missing a key point here: the microprocessor inside the RC does not support floating point operations in hardware.
...oh
That kind of deflates my entire argument. Never mind...
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
  #2   Spotlight this post!  
Unread 02-02-2005, 11:18
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Floats

Steven,

To expand for the benefit of other interested viewers, I thought I'd chime in...

I am entirely in agreement with Dave, Dave and Tristan on this issue. Never use floating point...

Let’s look at a sin function. According to Microchip application note AN660, the math library “sin” function has a performance of 4030 (minimum) to 6121 (maximum) machine cycles. Note: This data is for the PIC16 family. I could not find PIC18 data but I expect it is similar.

As my fixed point integer representation, I choose 0x0400 = 360 degrees for my integer variable “theta”. This is a granularity of about 1/3 of a degree (I dare you to argue that you need more. A table of integers (0x4000 = 1.000) is generated in Excel for the 1024 data points required and included into the code as a rom const int array named sine_table (2K of program memory used).

The statement

sine = sine_table [theta];

executes in 15 machine cycles. Note that you get cos just as easy from the same array:

cosine = sine_table [(theta + 0x0100) % 0x0400];

If using 2K of program space bothers you, you can use various math techniques such as a Taylor series expansion (see this thread for a discussion).

Regards,

Mike

Post Script: I never saw Seth's last question in the above link until just now...

Code:
// sine_table is an array of 1024 2FX14 integers where 0x4000 = 1.0 and 0xC000 = -1.0
// sine.csv is a slightly modified "comma separated variable" file created by Excel.
// The declaration "rom const" causes this array to exist in the PIC program space.
 
rom const int sine_table[DEG_360] = 
{
 #include "sine.csv"
};


Sorry for not responding sooner Seth... - Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Favorite Monty Python Sketch/Movie Joe Matt Chit-Chat 47 30-03-2004 21:45
EduCAD and Arrays!!!!! Sachiel7 Programming 14 03-11-2003 03:21
Exponenets and floats Jonbca Programming 4 31-01-2003 08:28


All times are GMT -5. The time now is 20:26.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi