|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Real time clocks, out of the question?
Yes, EasyC does have timers, six of them. I believe we have used up to three at once, and they all work fine.
What exactly isn't working for your? Could you post your code? Thanks, Nathan |
|
#2
|
||||
|
||||
|
Well, the problem is that I don't have any. Without EasyC, I just have the arm calculating based on loop counting. Multiples of 26.2 ms. There's no way I can switch to EasyC this year. I guess that would be a logical solution for next year.
Is there anyone here who has ever written a timer and interrupt routine for a real time clock? That's really the only thing I could worry about anyways. Otherwise I'll just have to stick with loop counting. |
|
#3
|
|||||
|
|||||
|
Re: Real time clocks, out of the question?
Timers are simple to use, no soldering required.
IFI has a white paper on coding timers that goes into the bits and bytes of it all: http://www.ifirobotics.com/docs/time...004-jan-14.pdf For a description of the timer library calls see the MPLAB-C18-Libraries.pdf manual under C:\mcc18\doc. Here's a sample using the timer libraries: Code:
// In user_routines.c
#include <timers.h>
#define CLOCKOFFSET 60535 //Set timer for 4ms
// Maximum for 16-bit timer 65535 - 5000 (4ms) = 60535
/* Use Timer3 (16-bits) to control our clock */
/* timer set to 4 ms */
// Call from User_Initialization()
OpenTimer3(TIMER_INT_ON &
T3_16BIT_RW &
T3_SOURCE_INT &
T3_PS_1_8
);
WriteTimer3(CLOCKOFFSET); /* Preload timer to overflow after 4ms */
Code:
// In user_routines_fast.c
#include <timers.h>
// globals declared as extern wherever else they are used
volatile unsigned long Clockms=0; // 1 millisecond clock
volatile unsigned int Clockds=0; // 1/10 second
volatile unsigned int Clocksec=0; // 1 second clock
//etc.
// In InterruptHandlerLow()
if (PIR2bits.TMR3IF) /* TIMER 3 INTERRUPT */
{
/** This provides us with a clock for timing events **/
PIR2bits.TMR3IF = 0; /* Clear Timer interrupt flag */
WriteTimer3(CLOCKOFFSET); /* Reset Timer to overflow in 4ms */
Clockms += 4; /* milliseconds */
Clockds = Clockms / 100;
Clocksec = Clockms / 1000;
// etc.
}
Last edited by Mark McLeod : 24-02-2007 at 12:17. |
|
#4
|
||||
|
||||
|
Thank you very much. I hope my assembly serves me well.
I think I can dig up the differences in the new controller. Want to be a mentor... just kidding. |
|
#5
|
|||||
|
|||||
|
Re: Real time clocks, out of the question?
Setting up just a realtime clock isn't that hard. I was thinking of doing it myself. I just have to figure out how to configure which timer to achieve something reasonable.
|
|
#6
|
|||
|
|||
|
Re: Real time clocks, out of the question?
Here is the code we used for a "clock". It uses Timer 2 and has a number of options for flexibility. It is not a "real time clock" in the sense that it doesn't compute hour/minute/second but works off clock "ticks", which for a 2 minute match, or a 15 second autonomous, works fine for us. By default, it's configured to count milliseconds (1 tick = 1 millisecond), but has 2 other predefined options for increased accuracy.
Mike |
|
#7
|
|||||
|
|||||
|
Re: Real time clocks, out of the question?
In teaching timers I use a demonstration program to calculate all the possible timer prescaler/postscaler combinations for a given Hertz or time period. It's an easy beginner exercise to write such a program for the PIC (or VB), and also can be used to teach them about maintaining the Master processor communication leading to an easy elimination of the Master handshake.
Here's a sample output calculating 2400 Hz used with an LCD display off a digital output. Last edited by Mark McLeod : 27-02-2007 at 13:11. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Networkable real-time game simulation for 'Aim High'! test it out now | Bongle | General Forum | 11 | 19-03-2006 23:10 |
| Real time photos from the buckeye regional | Greg Needel | Regional Competitions | 4 | 25-03-2004 12:46 |
| Robot motion after the time has run out. | Randy Ai | Rules/Strategy | 1 | 06-01-2003 17:17 |
| Real Time Scoring | archiver | 2000 | 2 | 24-06-2002 00:09 |
| real time chat | SharkBite | CD Forum Support | 4 | 07-02-2002 21:22 |