Go to Post Once we know how magic works it's no longer magic; it becomes science. - Karthik [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 04-02-2005, 22:35
MaxM's Avatar
MaxM MaxM is offline
Registered User
#0473 (Corvallis High School Robotics)
Team Role: Student
 
Join Date: Feb 2003
Location: Corvallis, Montana
Posts: 13
MaxM is on a distinguished road
Send a message via AIM to MaxM Send a message via MSN to MaxM
Unhappy Kevin Watson's encoder code with RPM output

I'm the programmer on Team 473. I've been trying to use Kevin Watson's encoder code to measure the RPMs of our transmission in order to write a shift scheduler. I've been trying to do this by getting the number of encoder counts which occur over 25 cycles of Process_Data_From_Master_uP. Since Process_Data_From_Master_uP runs every 26.2 ms, I can convert from rpms into encoder cycles per Process_Data_From_Master_uP runs. However, this is not giving me anything near an accurate RPM output (I have a digital tachometer to check the RPMs with).

Here's my code from Process_Data_From_Master_uP:
Code:
	if (++counter >= (24))
	{
		Left_Encoder_Count = Get_Left_Encoder_Count();
		printf("RPM Left: %5d\n",(int)((Left_Encoder_Count - previous_count_left)*0.698666667));
		previous_count_left = Left_Encoder_Count;
		counter = 0;
	}
0.698666667 is the conversion factor counts per 25 Process_Data_From_Master_uP cycle to RPMs. (1 rotation/1 min*1 min/60 sec*1 sec/1000ms*655 ms (25*26.2ms)/1 program cycle*65 counts/1 rotation)

Either my conversion factor is totally wrong or my method is totally wrong (or my tachometer is wrong, but since it's digital I don't think it is). Can anyone help?

Thanks,
__________________
Max Masnick
Montana Robotics Team 473
  #2   Spotlight this post!  
Unread 04-02-2005, 23:40
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: Kevin Watson's encoder code with RPM output

Two things...

1. The cycle time of 26.2 ms is approximate. To get accurate timing, write a timer interrupt routine.

2. Integer arithemetic! You are multiplying by 1... Try doing the math outside of the printf. Multiply by 6987 and store into a long int variable. Now divide by 10000 and store in an int variable. Now printf your int.

Regards,
__________________
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...
  #3   Spotlight this post!  
Unread 05-02-2005, 00:06
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Kevin Watson's encoder code with RPM output

Quote:
Originally Posted by Mike Betts
...Integer arithemetic! You are multiplying by 1... Try doing the math outside of the printf. Multiply by 6987 and store into a long int variable. Now divide by 10000 and store in an int variable. Now printf your int.
Or multiply by 45788 (2^16 * 0.6986666...) and then right shift sixteen bits or just grab the high order sixteen bits of the thirty-two bit long. Man, I dig this stuff <grin>.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
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
Team THRUST - Kevin's Code and Camera Code Combine Chris_Elston Programming 3 31-01-2005 22:28
Kevin Watson's Kick-off Demo Code! Mr. Lim Programming 27 22-01-2005 03:38
Updated Encoder Code Available Kevin Watson Programming 2 04-01-2005 01:00
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Rookie Programmer has question about the default code DanL Programming 3 26-01-2002 19:59


All times are GMT -5. The time now is 02:42.

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