Joel is right, interrupt every 1us is overkill. Minimalistic interrupt
service routine, even without mandatory flag clear sequency would take 9+8
bus cycles (SWI+RTI). That's 0.68us at 25MHz bus. Add here required timer
flag clear and CPU will be almost 100%.
If you need 1us counter, then why not using free running TCNT for this
purpose? If application allows, then you could set prescaler so that TCNT
tick is close to 1us. If you can't, then TCNT readings should be scaled to
1us resolution. If you need wider than 16bits counter, then you could use
timer overflow interrupt to increment higher order word of counter and use
TCNT as a lower order word of counter.
BTW this CanOpen implementation www.canfestival.net doesn't require 1us
interrupts.
Regards
Edward
----- Original Message -----
From: "jpdi"
To: <6...@yahoogroups.com>
Sent: Monday, May 18, 2009 6:09 PM
Subject: RE: [68HC12] Problem initialise timer for 1µs cycle
Hi,
As I told you in my precedent mail, I think you can't increment a character
each micro-second.
The reason is this delay is too short for that processor.
As I explained, an empty function (quartz 12 MHz, CPU frequency 6 Mhz) takes
2.5 micro-seconds :
EmptyFunction (void)
{ // nothing to do !
}
void main (void)
{ while (1)
{ led = 0;
EmptyFunction ();
led = 1;
}
}
The led will flash about 2.5 micro-second.
The micro-processor just have to (Core user guide, instructions JSR and RTS)
- (SP) - $0002 -> SP // JSR instruction
- RTNh:RTNl -> (Msp):(Msp+1)
- subroutine add -> PC
- do nothing
- (Msp):(Msp+1) -> PCh:PCl // RET instruction
- (SP) + $0002 -> SP
An interrupt function will take more time, because of some additional things
to do : save registers for example...
I don't know what is the sequence for interrupt call, but I can see, JUST
FOR the RTI instruction (return from interrupt) :
- (Msp) -> CCR // recover flags
- ((SP) + $0001 -> SP
- (Msp):(Msp+1) -> B:A // recover A and B registers
- ((SP) + $0002-> SP
- (Msp):(Msp+1) -> Xh:Xl // recover X register
- ((SP) + $0002-> SP
- (Msp):(Msp+1) -> PCh:PCll // recover PC register
- ((SP) + $0002-> SP
- (Msp):(Msp+1) -> Yh:Yl // recover Y register
- ((SP) + $0002-> SP
That means RTI restores CCR, B, A, X, PC, and Y.
Where RET has 2 things to do, RTI has 5 !
You can see, with the same core frequency, interrupt function will be slower
than empty function, because interrupt function has more things to do.
So, if you use PLL of the micro-processor, I say for example 24 Mhz core
freq, your empty function will take 2.5 / 4 micro-second, 0.63 micro-second.
BUT :
- because your interrupt function has more thing to do, I can suppose it
can't do in less than 1 micro-second.
- even if it is ok, your micro-processor will only run under its interrupt
service routine.
So, for me, forget to increment your character each micro-second : it's too
quick.
Of course, your timer will interrupt your main process... Even with RTI
timer, or the other timers T0...T7. But at which period ? Certainly not at 1
micro-second, I think !
I hope this helps.
Joel
-----Message d'origine-----
De : 6...@yahoogroups.com [mailto:6...@yahoogroups.com] De la part de
Sven K
Envoyé : lundi 18 mai 2009 14:38
À : 6...@yahoogroups.com
Objet : RE: [68HC12] Problem initialise timer for 1µs cycle
Hello,
>Because of character problems on the mail I received, I can't see if you
>want
interrupt each micro-second.
>If so, it seems very very fast for that
processor.
I need to increment a variable every micro-sencond. I am implementing an
CANopen stack at the controller. For this I need to increment a variable
every micro-second.
I have written a test programm to test the timer. The timer basically
works.. The interrupt works etc. but I do not know how to configure the
timer registers so that I get an interrupt every micro-second.
You can find attached the programm files. Perhaps someone can tell me how
to configure the timer to get an interrupt every micro-second.
Perhaps an additional question. How can I test the Interrupt? I toggle some
LED's every interrupt but I think when using a one micro-second interrupt
you can not see toggling the LED's any more ;).
It is all written in C.
Thank you very much!Best regards
--- f...@yahoo.com schrieb am Fr, 1.5.2009:
I find just this morning your problem about Timer.
Because of character
problems on the mail I received, I can't see if you
want interrupt each
micro-second...
If so, it seems very very fast for that
processor.
With 12 Mhz quartz, no PLL, I use an empty function (in C) to
delay 2.5
micro-seconds :
void Delay_2_5_micro (void)
{ //
nothing to do
}
That means just call and return from this empty
function take 2.5
micro-seconds, measured with oscilloscope.
Hope this
helps.
Joel
Von: f...@yahoo.com
Betreff: [68HC12] Problem initialise timer for 1µs cycle
An: 6...@yahoogroups.com
Datum: Freitag, 1. Mai 2009, 13:56
Hello,
I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ
second cycles. Every µs I want to increment a variable, but I do not know
how to initialise the timer, so that I get a timer interrupt every µs.
I hope that someone can help me.
Best regards
[Non-text portions of this message have been removed]
------------------------------------
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )