Example: barber

AN1076 - Microchip Technology

2007 Microchip Technology 1AN1076 INTRODUCTION DMX512 is a communication protocol used in most pro-fessional theater lighting components such as dim-mers, scanners, moving lights, strobes, etc. Thisapplication note presents a solution to transmit andreceive the DMX512 communication protocol that canbe implemented using any PIC microcontroller offer-ing a Universal Asynchronous Receiver Transmitter(UART) module. In particular, the PIC18F24J10, a gen-eral purpose device, was used in the code examplesprovided with this application note. It provides 1024bytes of data memory, which allows the demonstrationcode to store the data for the entire 512 channel buffer(although this is not required for the typical application).Only an external RS-485 compatible transceiver isrequired to complete the application DMX solution is provided in two Transmitter:This part will explain how to generate and transmit theDMX512 packets.

AN1076 DS01076A-page 4 © 2007 Microchip Technology Inc. EXAMPLE 1: DMX512 TRANSMITTER STATE MACHINE CODE Example 1 …

Tags:

  Example, An1076

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of AN1076 - Microchip Technology

1 2007 Microchip Technology 1AN1076 INTRODUCTION DMX512 is a communication protocol used in most pro-fessional theater lighting components such as dim-mers, scanners, moving lights, strobes, etc. Thisapplication note presents a solution to transmit andreceive the DMX512 communication protocol that canbe implemented using any PIC microcontroller offer-ing a Universal Asynchronous Receiver Transmitter(UART) module. In particular, the PIC18F24J10, a gen-eral purpose device, was used in the code examplesprovided with this application note. It provides 1024bytes of data memory, which allows the demonstrationcode to store the data for the entire 512 channel buffer(although this is not required for the typical application).Only an external RS-485 compatible transceiver isrequired to complete the application DMX solution is provided in two Transmitter:This part will explain how to generate and transmit theDMX512 packets.

2 This is divided into two subsections:(a) how to generate and transmit the DMX512 packets and (b) a demo program that shows how to sendcommands to a DMX512 light dimming Receiver:This part will explain how to receive the DMX512packets. Once more, it is divided into two subsections: (a) how to receive the data and (b) a demo program that sends the received data to thePWM module to control the brightness of a LED. BACKGROUNDIn the past, variable auto-transformers were used tocontrol theatre stage lights. That required long wiresaround the stage to supply electricity to the lamps anda whole team would be required to manually controlthetransformers. Later, electric motors were connectedto the auto-transformers, which made the controllingless cumbersome. Eventually, analog controls took theplace of auto-transformers, becoming quite popular,particularly the 0-10V analog consoles.

3 Still, thissystem had three major was prone to could be nonlinear depending ondifferent kinds of separate control wire was required for computer Technology became more cost effective,new digital consoles came to the market and with themthe need for a new standard that would allowequipment from different manufacturers tointeroperate. The United States Institute of Theatre Technology ,USITT, first developed the DMX512 protocol in 1986 asa standard digital interface between dimmers and con-soles, later expanded and improved in 1990. The cur-rent version, known as DMX512-A, has also beenadopted as an American National Standards Institute(ANSI) standard ( ). The development ofDMX512-A is currently managed by the EntertainmentServices & Technology Association (ESTA). You canobtain (purchase) a copy of the protocol specificationsfrom the web site or the OF THE DMX512 PROTOCOLDMX512 (an acronym for Digital MultipleX), isextremely simple, low cost and relatively robust.

4 Due tothese advantages DMX512 has gained a great popu-larity. As the name suggests, it can support up to 512separate control channels/devices. It is a unidirectionalasynchronous serial transmission protocol which doesnot provide for any form of handshake betweenreceiver and transmitter, nor does it offer any form oferror checking, or correction mechanism. Hence, it isnot suitable for any safety critical application. Data istransmitted at 250k baud rate using a physical interfacecompatible with the RS-485 transmission standardover two wires and ground. A DMX512 system has only one transmitter and multi-ple receivers. A DMX512 transmitter connects aDMX512 receiver via XLR 5-pin or XLR 3-pin connec-tors. A female connector is connected to a transmitterand a male connector on a receiver. The specificationstates that 2 pairs of shielded cables should be :Parthiv PandyaMicrochip Technology a PIC Microcontroller for DMX512 CommunicationAN1076DS01076A-page 2 2007 Microchip Technology , the use of a second cable is 1shows the physical pinout when a XLR 5-pin connectoris used.

5 TABLE 1:XLR 5-PIN CONNECTOREach DMX512 transmitter sends 512 8-bit dimming val-ues, between 0 and 255, where 0 represents the lightsoff and 255 represents the maximum intensity. Each receiver connected to the DMX512 line canchoose one of the 512 channels (address selection) tocontrol its output lamp (load).The DMX512 protocol requires the transmitter to con-tinuously repeat (at least once a second) the transmis-sion of a frame as shown in the timing diagram inFigure 1 and Table 1:DMX512 TIMING DIAGRAMTABLE 2:DMX512 TIMING VALUESXLR Pin NumberDMX 512 ApplicationFunction1 CommonCommon Reference2 DMX Data 1-Primary Data link3 DMX Data 1+4 DMX Data 2-Secondary (Optional) Data link (Unimplemented for 3 pin XLR connector)5 DMX Data 2+Note:XLR connectors are commonly used inprofessional audio, video and lightingapplications. The connector has a ruggedshell and a locking mechanism.

6 DescriptionMinimumMaximumTypicalUnitBrea k92 176 SecMark after Break12<1,000,000 SecBit SecDMX512 Packet12041,000,000 SecOther 511 BytesMark Before 0 1 1 0 1 0 11st Data Byte2 Stop Bits2 Stop Bits07 Mark after BreakBreakStart CodeLSbMSb 2007 Microchip Technology 3AN1076 DMX512 TRANSMITTERTo generate the DMX512 packets, the software solu-tion employs a simple state machine comprised of DMX data line is Bytes 0 to 511 of the DMX DMX data line is DMX data line is driven lowFIGURE 2:TRANSMITTER STATE MACHINEF igure 2 shows the state machine. In this application,to simplify the code and still remain within the timingconstrains, the SENDBREAK, SENDMAB and SENDMBB intervals were all set to 100 Sec. These timings canbe easily changed if required. The Timer0 module isused to control the 100 Sec timing and the spacingbetween the transmitted 1 SENDMBB DmxTxState = 0 Wait for 100 SecWait for 60 Sec between bytesState 2 SENDDATA DmxTxState = 1 State 3 SENDMAB DmxTxState = 2 Wait for 100 SecAfter 100 SecAfter 100 SecAfter 100 Sec512 bytes sentState 4 SENDBREAK DmxTxState = 3 Wait for 100 SecAN1076DS01076A-page 4 2007 Microchip Technology 1:DMX512 TRANSMITTER STATE MACHINE CODEE xample 1 shows the outline of the DMXT ransmitsubroutine implementing the state DMXT ransmit subroutine is designed for use in acooperative multitasking application.

7 To avoid any tim-ing issues, the state machine should be called fre-quently enough (approximately every 40 s or less)from the main program loop. The DmxTxState variableis used to represent the current state and as an offsetin a jump table to access the corresponding codesegment in the state machine THE BREAK SIGNALThe Break signal allows receivers to synchronize withthe DMX transmitter identifying the beginning of a newpacket of EUSART module available on mostPIC18 microcontrollers has the ability to automaticallygenerate a 12-bit long Break signal, corresponding to48 s at 250k baud. Unfortunately, this is too short foruse in a DMX512 application as the protocol requires aminimum length of 92 Sec. Figure 3 shows the alter-native hardware method chosen in this application noteto generate the longer Break signal. A 100 resistor isconnected in series with the microcontroller s EUSART transmit pin and the other end of the resistor to an I/Opin.

8 In the specific example , pin RC5 was used. Withthis solution, the Break time can be varied in software,from 92 Sec to 176 Sec to meet the DMX protocolBreak time specification, when sending a Break signal,pin RC5 is driven low. Later Pin RC5 is tri-stated toallow the transmission from the EUSART to 3:GENERATING A LONG BREAK SIGNAL;Jump TableDMXT ransmit:rlncf DmxTxState,Wandlw 0x0 Eaddwf PCLbra SENDMBBbra SENDDATAbra SENDMABbra .. To R S - 4 8 5 TransceiverRC6/TxRC5 PIC Microcontroller 2007 Microchip Technology 5AN1076 SENDING THE DIMMING DATAThe dimming data is 8-bits wide, where 0 represents alight off and 255 represents full intensity. Figure 4shows the digital representation of the dimming generate the two Stop bits required by the DMX512protocol, the PIC18 EUSART is configured for 9-bitmode and the 9th bit is set permanently to 1.

9 FIGURE 4:DIGITAL REPRESENTATION OF DIMMING DATAThe dimming data is stored in a 512 bytes buffer(TxBuffer), allocated in the PIC18F24J10 RAM mem-ory. The data is written to or read from the buffer usingthe indirect addressing registers available on PIC18microcontroller architecture for linear memory counter keeps track of the number of bytestransmitted from the buffer. Data = 0 Data = 255 Mark Before Break Start CodeLSbMSb2 Stop Bits0000000000 Mark Before BreakStart CodeLSbMSb2 Stop Bits11111111077 Note:Although the demonstration code storesand transmits the dimming data for all 512channels it can be easily modified to storeand transmit only a subset of channels,while leaving all remaining channels off(0). This could reduce considerably theMCU RAM requirements for a reducedfunctionality 6 2007 Microchip Technology APPLICATION DEMO: DIMMING A LAMPIn the previous section we saw that it is very easy togenerate a DMX512 packet using a PIC18F device.

10 Inthis demonstration application, we will use a potentiom-eter connected to the DMX512 transmitter to controlremotely a lamp attached to a standard DMX512receiver. The PIC18F24J10 has a 10-bit Analog-to-Digital Con-verter module with 13 inputs. The potentiometer can beconnected on pin RA0 of the MCU corresponding to theanalog input channel the potentiometer won t change very rapidly,sampling it every 10 mSec is generate anautomatic and periodic activation of the Analog-to-Digital Converter, a convenient feature of thePIC18F24J10 microcontroller can be used. The ADCmodule can, in fact, start periodically a new conversiontriggered by the Capture Compare and PWM module(CCP). The 16-bit Timer1 module is used in conjunctionwith the CCP module configured in 16-bit Comparemode. When the compare trigger occurs (Timer1 =CCPR1), the ADC conversion starts on the pre-selected input channel and Timer1 is reset.


Related search queries