Вы находитесь на странице: 1из 3

CCS :: View topic - Sub microsecond timing http://ccsinfo.com/forum/viewtopic.php?t=27891&highlight=inte...

FAQ Forum Help Official CCS Support Search Register

Profile Log in to check your private messages Log in

Sub microsecond timing

CCS Forum Index -> General CCS C Discussion

View previous topic :: View next topic

Author Message

hansknec Sub microsecond timing


Posted: Thu Aug 10, 2006 2:16 pm

Joined: 30 Sep 2004 I would be pleased to here any comments about the speed of execution of interrupts and C code
Posts: 15
Location: Virginia, USA with or without embedded assembly calls. In particular I would like to trigger on the rising edge
of an input TTL and immediately launch an output timing pulse. Can it occur in less than 1 usec?
What is the maximum trigger to trigger timing (phase) variation if this is a repeating stable clock
event? I'm thinking aloud now, but I'm assuming that there would always be a phase variation
of up to 100nsec from pulse to pulse since the incoming trigger could arrive at the beginning of
a system clock cycle or near the end of the cycle.

Project: PIC18F1220 at 40MHz. (25nsec per clock pulse, but this is 100nsec system clock
right?).
When TTL trigger arrives on an interrupt pin, take another pin high for 250usec, followed by
low for 100usec, followed by high for 4.2usec, then low again. The interrupt service routine
could then exit and wait for the next interrupt that is expected in about 16msec.

I have searched the forum for microsecond, interrupts, etc, but I can't locate a definitive
statement about code execution speed with regard to interrupts. I think the ultimate answer will
lead me to programming in assembly and I have very little experience with that.

Thanks, John

rwyoung Posted: Thu Aug 10, 2006 2:24 pm

I'm sure RJ or PCM Programmer will jump in and correct me but I believe the fastest you can get
Joined: 12 Nov 2003
Posts: 573 into your ISR is around 30 to 40 instructions using the CCS compiler. That requires writing your
Location: Lawrence, KS USA own generic handler and using a combination of the FAST and PRIORITY qualifiers. That was a
flip and off-hand description of the solution.

You might want to consider NOT using an interrupt if your PIC isn't going to be doing anything
except waiting for the edge. Set up a nice tight loop and poll for the edge transition instead.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!

PCM programmer Posted: Thu Aug 10, 2006 2:38 pm

Example of polling the INT_EXT flag (instead of using an isr):


Joined: 06 Sep 2003
Posts: 6775 http://www.ccsinfo.com/forum/viewtopic.php?t=27167&start=4

1 от 3 01.3.2007 г. 10:17
CCS :: View topic - Sub microsecond timing http://ccsinfo.com/forum/viewtopic.php?t=27891&highlight=inte...

hansknec Posted: Thu Aug 10, 2006 2:44 pm

In my past experience with PicBasic Pro (sorry), assembly interrupts were always faster than a
Joined: 30 Sep 2004
Posts: 15 tight loop looking for a change of state. Is this not the case with CCS C compiled code?
Location: Virginia, USA

In the example given, is this really just as fast as assembly code doing the same task?
Code:
clear_interrupt(INT_EXT);
while(!INTF); // Wait for rising edge

PCM programmer Posted: Thu Aug 10, 2006 2:54 pm

The interrupt dispatcher has to save and restore the state of the program.
Joined: 06 Sep 2003
Posts: 6775 That will always take longer than just polling a register bit.

Ttelmah Posted: Thu Aug 10, 2006 2:57 pm


Guest

hansknec wrote:

In my past experience with PicBasic Pro (sorry), assembly interrupts were always faster
than a tight loop looking for a change of state. Is this not the case with CCS C compiled
code?

In the example given, is this really just as fast as assembly code doing the same task?
Code:
clear_interrupt(INT_EXT);
while(!INTF); // Wait for rising edge

Faster.
The interrupt 'response' (time to actually reach the handler), will be slightly faster (at best a
couple of instruction times), but unless your cde only changes the registers automatically
saved/restored using RETFIE1, by the time you have saved even one extra register, the polled
loop will be winning...

Best Wihes

hansknec Posted: Thu Aug 10, 2006 3:05 pm

agreed. When I was talking about PBP it was with regard to the ability to have a low phase
Joined: 30 Sep 2004
Posts: 15 variation between captured edges. For some reason, polling the pin would give a horrible result.
Location: Virginia, USA
I understand that this is not polling the pin, but polling a register instead. I need to do some
reading to find out why it would be different for speed.

Thanks, John

Ttelmah Posted: Thu Aug 10, 2006 3:27 pm


Guest

The advantage of using the interrupt bit, is the ability to 'see' short signals. With the polled
loop, the bit has to be present for one 'loop time', if it is not to be missed. The interrupt flag
will get set by a signal that is present for just one clock cycle. The jitter will still be worse than
with the full 'interrupt' solution.

2 от 3 01.3.2007 г. 10:17
CCS :: View topic - Sub microsecond timing http://ccsinfo.com/forum/viewtopic.php?t=27891&highlight=inte...

Best Wishes

hansknec Posted: Thu Aug 10, 2006 3:40 pm

ding! Light just turned on. I forgot about that.


Joined: 30 Sep 2004
Posts: 15
Location: Virginia, USA In the mean time I've been reading over a tutorial for assembly. I'm sure it will benifit me in the
end for quick bit manipulations.

Thanks, John

Display posts from previous: All Posts Oldest First Go

All times are GMT - 6 Hours


CCS Forum Index -> General CCS C Discussion

Page 1 of 1

Jump to: General CCS C Discussion Go

You can post new topics in this forum


You can 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

3 от 3 01.3.2007 г. 10:17

Вам также может понравиться