Periodic mode and oneshot mode
mantegazza at aero.polimi.it
Fri Jun 9 10:39:50 CEST 2006
Francesco Carsana wrote:
> I'm writing a real time module to generate a square wave on the parallel
> port (See attached file).
> If I use periodic mode, I can generate a wave , but the period must be a
> multiple of 8254's programmed period.
> I've decide to use oneshot mode, so I can change the period on the run
> with a user space program.
> If, for example, I decide to use a wave period of 10 or 20 microseconds,
> I don't obtain the result, in terms of quality, that I've obtained with
> periodic mode. Infact, in oneshot mode, the square wave is much more
> unstable than in periodic mode.
> If I use an higher period (100 microsecons), periodic mode and oneshot
> mode produce the same result.
> The questions are:
> 1) Have I made a mistake in the code?
> 2) Why in periodic mode I obtain a so bad result? Does it matter the
> 8254's reprogramming time?
It is likely you did no mistake, but you must be aware that a PC is not
a DSP in relation to us determinism. In fact when you go down to 10/20
us you are in the uncertainty range of your machine, especially if there
is soem Linux activity. That means there could be more than 10 us
indeterminacy right at the interrupt processing, i.e. you interrupt
comes and the hardware takes more than 10 us just to get to the very
first instruction of your interrupt handler. The calibration test can
show that to you.
Programming the 8254 interrupt counter is a cause of jitter addiing for
sure and that's why, generally speaking, we prefer the periodic mode for
very high frequecies. After all if there is at least one task requiring
a few ten us period the resultion is enough for every other tasks
running slower and the constraint of working with integer multiples of
the timer period becomes quite acceptable.
In any case you should check if you can enable the APIC on your machine,
as in such a case oneshot mode might be less jittery.
More information about the Rtai