Go to Post FIRST gives everyone lots of practice in getting used to late nights. - waialua359 [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 09-02-2005, 17:39
Orborde Orborde is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Apr 2004
Rookie Year: 2003
Location: Indianapolis, IN
Posts: 44
Orborde has a spectacular aura aboutOrborde has a spectacular aura about
Send a message via AIM to Orborde
System Clock?

I'm pretty new at this programming stuff, and as we're trying to get a speed control on our robot's wheels together, I concluded that we needed some way to record time. I came up with the following, which will keep track of the time since powerup:

Code:
/* clock.h */ 

#ifndef CLOCK_H
#define CLOCK_H

typedef unsigned long int clock_int;

/* sets up the clock interrupts and such */
void clock_init();

/* runs every time the clock hits an interrupt */
void Clock_Interrupt_Handler();

/* starts the clock ticking */
void clock_start();

/* halts the clock */
void clock_stop();

/* returns the current clock time safely */
clock_int Get_Clock_Time();

#endif


/* clock.c */
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "clock.h"

volatile clock_int clock_time;	// time elapsed since last boot * .1msec

/* sets up the clock interrupts and such */
/* call this from User_Initialization */
void clock_init()
{
	clock_time = 0;
};

/* runs every time the clock hits an interrupt */
void Clock_Interrupt_Handler()
{
	//
};
/* starts the clock ticking */
void clock_start()
{
	// enable the clocking interrrupt
};

/* halts the clock */
void clock_stop()
{
	// disable the clocking interrupt
};

unsigned long int Get_Clock_Time()
{
	unsigned long int time;
	
	/* halt the clock for reading */
	clock_stop();

	/* read the time */
	time = clock_time;

	/* start the clock again ASAP */
	clock_start();

	return time;
};
Explanation of the above:
All times are of type clock_int, which is an unsigned long int (32 bits).
clock_init() is called in User_Initialization and will set up the interrupts for the timer.
Clock_Interrupt_Handler() is called from the interrupt handling routine; it checks to see if the timer triggered the interrupt, and if so, increments clock_time.
Get_Clock_Time() safely returns the value of clock_time.

The timer interrupt will be so arranged as to trigger every .1 msec. Thus, the clock ticks every .1 msec. Doing the math on that shows me that the RC could run for nearly 5 days continuously before the clock resets to 0. I think it's a pretty safe bet that no match will go on that long, so I now have a safe way of timing things by simple subtraction.

Comments? I'll be the first to admit I'm a n00b. Is this a totally insane way of doing this? Is there some RC feature that does this for me? Or am I a Clever Boy for putting it together?
 


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
Multiple Auton's Joe Clohessy Programming 17 11-02-2005 18:46
Building a Clock with Periodic Motion IMDWalrus Math and Science 15 24-03-2004 16:48
What do you wish you knew about the new control system? Joe Ross Control System 2 09-01-2004 21:47
control system worth more than $500 archiver 2001 8 24-06-2002 02:00
New Innovation FIRST control system and the dashboard archiver 2000 0 23-06-2002 22:15


All times are GMT -5. The time now is 13:04.

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