The DMX512.com Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

SMF - Just Installed!

Pages: [1] 2

Author Topic: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL  (Read 36626 times)

tendai02

  • Newbie
  • *
  • Posts: 10
SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« on: November 20, 2009, 09:18:19 AM »

I am trying to design a simple LED light which can be controlled by dmx512 signal to give out different colors. i have the MAX485 chip for the input to my project( university final year project) and now i am not sure if i can use the 8051 to do the job, that is, to be able to use dip-switches for address setting and be able to get 3 pulse width modulations frm the 8051 to my LED cicuit. i have heard of PIC microntrollers but am not sure which one is best. are these PIC microcontrollers programmable with simple C compilers or they are self programmable? Please help.
Logged

DMX512

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #1 on: November 20, 2009, 10:48:18 PM »

It is easily possible to do PWM on a PIC chip, and many PICs have support for two channels of PWM in hardware, which makes PWM generation particularly simple; just stuff a few registers and off it goes.

However. most lighting implementations want more than two channels and/or want a lower cost device, so PWM is done in software.

PICs can be programmed using free assembler language tools for Microchip themselves, and a google search will turn up plenty of code to receive DMX512 and do PWM in assembler.  There are C compilers available, probably the best known being the CCS C compiler, but it is not free.

You can use an 8051 or derivitive to do the job, or a Cypress PSoC, or a Parallex propellor (probably an excellent choice for this application as it can do many PWM channels - up to 32 I think - and the dev tools are free) or indeed pretty much any processor as even the most humble processor available this centrury has enough grunt to do what is a fairly simple computational job.

Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #2 on: November 21, 2009, 09:02:23 PM »

thanks a million for the advice, i will stick to the 8051 since i am a bit firmiliar  with the code( C assembler, C compiler and Turbo C) but i think TurboC will be better since i can change it to HEX file and upload to the 8051

i just need 3 channels so i think the 8051 is best for the job

once again thanks a lot
Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #3 on: March 14, 2010, 06:00:11 PM »

i have done a program with .asm extension for my project. i have assembled it and have no errors. after this i created a hex file using Quickbuild in MPLAB IDE version 8.43 and still no problem. the program is supposed to accept a DMX512 signal from a console and then control a PIC16F876 to produce a dimmable light using pulse width modulation.
the programmer i mnaged to get is a Velleman K8048 whic is supposed to program the pic without any problems. when i load the hex file, it does not give me the message to indicate that the pic was programmed successfully.
does my program have anything to do with this?
please help
i have included the .asm file
Code: [Select]
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PIC16F876.
;                                                                     *
;    Filename:     xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:    charles01                                             *
;    Files Required: P16F876.INC                                      *
;                                                                     
;    Notes:  DMX512 demo program for an LED light to respond to the DMX signal   *
;                                                                     
;*********
      list      p=16f876            ; list directive to define processor
    #include <p16f876.inc>        ; processor specific variable definitions
    errorlevel -302
;*****
   __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF
;*****
      #define CHANNEL .000 ;select the receiver slot/channel 
;*****
;***** VARIABLE DEFINITIONS
     w_temp        EQU     0x7E        ; variable used for context saving
     status_temp   EQU     0x7F        ; variable used for context saving

       CBLOCK 0x20
    CountH ;16-bit counter
   CountL
   RxBuffer: .512 ;512 bytes buffer allocation
           ENDC
;**********************************************************************
ORG     0x000             ; processor reset vector
clrf    PCLATH            ; ensure page bits are cleared
  goto    main              ; go to beginning of program
;*****
ORG     0x004             ; interrupt vector location
movwf   w_temp            ; save off current W register contents
movf STATUS,w          ; move status register into W register
movwf status_temp       ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf    status_temp,w     ; retrieve copy of STATUS register
movwf STATUS            ; restore pre-isr STATUS register contents
swapf   w_temp,f
swapf   w_temp,w          ; restore pre-isr W register contents
retfie                    ; return from interrupt
;*****
        main
      call SetupSerial ;Setup Serial port and buffers
;******************************************************************************
       Start
;          first loop, synchronizing with the transmitter
       WaitBreak
      btfsc PIR1,RCIF ; if a byte is received correctly
        movf  RCREG,W ; discard it
        btfss RCSTA,FERR ; else
        goto  WaitBreak ; continue waiting until a frame error is detected
        movf  RCREG,W ; read the Receive buffer to clear the error condition
;second loop, waiting for the START code
WaitForStart
        btfss PIR1,RCIF ; wait until a byte is correctly received
        goto  WaitForStart
        btfsc RCSTA,FERR
        goto  WaitForStart
        movf  RCREG,W
; check for the START code value, if it is not 0, ignore the rest of the frame
        andlw 0xff
        bnz    Start ; ignore the rest of the frame if not zero
; init receive counter and buffer pointer
        clrf CountL
        clrf CountH
;;        clrf RxBuf
        clrf RCREG; third loop, receiving 512 bytes of data
WaitForData
        btfsc RCSTA,FERR ; if a new framing error is detected (error or short frame)
        goto    RXend ; the rest of the frame is ignored and a new synchronization is
;                     attempted
        btfss PIR1,RCIF ; wait until a byte is correctly received
        goto    WaitForData ;
        movf  RCREG,W ; MoveData
        movwf RxBuffer ; move the received data to the buffer
; (auto-incrementing pointer)
        incf  CountL,F ; increment 16-bit counter
        btfss STATUS,C
        goto    WaitForData
        incf  CountH,F
        btfss CountH,1 ; check if 512 bytes of data received
        goto  WaitForData
;******************************************************************************
; when a complete frame is received
; use the selected CHANNEL data to control the CCP1 & CCP2 module duty cycle
RXend
        clrf  RxBuffer ; use indirect pointer 0 to address the receiver buffer
GetData
        movlw  LOW(CHANNEL) ; add the offset for the select channel
        addwf  FSR,F
        movlw  HIGH(CHANNEL)
        addwf FSR,F
;;        movwf  INDF,CCPR2L ; retrieve the data and assign MSB to control PWM2
;;        movwf  INDF,CCPR1L ; retreive the data and assign MSB to control PWM1
        movlw  INDF
        movwf  CCPR2L ; retreive the data and assign MSB to control PWM2
;*****           
        movlw  INDF
        movwf  CCPR1L ; retreive the data and assign MSB to control PWM1
;*****           
        goto    Start ; return to main loop
;******************************************************************************
; Setup Serial port and buffers
SetupSerial
; Clear the receive buffer
;*****
        clrf    RxBuffer
CBloop
        clrf    RxBuffer ; clear INDF register then increment pointer
        incf    CountL,F
        btfss   STATUS,C
        goto    CBloop
        incf    CountH,F
        btfss   CountH,1
        goto    CBloop
; Setup EUSART
        banksel TRISC
;;        bsf     TRISC,7 ;B'10000000' ; allow the EUSART RX to control pin RC7
;;        bsf     TRISC,B'10000000'; allow the EUSART TX to control pin RC6
movlw B'11000000'
movwf TRISC
        movlw   0x04 ; Disable transmission
        movwf   TXSTA ; enable transmission and CLEAR high baud rate
        movlw   0x90
        movwf   RCSTA ; enable serial port and reception
;;        bsf     BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
        bsf     TXSTA,BRGH
        clrf    SPBRG
        movlw   .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
        movwf  SPBRG
; Setup PWM module
        movf    CCP1CON,W               ; configure CCP1 for PWM mode
        andlw   0xF0
        iorlw   0x0C
        movwf   CCP1CON
;*****
        movf    CCP2CON,W             ; set CCP2 as PWM mode
        andlw   0xF0
        iorlw   0x0C
        movwf  CCP2CON
;*****
  ; Timer1 control
        movf  T1CON,W              ; configure Timer1 to oscilation
        andlw   0x09
        iorlw   0x04
        movwf   T1CON       
;Timer2 control
        movlw   0x04                    ; enable Timer2, select a prescale of 1:1
        movwf   T2CON
          ; PWM period
        movlw   0xFF ; 256 x .25us = 64us period
        movwf  PR2
; init  I/O
        banksel TRISA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;        bsf     TRISA;;;;;;;;;;;;;
movlw 0x00
movwf TRISA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        movlw   b'11111111'             ; make pins on PortA inputs
        movwf   PORTA
;int   I/O
        banksel TRISB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;        bsf     TRISB;;;;;;;;;;;;
movlw 0x00
movwf TRISB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        movlw   b'11111111'              ; make pins on PortB inputs
        movwf   PORTB
;init I/O
        banksel TRISC
;;        bsf     TRISC;;;;;;;;;;;;;;
movlw 0x00
movwf TRISC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        movlw   b'11110111'             ; make pin RC2 (CCP2) output
        movwf   PORTC
        return
;*****
    END                       ; directive 'end of program'
Logged

jpk

  • Newbie
  • *
  • Posts: 1
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #4 on: March 19, 2010, 01:44:10 AM »

Might be of some use but possibly overboard for your project, I have released my USB DMX512-A product as open source. One method I use to ensure 100% reliable DMX512 break reception is by using an external counter, see attached schematic.

Firmware is at http://code.google.com/p/dmxking-usbdmx512/ and you can become a fan on the facebook page http://www.facebook.com/pages/DMXking/335067574205

Jason
Logged

DMX512

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #5 on: March 19, 2010, 03:06:52 AM »

One method I use to ensure 100% reliable DMX512 break reception is by using an external counter, see attached schematic.
Although I cant see the schematic (not attached), using a counter to detect break is an excellent idea, much better than misusing framing errors, which is the most widely used approach.  However, depending on your choice of processor, and how much the resources offered by the processor are utilised, you could possibly use on on-board counter to do the same thing as an external counter.
Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #6 on: March 19, 2010, 09:40:28 AM »

i think that is a brilliant idea, i never thought of it. i am a newbee on the PIC microcontroller programming. i will see if i can add it to my circuit

thnk you for the information
Logged

DMX512

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #7 on: March 19, 2010, 09:12:00 PM »

The PIC isn't a bad choice of processor for this trick, as it has count / compare thingies, which I think could be persuaded to do most of the work for you.

Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #8 on: March 23, 2010, 03:46:12 PM »

hi guys
i have a Velleman K8048 programmer and it seems to give me problems everytime i try to assemble my .asm file from MPLAB v8.43 so i can load the hex file  to the PIC16F876. it gives me errors which i do not get when i use the v8.43 to create hex files
the Velleman comes with MPLAB IDE v5.2.
could it be the different versions of MPLAB which cause the problems when assembling?

please help
thank you in advance
Logged

DMX512

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #9 on: March 26, 2010, 07:27:33 PM »

Could you be more specific as to the "problems"?
Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #10 on: March 26, 2010, 08:43:52 PM »

i was trying to load a .asm file from MPLAB IDE v8.43  to the MPLAB v 5.2 which comes with the Velleman K8048 programmer. so i have been able to load the hex file using the functions in the PicProg2009 software. now when i load the hex file and try to run the program from the PIC16F876, nothing happens
i have tried to change the coding but still nthing happens
when i test the voltages on the pins iget the following
pin 9 with respect ot ground = 1.85V
pin 10 wit respect to ground = 2.55V
pin 9 and 10 are the external 20MHz connections(crystal oscilator)
pin 18 (RC7 DMX input has 4.97V from the TIL194 opto-isolator)
opto- isolator gets the biasing voltage from pin1 of the max485 chip which is connected to the DMX512 line

my proposed output pins for PWM are RC0, RC1 and RC2 of the chip and i get 0.1V from them which is not high enough to switch on the transistors driving the High brightness LEDs
Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #11 on: March 28, 2010, 11:40:35 AM »

hi guys
i have assembled my program without any errors and have run the MPLAB SIM and iget the following message. does it affact my program form running after loading to my PIC16F876
here is the message   
Code: [Select]
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
UART-W0005: Synchronous mode is not implemented in USART. Use Asynchronous mode only.
 

please help
thank you in advance
Logged

DMX512

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #12 on: March 28, 2010, 09:07:05 PM »

DMX512 reception uses asynchronous comms, so the fact the simulator doesn't support a mode you're not using is not a problem.  Those are just warning messages anyway.

In terms of debugging - start simple - dont try to get PWM up intially, settle for a LED going on and off.

The three tools I find most helpful for PIC debugging is the on-board ICD with MPLab's free software, a LED or two attached to pin(s) and a scope (or a counter / timer) for timing things.  With real-time stuff you cant single step your way through code with the ICD, but you can use breakpoints and examine data which is really helpful.
Logged

tendai02

  • Newbie
  • *
  • Posts: 10
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #13 on: March 28, 2010, 09:52:47 PM »

thank you very much for the advise. the reason why i am using PWM is because it is one of the conditions in my final year project. so in this project, the pulse-width-modulation will be used to dim the LED light using the signal from a DMX512 console or generator which can produce the DMX512 signal. at the moment, i am using a Velleman USB controlled DMX interface to get my DMX512 signal.
Logged

Colby

  • Newbie
  • *
  • Posts: 1
Re: SIMPLE LED LIGHT CONTROLLED BY DMX512 SIGNAL
« Reply #14 on: February 03, 2011, 03:11:43 AM »

I want to see more updates of that work. The simple LED light is one of the nicest light. It is such a good thing to be learned.
« Last Edit: February 05, 2011, 04:43:48 AM by Colby »
Logged
Pages: [1] 2