![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
SkeeterHawk
Joined: 16 Oct 2010 Posts: 31 Location: Florissant, CO
|
get_ticks not counting high enough |
Posted: Mon Nov 19, 2012 8:55 pm |
|
|
I am trying to make a timer to count mS up to around 24-32 bits for a "session timer". I am trying to use the #USE TIMER(TIMER=1,TICK=1ms,BITS=32,NOISR) pre-processor and the Set/get ticks functions to use it. Here is basically what I am trying to accomplish in the code:
Code: |
#USE TIMER(TIMER=1,TICK=1ms,BITS=32,NOISR) // Get Timer1 ready to serve at the mercy of the Tick counter
void CheckEncoderMotion (void)
{
int8 EncoderTemp;
EncoderTemp = (input_e() & 0b00011110);
if (EncoderTemp ^ EncoderCurrent) // Check to see if the current masked encoder is different than the last "current" reading
{
EncoderHistory = EncoderCurrent; // Backup the new setting to the global registers
EncoderCurrent = EncoderTemp;
EncoderTimeAccu = get_ticks(); // Get the current tick reading so we know how many mS it has been
set_ticks(0x00000000); // Clear the tick register so that we can start counting new
}
return;
}
|
For some reason it seems like it is getting "stuck" and will only increment the first few bits. I would really appreciate it if someone could give me a clue as to why it isn't filling up this 32-bit register.
This seems to be a rather obscure function, so your input is greatly appreciated. _________________ Life is too short to only write code in assembly... |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Nov 20, 2012 1:04 am |
|
|
You don't post a complete program so we will have to guess some details:
First obvious answer would be that it never counts high because you keep setting it to zero. That is, I expect your encode to be called every few milliseconds?
If your encoder is slow and you expect larger time outs, then the second answer would be the NOISR parameter. With this parameter present it is up to your code to call the get_ticks function before it overflows. How fast the timer overflows depends on your PIC model. An 8 bit timer with your settings would overflow in 255ms.
Please provide PIC type number, program version and a small but _complete_ program for more help.
Then another tiny style remark: Code: | if (EncoderTemp ^ EncoderCurrent) // Check to see if the current masked encoder is different than the last "current" reading | I find the XOR construction difficult to read, I always have to think three times what's happening to understand the code. You expect the same trouble, that's why you added the comments. Much better is to write code that shows your intention and then have the compiler worry about optimizations. Speed isn't critical here anyway and though I didn't check the resulting assembly code I doubt your version is faster than the easier to read: Code: | if (EncoderTemp != EncoderCurrent) // Reading changed? |
|
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Nov 20, 2012 5:10 am |
|
|
Yes, with NOISR the tick counter will only be updated when you call get_ticks(). To get it to update automatically use ISR AND enable global interrupts, even if your code does use any (other) interrupts. The compiler will supply the necessary interrupt routine, though probably not as C source.
Also be aware you might not get precisely the tick interval you requested. It will give the nearest available and generate a compiler warning telling you the actual tick time. or so the help says as I confess I hadn't seen this before and even the help index in my PCWH 4.132 doesn't have this function!
RF Developer |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|