h1

DMX-512 transmission successful

2010/06/02

Some fairly quick software work and I’ve got a baseline for DMX transmission from the Xmega DMX board ;-)

The code after the break is quick and dirty, and hogs the whole chip, but it works!  The next step is to convert it so that it uses DMA, then enhance it to use timers and events so that the MBB/Make/MAB sequence and transmission is as lightweight as possible.  The trick is to balance peripheral usage vs. interrupt overhead.  Given the slop built into the DMX protocol, I can set the interrupts to lowest priority safely enough, and probably get the overall CPU time required to transmit a continuous DMX universe down to something like 0.05% of a 32MHz chip.

The next challenge is DMX reception, which can be done with interrupts, but can also potentially be done with timer capture channels.  I’ll have to start with the dumbed-down version first of course…

int main() {
  uint16_t chan;
  uint8_t val = 0;
  uint8_t dir = 1;

  DMX0_PORT.DIRSET = DMX0_TX_bm | DMX0_DE_bm;
  DMX0_PORT.DIRCLR = DMX0_RX_bm;

  DMX0_PORT.OUTSET = DMX0_TX_bm | DMX0_DE_bm;

  DMX0_USART.CTRLB = USART_CLK2X_bm;
  DMX0_USART.CTRLC = USART_SBMODE_bm | USART_CHSIZE_8BIT_gc;
  DMX0_USART.BAUDCTRLA = 0;
  DMX0_USART.BAUDCTRLB = 0;

  while (1) {
    // break
    DMX0_PORT.OUTCLR = DMX0_TX_bm;
    _delay_us(92);
    // mark after break
    DMX0_PORT.OUTSET = DMX0_TX_bm;
    _delay_us(8);
    // enable transmitter
    DMX0_USART.CTRLB |= USART_TXEN_bm;
    // transmit start code
    DMX0_USART.DATA = 0x00;
    loop_until_bit_is_set(DMX0_USART.STATUS,USART_TXCIF_bp);
    DMX0_USART.STATUS = USART_TXCIF_bm;

    // transmit data
    for (chan=0;chan<32;chan++) {
      DMX0_USART.DATA = val;
      loop_until_bit_is_set(DMX0_USART.STATUS,USART_TXCIF_bp);
      DMX0_USART.STATUS = USART_TXCIF_bm;
    }

    // disable transmitter and run MBB
    DMX0_USART.CTRLB &= ~USART_TXEN_bm;
    _delay_us(10);

    if (dir) {
      if (val == 0xff) val=0xfe,dir=0;
      else val++;
    } else {
      if (val == 0) val=0x1,dir=1;
      else val--;
    }
  }
}

Advertisements

One comment

  1. Did you try http://www.mathertel.de/Arduino/default.aspx ? This is the most useful DMX library I found until now. Stable and versatile. And the best thing – it is free for NON-Commercial use. I don’t know if you want it commercially, perhaps you should ask Matthias.

    Good luck!
    Dani



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: