4
Channel DMX512 Driver
for PIC16F688
|
|
Description
This project is a 4 channel
DMX512 driver board. It features four power MOSFETs that
can be configured to operate in PWM mode or as on/off outputs.
The driver can be configured to use any four consecutive
addresses across the full 512 channel address range. It can be
used to drive LED arrays or low voltage lamps in PWM mode or
operate relays in static mode.
Feature list:
- 4 channels with low side N
channel MOSFETs providing up to 3 amps per channel
- Two modes of operation:
- 8 bit resolution PWM
mode with a PWM period of 10ms (100Hz).
- static drive mode with
on/off outputs.
- When no DMX data is
received the driver can be configured to turn off all
outputs, or leave them in their current state.
- Configuration held in
EEPROM so no external switches or jumpers required.
- Flexible modes available
to set configuration.
- Configurable for
active-high or active-low outputs to allow ease of
interfacing to external drive electronics.
One of the design goals for
this project was to keep the external hardware required to a
minimum. For this reason, most of the configuration is
held in the PICs EEPROM. The only two hardware enabled options are
Output active drive level and Config mode enable. The
other goal was to make it easy to construct, to that end the PCB
is single sided and uses easy to obtain through-hole parts.
I also didn't include the DMX connectors on the PCB since there
are three types in use.
Driving four white LED
arrays with PWM
|
Optional DMX address
board
|
Driver with address
board and PICkit2 attached |
Running with red,
green, blue and white LED arrays |
DMX
Protocol Overview
Without going into too much
detail the following is a brief overview of the DMX protocol.
The protocol uses 8-bit asynchronous NRZ serial data and is
unidirectional with the data being generated by a master
controller. The protocol supports up to 512 devices.
The maximum number of data slots that can be sent in one frame
is 513, this comprises the Start Code and 512 Channel Data
slots. There is no address information contained in the
data stream and no error checking or correcting information.
Devices receiving the data must count the number of data slots
received to identify the Channel data corresponding to their
base address and any additional following data slots if the
device requires it.
The physical layer, based on
EIA-485 electrical specification can support up to 32 devices
(including the controller) on one bus. Data is sent over
the bus using differential signalling. The end of the bus should
be terminated with a 120R resistor across the Data+ / Data- pair.
The full DMX512 specification
is available from the
USITT
-
MAB is
Mark-after-break
-
Time between
two Breaks may vary from 1.196mS to 1.25S
-
For dimming
commands the start code value is 0x00. Alternate start codes
can be used (see the USSIT-DMX512-A protocol specification,
annex D).
Some photo's taken
during testing
The scope trace
clearly shows the break, followed by the MAB, start code of
zero, a non zero value in channel one and zero for the data in
the following channels. The high pulses are the two stop
bits at the end of each byte (see
PDF
)
Component List
You can buy all the parts
needed to build this project from most component suppliers world
wide. In the UK you can get nearly everything from Rapid Online and
I've included a parts list with their part numbers below.
All
Rapid parts/descriptions correct at 11-December-2008. You should
check part# and descriptions are correct when ordering in case
I've made a mistake transferring them onto this page.
Component |
Description |
Part # |
R3,8,9,10,11 |
PK 100 120R 0.25W CF
RESISTOR (RC) [Order 1
Pack] |
62-0348
|
R4,5,6,7,12,13 |
PACK 100 10K 0.25W CF
RESISTOR (RC) [Order 1 Pack] |
62-0394
|
R14 |
PK 100
330R 0.25W CF RESISTOR (RC)
[Order 1 Pack] |
62-0358 |
|
|
|
C2,3,6 |
100N 2.5MM X7R
DIELEC.CERAMIC (RC) |
08-1015 |
C4 |
10U 35V 105 DEG.RADIAL
ELECT. (RC) |
11-1220
|
C5 |
47U 25V 105 DEG.RADIAL
ELECT. (RC) |
11-1165
|
|
|
|
D1 |
1N4148 SIGNAL DIODE
75V 150MA (TRU) RC |
47-3416 |
D2,3,4,5* |
1N4001A 1A 50V
RECTIFIER DIODE (RC) |
47-3420 |
Q1,2,3,4 |
STP36NF06L MOSFET
LOGIC N 60V 30A (RC) (alternatives) |
47-0552 |
|
|
|
IC1 |
Requires pre-programmed PIC available from
online store only |
|
IC2 |
DA78L05 V REG +5V 100mA
TO-92 TRU (RC) |
47-3612 |
IC3 |
ST485CN 8P L/P
RS485/422 TRANSCEIVER RC |
82-1044 |
|
|
|
JP1 |
2+2 WAY DOUBLE ROW PCB
HEADER PLUG (RC) |
22-0525 |
X1,2,3,4,5 |
2 WAY 16A INTERLOCKING
TERMINAL BLOCK RC |
21-0440
|
CON1 |
3 W SINGLE ROW PCB
HEADER PLUG RC |
22-0500
|
CON2** |
5 WAY R/A SINGLE ROW
PLUG (RC) |
22-0710 |
ICSP |
5 WAY R/A SINGLE ROW
PLUG (RC) |
22-0710 |
JP2 |
2 WAY SINGLE ROW PCB
HEADER PLUG (RC) |
22-0520
|
socket for IC3*** |
8 PIN 0.3IN DIL SKT
(RC) ALSO 22-0131 |
22-0150
|
socket for IC1*** |
14 PIN 0.3IN DIL SKT
(RC) ALSO 22-0132 |
22-0155
|
|
|
|
Parts for the optional DMX
Address Board |
R1 |
PACK 100
1K 0.25W CF RESISTOR (RC)
[Order 1
Pack] |
62-0370 |
C1, C2 |
100N 2.5MM X7R
DIELEC.CERAMIC (RC) |
08-1015 |
D1-D10 |
1N4148 SIGNAL DIODE
75V 150MA (TRU) RC |
47-3416 |
IC1 |
4017B
DECADE COUNTER/DRIVER (RC) |
83-0340 |
SW1 |
EXCEL
9 WAY 18 PIN DIL SWITCH (RC) |
80-0314 |
Socket for
IC1 |
TUBE (30)
16 PIN 0.3IN DIL SOCKET. |
22-0133 |
Parts List Notes
* These Diodes only needed if you
will be driving relays or inductive loads, otherwise don't fit
them.
**
Cut off one pin to make a 4-way
***
Much cheaper to buy a tube of 30 sockets if you're making more
than one driver board
Alternate MOSFETS
The
STP36NF06L
MOSFETs specified are logic
level devices and are specified to operate with a low gate
voltage. You can use standard N Channel MOSFETs with a
suitable Ids current rating if you can't
obtain this part and they should work fine with load currents of 2-3 amps.
Construction notes:
Fig. 1 Ensure you follow
ESD precautions when constructing the board. The MOSFETs
in particular are very susceptible to ESD damage
Fig. 2 Start by
installing the resistor, R2/3 aren't used.
In Fig.3
Install Diodes taking care to fit them the correct way round
with the band on the diode body aligned as shown on the
component overlay.
Note: Diodes D2,3,4,5 are only required if
the board will drive relays or inductive loads (board right) They're
not required if the board will only be used for driving LEDs (board on left)
Fig. 4 Install the
capacitors. Note C4 and C5 are electrolytic
capacitors and need to be installed the correct way round.
C1 is not used.
Fig.5 Install the
voltage regulator IC2 and the wire link LK1. For the wire link
use an off-cut from one of the other component leads.
Fig.6/7 Install
all the connectors, pin headers and sockets and LED1. When
installing the LED ensure the flat side on the LED body is
aligned as shown on the component overlay.
The
wire loop in the Gnd test point isn't required (I used it for
connecting an oscilloscope probe during development)
Fig.8/9 Install
the four MOSFETs Q1,2,3,4 last. Observe antistatic handling
precautions to avoid damage. Install and solder them into
place one at a time. Solder the lead that connects to the
copper ground plane first, then the lead at the opposite end and
finally the centre lead.
Use solder to tin the copper
tracks between the MOSFETs and the screw connectors to increase
their current carrying capacity.
Fig. 12 Once the
board has been assembled, apply power to the board and check
that there is 5 volts between pins 1-14 of the IC1 socket and
5-8 of IC3 socket. Don't install the ICs into the sockets
until this has been checked and is correct.
Important:
If the board will be used with
all four channels at high currents you must use solder to
heavily tin all the copper tracks between the screw connectors
and all the tracks feeding the MOSFETs
Connecting the board
The board can operate from
voltages in the range 9-24 volts. The input voltage should be
selected to suit the devices connected to the channel outputs.
Each channel can supply an
absolute maximum of 3 amps*.
As there is no fault protection on the outputs
you may need to use suitably rated in-line fuses depending on your particular application.
The red + channel connections
are connected to + DC in and are all connected together on the PCB.
The black channel wires are the MOSFET switched connections to ground.
Connection diagrams for LED
arrays and relays are shown on the right. When used with
relays ensure that the operating mode is set to
static and not PWM.
|
|
|
Connection for DMX in-out
using 3 pin XLR socket.
There are also
standards for 5-pin XLR and RJ45 connection.
www.dmx512.com |
Configuring Driver Options
Options Summary
The DMX driver board has
various user configurable options as summarised below.
- The outputs can be
configured to operate in PWM mode or static mode. In
PWM mode all four channels are driven with an 8 bit
resolution PWM signal at 100Hz. The duty cycle is
derived from the DMX channel data with 0=0% through to 255=100%
In static mode the outputs are either on or off. The
DMX channel data controls the output with channel data
values from 0-127 corresponding to off and 128-255
corresponding to on.
The driver cannot operate in a mixed mode, the outputs are
either all PWM or all static.
- When the driver stops
receiving valid DMX data the outputs can be configured to
either remain in their current state / maintain the PWM duty
cycle, or turn off / set PWM duty cycle to 0%.
The time from the last valid packet being received to
entering the stopped state is approximately 1.5 seconds.
-
User configurable DMX
Start Code. For dimming commands the start code
value is 0x00. Alternate start codes can be used (see the
USSIT-DMX512-A protocol specification, annex D). The driver
will ignore any DMX packets where the start code does not
match the configured value.
- DMX channel base address
for the driver
Methods for Configuring the DMX
Driver
The driver can be configured
using the following methods:
- Using a PIC programmer (via ICSP
header) to modify the config in the PIC EEPROM.
If you use this method please see the notes about
writing
to a code-protected PIC here
- using a DMX controller to send the configuration as
in-band channel data.
- The address only can be
set using the optional hardware switch address board
In-band Configuration over the DMX
channel
In order to use this method of
configuration the DMX controller must be capable of allowing the
channel data values to be set precisely. Controllers that
don't display the actual channel data value cannot be used
since it's not possible to tell precisely what value has been
set.
When the DMX configuration
mode is enabled the driver listens for a packet with a start
code of 0x00 and reads the data starting on DMX Channel 1.
The drivers current configured base address and start code are
not used when in DMX configuration mode. This allows it to
be reconfigured even if the current data held in EEPROM is
invalid.
The parameters that can be set
over the DMX channel are:
- DMX device base address
- DMX channel 0 start code
(this should normally be set to 0)
- PWM / Static mode select
- Output behaviour when DMX
data signal is lost
To configure the driver using DMX
channel
data:
- Connect a physical jumper
between pins 1-3 of JP1. (Option 1)
- Cycle power to the board.
- Channel data is read from
the first valid DMX packet received and used to configure
the driver as shown in the table below.
- Once the options have been
programmed into the EEPROM the driver will blink its status
LED in a repeating 2 blink pattern.
- Remove the physical jumper from JP1
- Cycle the power to the
driver to restart using the new settings.
- Watch the status LED to ensure the assigned DMX address
is valid
DMX channel data / EEPROM is interpreted
as follows:
DMX
address |
EEPROM
address |
Value |
Setting |
001 |
0x00 |
0-1 |
DMX address high byte |
002 |
0x01 |
0-255 |
DMX address low byte |
003 |
0x10 |
0-255 |
DMX Start Code |
004 |
0x11 |
0-127 |
PWM
Mode on |
128-255 |
Static Mode on |
005 |
0x12 |
0-127 |
no DMX data receive turn off output |
128-255 |
no DMX data receive hold outputs in current state |
DMX Base Address
The driver board
receives data over four consecutive channels starting at the
base address configured on the board. The base address can
be set to start at any address in the DMX packet, however it
also needs to be set to an address compatible with the DMX
controller. Some controllers expect the start address to
be located at fixed offsets, eg. 1, 7, 13, 19,25...
Refer to your controllers documentation.
The base address for the driver
board is held in the EEPROM of the PIC. It can be set
by:
a) using the optional
DMX address board
b) programming the PICs
EEPROM directly
c) DMX in-band
configuration mode using the DMX controller
The DMX address requires 9 bits
to hold the full range of valid addresses. It is stored in EEPROM using two memory locations; these are address 0x00 (high
byte) and 0x01 (low byte).
If an invalid address is found in the EEPROM the driver board
will indicate the error condition with the
status LED.
Example 1.
DMX address 7
In Hexadecimal this is 007
Write 00 to high byte at EEPROM address 00
Write 07 to low byte at EEPROM address 01
If address less than 256
then high byte = 0 and low byte is the address
e.g. address = 7
high byte = 0
low byte =7
|
Example 2.
DMX address 300
In Hexadecimal this is 12C
Write 01 to high byte at EEPROM address 00
Write 2C to low byte at EEPROM address 01
Decimal conversion for
sending as DMX channel data
if address greater than
255 then high byte = 1 and low byte is address - 256.
e.g. address = 300
300 is > 255 so high byte
=1
low byte 300-256 = 44 |
Google will convert decimal to
hex if you enter 'decimal_number to hex' into the search
engine. The convention for indicating a value is in hex is to
prefix it with 0x.
The example above shows the
EEPROM data for a driver board configured to use DMX base
address 7
- Start code 0
- PWM outputs
- Outputs shutdown when no
DMX data is received
The example above shows the
EEPROM data for a driver board configured to use DMX base
address 300
- DMX start code 0x0A
(10 decimal)
- PWM outputs
- Outputs remain in current
state when no DMX data is received
DMX Address Board
The DMX Address Board
option allows the base address of the driver board to be
set using a bank of DIP switches.
At power-on the firmware
in the PIC reads the current base address from the EEPROM. It then tests for the presence of the
optional DMX Address Board. If the board is
present the address set on the DIP switch bank is read
and compared to the current address in EEPROM. If
the address set on the DIP switches is different, the
new address is used and the EEPROM updated.
See flowchart
If the address board is
present it will always take precedence over the address
held in EEPROM or the address sent in any in-band DMX
configuration. |
|
If no board is detected, the
driver will use the address from the EEPROM. This means a
single DMX Address Board can be used with multiple drivers since
it only needs to be present to set a new address. Of
course if you want each driver to have its own address board
there is no reason why you can't fit one to each driver.
The use of a 9-way DIP switch
allows the full range of 512 DMX addresses to be set and used.
A smaller DIP switch can be used if you only want to set
addresses within a smaller range. For example, a 6-way
switch would allow addresses in the range 1 to 63 to be set.
The PCB is designed to take
a 10-way DIP switch module. The 10th switch is not
required or used. The reason the PCB is designed for a 10 way
switch is that these seem to be both cheaper and more readily
available than 9-way. The PCB therefore provides the end
user the flexibilty to use either.
The address is set on
the switch bank in binary.
Switch No |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
Binary value |
256 |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
Example: To set the base
address to 300, set switches 9,6,4 & 3 to the on position.
256 + 32 + 8 + 4 = 300
Switch No |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
Binary value |
256 |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
Switch position |
On |
Off |
Off |
On |
Off |
On |
On |
Off |
Off |
Google will convert decimal to
binary (see example below).
Ignore the leading 0b and set
the switches so 1 = switch on and 0 = switch off.
Operation
DMX Channel data
PWM mode
Channel |
Value |
Function |
|
0 |
0 - 255 |
PWM 0% - 100% |
|
1 |
0 - 255 |
PWM 0% - 100% |
|
2 |
0 - 255 |
PWM 0% - 100% |
|
3 |
0 - 255 |
PWM 0% - 100% |
|
Static mode
Channel |
Value |
Function |
|
0 |
0 - 127
128-255 |
Off
On |
|
1 |
0 - 127
128-255 |
Off
On |
|
2 |
0 - 127
128-255 |
Off
On |
|
3 |
0 - 127
128-255 |
Off
On |
|
Connectors / Headers /
Jumpers
DC in
Input power for the driver
board. 9-24 volts regulated DC. The current
rating of the power supply will depend on the devices being
driven. Ensure you use a suitable power supply for
your application.
CH0,1,2,3
Low side switched outputs
connected to the onboard MOSFETS. Channel 0 is
controlled by data sent to the DMX base address of the
board, channels 1,2 and 3 to the next 3 consecutive
addresses. Do not exceed 3 amps per channel absolute
maximum.
There is no fault
protection on the outputs so depending on your application
you may want to use suitably rated in-line fuses.
DMX RX in
Connects to the DMX data
cable. Since there are various DMX connector standards
you'll need to wire this to the particular connector you are
using e.g. XLR-3pin, XLR-5pin, RJ45 jack.
JP2 (TERM)
When the jumper is closed,
the DMX signal is terminated into a 120 ohm resistor on the
board. This should only be done on the last board.
Also, if an external cable terminator is used, don't
terminate on the board.
DMX address in
Connects to the optional
DMX address DIP switch board.
JP1
Option 1
Pins 1-3: Open,
normal operation
Closed, enable DMX configuration mode
(see text)
Option 2
Pins 2-4: Closed,
output active low. Open, outputs active high.
Leave this jumper open for use with the driver board
described on this page.
ICSP header
This provides a connection
for In-circuit serial programming of the PIC. The
driver board must be powered when using the ICSP connector
since it does not support powering from the programmer
itself. Disconnect the programmer before resuming
normal operation.
Status
LED
The status LED provides
indication that DMX data is being received during normal
operation and error and status codes if a problem is
detected during start-up.
Note: Since the status
LED shares the same PIC control line as a signal on the ICSP
header when the the board is connected to a PIC programmer
the status LED should be ignored until the programmer is
disconnected.
Normal operation
LED |
Explanation |
Blinking 2Hz (*_*_*...) |
- DMX data received within the last 1.5 seconds
- At power-on
for 1.5 seconds (even if no data received)
|
On (*) |
- No DMX data has been received within the last 1.5
seconds
- Valid DMX data with a
start
code different to the one configured will also
cause this condition
- DMX D+/D-
signal connection reveresed.
|
|
|
Startup Status Codes
During startup the status
LED indicates errors and status by blinking a number of times followed
by a pause; this repeats continuously. The cause must
be corrected and the driver restarted to clear the condition
and enter normal operation.
|
LED
blinks |
Cause |
2 |
*-*--- |
Completed a DMX
in-band
configuration. |
3 |
*-*-*--- |
Invalid DMX base
address. =0 |
4 |
*_*-*-*--- |
Invalid DMX base
address. >509 |
5 |
*-*-*-*-*--- |
EEPROM write failed
after 5 retries |
6 |
*-*-*-*-*-*--- |
PIC internal GPR
memory failed to initialise |
- Status code 2 is not
an error. Once the DMX configuration has
completed, remove the mode jumper and cycle power to the
board to use the new settings.
- Status codes 3 and 4
indicate the DMX base address for the board is invalid.
Re-program a valid address, using either the DMX address
board, DMX in-band configuration or by programming the PIC EEPROM
directly through ICSP.
- Status codes 5 and 6.
If these can't be cleared by cycling power to the board,
then the PIC is faulty and should be replaced.
Firmware
Full Function release
The full version of the
firmware for this projects is no longer available to buy.
This projects has been updated and a new version of firmware
produced to work with it.
Please see the 4-Channel DMX Driver #805
project page
Web Demo Evaluation release
The HEX file download is a free
to use demo / evaluation version. You'll need a spare
PIC16F688 to program the code into. It is a fully functional version of
the 4 channel DMX driver as described on this web project page
but has the following limitations:
- DMX base address is fixed
at 001
- The start code is fixed to 0
These settings are fixed,
and any changes made by inline commands, EEPROM data or the
optional address board have
no effect.
Description |
Filename |
Download link |
Web demo release (fixed
base address)
HEX file
ready to program into the PIC |
dmx688webdemo.HEX
v1.1.2 27/03/2009
|
download
checksum D44C |
IMPORTANT please read:
It has been brought to my
attention that some (free) programmer software either does not correctly
preserve the data in the PICs config register at 0x2008 or needs
to be told not to overwrite it.
This register holds the HF internal oscillator calibration word.
If it gets erased or altered the PIC will not run at the correct
frequency.
Since the timing for the DMX
data receiver is based on this clock if the calibration word is
incorrect the DMX driver may not be able to receive data
correctly or at all.
If in doubt get a
Microchip PICkit2 programmer. This will program the 16F688
correctly, it won't however recover a 16F688 that has been corrupted
by another programmer.
Changing the
EEPROM configuration options
Important: If you have
bought a pre-programmed PIC for this project it is code
protected. It is most important that only the EEPROM data
is written, therefore you must un-check the 'Program
Memory enabled' option before clicking on Write
( see screen shot below)
Changes to the configuration
are easy to make if you are using a PICkit2 programmer since this programmer allows you to directly edit the EEPROM data
before programming. Start by reading the data back from
the PIC. The program memory will appear as 000 because the
PIC is code protected, the EEPROM data should return the current
values stored in it.
Click on the EEPROM data
to highlight it and enter the new value(s). Once changes are
complete simply click on the write button to program into the PIC. Remember the values entered are in Hex not decimal so
you'll need to convert them as required.
In the demo version of the
code, you can edit the settings in the EEPROM, but the base
address and start code values are ignored. The other
settings are still effective in the demo version.
DMX
Compatibility
We've tested the DMX driver
board with the following DMX controllers:
DMX512 test data
transmitter.
This small application
generates 8 frames of DMX data in channels 1 to 8. The
data in channels 1 to 4 increments from 0 to 255 in a repeating
pattern. Data in channels 5 to 8 is always zero.
This code was written to allow
testing of the DMX Driver with a DMX data stream where the
Break, MAB, packet idle time, packet length, etc could all be
configured. This was required since many commercial
products don't generate DMX packets with minimum timing
parameters and it was necessary to ensure the application code
would work reliably under these conditions.
This code has been provided to
allow testing of the DMX Driver described on this web page with
a consistent DMX512 data packet stream. The DMX output
from this code generates a Break of 92uS, MAB of 5uS and an
idle time between packets of 5uS. Channel data is sent
back-to-back with no delay.
Description |
Filename |
Download link |
DMX transmitter test code
HEX file
ready to program into the PIC |
dmx688demotx.HEX
V1.0.0 15/10/2012
|
download
checksum 7347 |
Example schematic for testing
|