[asterisk-dev] Re: TDMoE protocol

Tony Mountifield tony at softins.clara.co.uk
Fri Feb 24 06:04:41 MST 2006

In article <001d01c63936$c7eeefe0$0d01b30a at paul>,
Paul Cadach <paul at odt.east.telecom.kz> wrote:
> Tony Mountifield wrote:
> [skipped]
> > As the one who added 2.6 RTC support to ztdummy, I'm qualified to comment!
> > The primary reason for ztdummy is to support SIP, IAX and MeetMe in a
> > system with no Zaptel cards. It is quite adequate for that, although
> > there is a patch on the bugtracker that aims to address a perceived
> > weakness in it.
> The main reason for presense of ztdummy is to provide TIMING source for zaptel,


> > However, I don't think ztdummy as it stands is quite accurate enough
> > for governing TDMoE, because it doesn't maintain a 1ms spacing. Since
> > the RTC can only do power-of-2 subdivisions of a second, it is set to
> > 1/1024 sec (0.9765625ms), but then 3 interrupts out of every 128 are
> > skipped (evenly spaced) to give an average of 1000 per second. This
> > is ok for VoIP with a 20ms or 30ms frame size, but not for TDMoE with
> > a packet every 1ms. I would probably try making ztdummy use 4096 RTC
> > interrupts per second and skip 3096 of them. This would make the
> > interval between two consecutive packets either 0.9765625ms or
> > 1.220703125ms.
> Timing source is not required to be so accurate, it should take minimum jitter.
> So, skip 3 interrupts makes pause in timing of 3/1024 sec (3 ms), while skip of
> 3096 interrupts makes timing pause for more than 755 ms.

No, you misunderstand me. I wasn't talking about skipping multiple interrupts
in succession, but spreading out the skipped interrupts evenly. When skipping
3 interrupts out of 125 (24 out of 1024), it actually skips every 41st or 42nd
interrupt. So most interrupts are spaced at 0.9765625ms, but after 41 or 42
you get one space of 1.953125ms.

If we made the timer run at 4096Hz, we would normally run zaptel every 4th IRQ,
with a spacing of 0.9765625ms as before, but every 10 or 11ms we would do so
on the 5th IRQ instead, giving a spacing of 1.220703125ms. In one second this
would give us 904 intervals if 1/1024 sec and 96 of 5/4096 sec.

Something like this:

  #define CALLED_RATE 4096
  #define ZAPTEL_RATE 1000

  void called_at_called_rate_by_irq(void)
    static counter = 0;

    counter += ZAPTEL_RATE;
    if (counter >= CALLED_RATE) {
      counter -= CALLED_RATE;

I would actually make CALLED_RATE a module parameter and use it to initialize
the RTC chip.

> Better is to provide some sort of PLL - just to collect interrupt count with
> fractional part (i.e. 4096 RTC interrupts per second generates 4.096 interrupts
> per ms, so you skip 3.096 irqs and passes one to zaptel). The calculations
> should be looks like as (we take every 4th PLL count out to zaptel, marked with
> '+' sign)
> RTC int PLL count

I think this is another way of saying the same as I meant all along.

> [... snip figures ...]
> As you can see, zaptel's interrupt jitter is just ONE RTP interrupt interval,
> i.e. 1/4096 sec (about 0.24 ms).


Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org

More information about the asterisk-dev mailing list