|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
Re: quick question: TIMERS
Yes, it does have timers (4), but I couldn't figure out how to use them, and didn't feel the need to try much. If someone knows how, those would also work.
|
|
#17
|
||||
|
||||
|
Re: quick question: TIMERS
Quote:
-Kevin |
|
#18
|
|||||
|
|||||
|
Re: quick question: TIMERS
I have had problems with interupts.c and timers. I use Timer 2 (and/or 1) to increment a variable and if that variable overflows, it increments another one. The problem is that I can't ever seem to get either to change. Help?
|
|
#19
|
|||||
|
|||||
|
Re: quick question: TIMERS
Quote:
Here's a sample initialization of Timer 4 to cause a 4ms interrupt. Code:
OpenTimer4(TIMER_INT_ON & T4_PS_1_16 & T4_POST_1_10); WriteTimer4(6); /* Preload timer to overflow after 4ms */ Code:
unsigned long Clockms; // 1 millisecond clock
unsigned long Clockcs; // 100 millisecond
unsigned long Clocksec; // 1 second clock
static unsigned char t100ms=0;
static unsigned int t1sec=0;
...
else if (PIR3bits.TMR4IF) /* TIMER 4 INTERRUPT */
{
/** This provides us with a clock for timing events **/
PIR3bits.TMR4IF = 0; /* Clear Timer interrupt flag */
WriteTimer4(6); /* Reset Timer to overflow at 4ms */
Clockms += 4; /* milliseconds */
if (++t100ms >= 25)
{
t100ms = 0;
Clockcs++; /* tenths of seconds */
if (++t1sec >= 10)
{
t1sec = 0;
Clocksec++; /* seconds */
}
}
}
Last edited by Mark McLeod : 12-03-2004 at 10:13. |
|
#20
|
||||
|
||||
|
Re: quick question: TIMERS
Quote:
|
|
#21
|
||||
|
||||
|
Re: quick question: TIMERS
now if i was to use the timers that kevin has on his site inorder to do a dedreckoning autonomus what would it look like ? I begin to have a little more trouble when the interrupts are thrown in there i looked through the actuall clock.c file and the user_routines_fast.c file how would i specify time lengths for an action ? Im not too sure how the interupts work i read the first white paper on them but my understanding of them are still kinda wavy.
|
|
#22
|
|||||
|
|||||
|
Re: quick question: TIMERS
Quote:
e.g., Code:
if (Clock < 10) // Clock is in tenths of seconds // Do first thing else if (Clock < 30) // @ 3 second // Do another thing else if (Clock < 60) // @ 6 seconds // Keep adding stuff to do . . . else if (Clock < 150) // @ 15 seconds // Make sure you stop all engines at the end [edit] Corrected the ">" , typed too freely. Thanks Jamie! Last edited by Mark McLeod : 12-03-2004 at 19:08. |
|
#23
|
|||||
|
|||||
|
Re: quick question: TIMERS
The timer (1-4, actually) is initialized, and I have checked the enabled bit. The overflow variable (a char) is to slow it down. I send the long both over the terminal and through the dashboard. Both always say 0. The code looks like it should work, but doesn't. This is my ISR:
Code:
extern char TICK;
extern long TIME;
extern long AUTOCLOCK;
void Timer_1_Int_Handler(void)
{
TICK++;
if (TICK == 255)
{ TIME++; }
AUTOCLOCK++;
}
|
|
#24
|
|||||
|
|||||
|
Re: quick question: TIMERS
make sure its not only enabled, but i think you have to start it too
|
|
#25
|
||||
|
||||
|
Re: quick question: TIMERS
i got kevins interrupt code and i looked through it, how do i call one of the timers to start counting ? then how would i implement it into autonomus ?
|
|
#26
|
||||
|
||||
|
Re: quick question: TIMERS
Call the start method in the User_Initialization function (Timer2Start() or Timer4Start() or whatever it is). Then, use the state machines that we told you about in the first page of this thread. In the StateInit() function, set a new variable like StartTime or something to keep track of where the timer was when you moved into the next state. Then just subtract the start from the actual, and when that value is larger than the one you want (how long you want to stay in the state), move to the next state and call the Init function.
|
|
#27
|
|||||
|
|||||
|
Re: quick question: TIMERS
Initialize_Timer_X, And you have to modify the line that reads: TxCONbits.TMRxON = 0; to TxCONbits.TMRxON = 1;, else the timer won't go.
|
|
#28
|
|||||
|
|||||
|
Re: quick question: TIMERS
Quote:
Your code looks file of course. Have you tried displaying TICKS on the dashboard or terminal to see if it is also not getting incremented? I have to run now, but I'll be back later and try to duplicate what you did in a test program. |
|
#29
|
|||||
|
|||||
|
Re: quick question: TIMERS
Quote:
Code:
extern long TIME; extern long AUTOCLOCK; extern char TICK; The User_Routines_Fast.c Interuptor (Actually executed by proc) is this, just to check: [code]#pragma code InterruptVectorLow = LOW_INT_VECTOR void InterruptVectorLow (void) { _asm goto InterruptHandlerLow // jump to InterruptHandlerLow() _endasm } #pragma code //... #pragma interruptlow InterruptHandlerLow save=PROD,section("MATH_DATA"),section(".tmpdata") void InterruptHandlerLow() { //... }[/check] I didn't edit this (to my knowledge ), so I can't imagine that would be it. The code is compiling fine, no errors or warnings. |
|
#30
|
|||||
|
|||||
|
Re: quick question: TIMERS
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick Question | Burgabot | Programming | 31 | 02-12-2003 19:22 |
| Quick <hr> question | Jack | Website Design/Showcase | 1 | 31-01-2003 22:19 |
| A quick question | Joelster | Technical Discussion | 6 | 10-02-2002 09:09 |
| quick question about qualifying points | Hymnson | General Forum | 4 | 25-09-2001 21:19 |
| Quick Question, i guess | Andrew Rudolph | Motors | 1 | 12-08-2001 14:39 |