Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   quick question: TIMERS (http://www.chiefdelphi.com/forums/showthread.php?t=26637)

Astronouth7303 12-03-2004 20:16

Re: quick question: TIMERS
 
I just relized something. In the initialize routines for the timers, the first 2 lines are address setters (I think). Most of mine are 0x00! Does this make a difference?

Mark McLeod 12-03-2004 22:21

Re: quick question: TIMERS
 
Quote:

Originally Posted by Astronouth7303
I just relized something. In the initialize routines for the timers, the first 2 lines are address setters (I think). Most of mine are 0x00! Does this make a difference?

No. Those just mean the timer starts at 0.

Believe I found the problem.
TICKS is declared as char (-127 to 127)
You are checking for 255 as an overflow.
TIME will never increment.


I grabbed Kevins interrupt code and added your code to the interrupt handler.
Only difference is I just declared your globals as static just within interrupts.c for my ease of duplicating your results.

TICKS and AUTOCLOCK increment as you wanted.

In Initialize_Timer_1 I changed:
Code:

PIE1bits.TMR1IE = 1;
T1CONbits.TMR1ON = 1;


Xufer 12-03-2004 22:47

Re: quick question: TIMERS
 
before i enable one of those timers, is there anythign i should know about which one would work best are there significant differences for them, i noticed you can change the ammount of time each tick increses the clock by.

once i enable one im still confused as far as the state switches and the case statements, idon't understand how the whole thing works is there any documentation or sample code i can look through, im really stumped and i would like to get a timer working.

10intheCrunch 13-03-2004 22:58

Re: quick question: TIMERS
 
OK...I really want to help you dude but it seems like you don't understand what we're trying to say each time, or I can't explain it well enough...why don't you IM me (sn: TenintheCrunch)? I think I'll be able to help you more talking directly :)

Cheers,

Astronouth7303 15-03-2004 07:29

Re: quick question: TIMERS
 
I changed a compiler option to assume Char is unsigned. I only use a signed char one place, -1 - 1, and it's declared as signed. I also sent TICK to dashboard, and it didn't work. I didn't have IE set to 1, but I didn't think it would make a difference (it would just be slower, right?)

10intheCrunch 15-03-2004 10:14

Re: quick question: TIMERS
 
Where's the option for making chars unsigned by default? Does that affect ints and longs as well?

Mark McLeod 15-03-2004 10:36

Re: quick question: TIMERS
 
Quote:

Originally Posted by 10intheCrunch
Where's the option for making chars unsigned by default? Does that affect ints and longs as well?

You set compiler flags in MPLAB
Project->Build Options...->Project
under tab "MPLAB C18"

There is a quick radio button for treating "char" as unsigned and one for forcing all calculations to be performed at least as int rather than the smallest type included in the calculation.
You can also enter your own flags by clicking on "Use Alternate Settings" and typing into the box that becomes enabled. You'll find the available compiler flags documented in the MPLAB C18 C Compiler User's Guide that came on the MPLAB installation CD, Appendix C. e.g., -k is the flag for treating char as unsigned. When you click on the radio button you'll see "-k" appear in the "Inherit global settings" window.

Mark McLeod 15-03-2004 10:41

Re: quick question: TIMERS
 
Quote:

Originally Posted by Astronouth7303
I didn't have IE set to 1, but I didn't think it would make a difference (it would just be slower, right?)

If you mean:
INTCON3bits.INT2IE = 1;
Yes, this is required. It's your on/off switch for individual interrupts. It enables the interrupt which is disabled by default. Otherwise, nothing will happen.

Astronouth7303 15-03-2004 11:24

Re: quick question: TIMERS
 
Banner interupts work, but not timers.

Mark McLeod 15-03-2004 11:49

Re: quick question: TIMERS
 
Quote:

Originally Posted by Astronouth7303
Banner interupts work, but not timers.

Sorry I mistyped and used the external interrupt flag. I meant to type:
Code:

PIE1bits.TMR1IE = 1;
This is required to turn on interrupt on timer overflow.

Xufer 15-03-2004 16:23

Re: quick question: TIMERS
 
i got my ded reckoning worked out and i have a switch wired up to switch between the two modes how would i do that using case statements?

it should be something like


case1 if (rc_dig_in_10=1)
{auton 1}

case2 else(rc_dig_in10=0)
{auton 2}

i read about them but how would they be used to work with a digital input from the rc

Mark McLeod 15-03-2004 16:48

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
i got my ded reckoning worked out and i have a switch wired up to switch between the two modes how would i do that using case statements?

it should be something like


case1 if (rc_dig_in_10=1)
{auton 1}

case2 else(rc_dig_in10=0)
{auton 2}

i read about them but how would they be used to work with a digital input from the rc

You don't need a case statement if you only have two choices.
Code:

if (rc_dig_in_10 == 1)  //or just "if (rc_dig_in_10)"
{auton 1}
else
{auton2}


Xufer 15-03-2004 23:26

Re: quick question: TIMERS
 
Quote:

Originally Posted by Mark McLeod
You don't need a case statement if you only have two choices.
Code:

if (rc_dig_in_10 == 1)  //or just "if (rc_dig_in_10)"
{auton 1}
else
{auton2}


will that work if my autonmode begins in if statements though ? i tried something along those lines and it didnt seem to work...

Mark McLeod 16-03-2004 10:37

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
will that work if my autonmode begins in if statements though ? i tried something along those lines and it didnt seem to work...

It will work.
If you try it and it doesn't behave as you expect post the error here and we'll help you debug any problems.

10intheCrunch 16-03-2004 13:26

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
i got my ded reckoning worked out and i have a switch wired up to switch between the two modes how would i do that using case statements?

it should be something like


case1 if (rc_dig_in_10=1)
{auton 1}

case2 else(rc_dig_in10=0)
{auton 2}

i read about them but how would they be used to work with a digital input from the rc

You don't need to use case statements, but there are a couple other things you have to do.

When you enter autonomous mode, all inputs are reset to neutral, so you have to capture the value from rc_dig_in_10 before autonomous turns on. Create a prevRcDigIn10 variable, and set that equal to the current one at the end of every loop (right before putdata()), then when you move into autonomous, look at that previous varialbe, not the real one (the "real" one will always be zero).


All times are GMT -5. The time now is 12:47.

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