PDA

View Full Version : DMX512 Problem ..Schema+Code



programmer07
- 25th February 2007, 19:03
i want to make code for dmx512 protocol i have 9 dipsw on my project and 3 led i want to make 512 adres with the dips. and i will make pwm control for my 3 leds as a seperate it means dmx512 control with 3 chanel i have schema and code but not working can you help me please?


' 512 Kanal DMX SLAVE

'******************** INCLUDE FILES **********************

INCLUDE "modedefs.bas"

'************************************************* ************
'******************** REGISTER **********************
DEFINE OSC 4
DEFINE HSER_TXSTA 24h
DEFINE HSER_RCSTA 90h
'DEFINE HSER_SPBRG 129
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1


CMCON = 7 ' Disable analog comparator


'************************************************* ************


'******************** DEĞİŞKENLER **********************
DipAdrr VAR WORD ' 512 Veya 1024 Adresle İçin WORD
DipAdr_L VAR DipAdrr.Byte0 ' 512 Veya 1024 Adresle İçin
DipAdr_H VAR DipAdrr.byte1 ' 512 Veya 1024 Adresle İçin

DmxAdrr VAR WORD
DmxAdr_L VAR DmxAdrr.Byte0
DmxAdr_H VAR DmxAdrr.Byte1



IntData VAR BYTE[4] ' Kesme Data Dizisi
DmxData VAR BYTE ' Networkten Gelen Data
DmxChanel VAR BYTE ' DMX Kanal
DmxCom VAR BYTE ' Dmx Komut

Addr VAR BYTE ' Genel Sayac
KesmeSayac VAR BYTE ' Kesme Sayac




'************************************************* ************



'******************** ATAMALAR **********************
Led_G VAR PORTB.0 ' Green Led
Led_R VAR PORTB.3 ' Red Led
Led_B VAR PORTB.7 ' Blue Led

DipAdr0 VAR PORTA.0 ' Dip Swicht 0
DipAdr1 VAR PORTA.1 ' Dip Swicht 1
DipAdr2 VAR PORTA.2 ' Dip Swicht 2
DipAdr3 VAR PORTA.3 ' Dip Swicht 3
DipAdr4 VAR PORTA.4 ' Dip Swicht 4
DipAdr5 VAR PORTB.4 ' Dip Swicht 5
DipAdr6 VAR PORTB.5 ' Dip Swicht 6
DipAdr7 VAR PORTB.6 ' Dip Swicht 7
DipAdr8 VAR PORTA.5 ' Dip Swicht 8


GIE VAR INTCON.7 ' Global İnterrupt Enable Bit
PEIE VAR INTCON.6 ' Çevresel İnterrupt Enable Bit
T0IE VAR INTCON.5 ' Timer0 İnterrupt Enable Bit
INTE VAR INTCON.4 ' PORTB İnterrupt Enable Bit
RBIE VAR INTCON.3 ' Up PORTB İnterrupt Enable Bit
T0IF VAR INTCON.2 ' Timer0 Flag Bit
INTF VAR INTCON.1 ' PORTB.0 Flag Bit
RBIF VAR INTCON.0 ' PORTB Flag Bit


RCIF VAR PIR1.5 ' Receiver Enable Bit
TXIF VAR PIR1.4 ' Transmit Enable Bit

SYNC VAR TXSTA.4 ' Usart Mode Select Bit 1=Senkron, 0= Asenkron

SPEN VAR RCSTA.7 ' Serial Port Enable Bit
RX9 VAR RCSTA.6 ' 9 Bit Receive Enable Bit
SREN VAR RCSTA.5 ' Single Receive Enable Bit
CREN VAR RCSTA.4 ' Continuous Receive Enable Bit
ADEN VAR RCSTA.3 ' Address Detect Enable Bit
FERR VAR RCSTA.2 ' Frame Error Bit
OERR VAR RCSTA.1 ' Overrun Error Bit
RX9D VAR RCSTA.0 ' 9 Bit Of Receive Bit


'************************************************* ************


'******************** PORT YONLERI **********************

TRISA.0=1 ' IN
TRISA.1=1 ' IN
TRISA.2=1 ' IN
TRISA.3=1 ' IN
TRISA.4=1 ' IN
TRISA.5=1 ' IN


TRISB.0=0 ' OUT
TRISB.3=0 ' OUT
TRISB.4=1 ' IN
TRISB.5=1 ' IN
TRISB.6=1 ' IN
TRISB.7=0 ' OUT


Addr = 0
KesmeSayac = 0



PIE1.5 =1 ' Enable USART receive interrupt
INTCON.6 =1 ' Enable peripheral interrupt

ON INTERRUPT GoTo DmxKesme


Main : GoSub DipOku

DmxAdr_L = IntData[0]
DmxAdr_H = IntData[1]
DmxCom = IntData[2]
DmxChanel = IntData[3]


IF DmxAdrr = DipAdrr Then

IF DmxCom = "1" Then

IF DmxChanel = "1" Then
High Led_G
EndIF

IF DmxChanel = "2" Then
High Led_G
EndIF

IF DmxChanel = "3" Then
High Led_G
EndIF

EndIF


IF DmxCom = "0" Then

IF DmxChanel = "1" Then
Low Led_G
EndIF

IF DmxChanel = "2" Then
Low Led_G
EndIF

IF DmxChanel = "3" Then
Low Led_G
EndIF

EndIF

EndIF



GoTo Main



'************************************************* ************
'******************** ADRES OKU **********************
'************************************************* ************
DipOku : DipAdrr.0 = DipAdr0
DipAdrr.1 = DipAdr1
DipAdrr.2 = DipAdr2
DipAdrr.3 = DipAdr3
DipAdrr.4 = DipAdr4
DipAdrr.5 = DipAdr5
DipAdrr.6 = DipAdr6
DipAdrr.7 = DipAdr7
DipAdrr.8 = DipAdr8
DipAdrr.9 = 0
DipAdrr.10 = 0
DipAdrr.11 = 0
DipAdrr.12 = 0
DipAdrr.13 = 0
DipAdrr.14 = 0
DipAdrr.15 = 0



Return
'************************************************* ************



'************************************************* ************
'******************** KESME **********************
'************************************************* ************
Disable INTERRUPT

DmxKesme : DmxData = RCREG

IntData[Addr] = DmxData

IF Addr = 4 Then
Addr = 0
Else
Addr = Addr + 1
EndIF

RCSTA=$90

Resume

Enable INTERRUPT
'************************************************* ************





End

mister_e
- 25th February 2007, 20:34
DMX baudrate is 250 000 Baud, 9600 will never ever work.

AND as you dont use any HSERIN/HSEROUT, the DEFINE HSER_xxx are useless. You need to write the right value directly to the SPBRG, RCSTA, TXSTA register

AND @4MHZ... good luck to have a reliable 250K baud serial comm. 12MHZ and up will work.

programmer07
- 26th February 2007, 17:50
thanks for helping. i have tryed it with 250.000 too but stll have some problem and not working do youahev any schematic like this or some code to help to me about this dmx512aderes systems?

malc-c
- 26th February 2007, 18:44
Edited - just saw the original post - sorry

programmer07
- 26th February 2007, 19:58
is there anybody here to solve my problem ?
for my schmatic i have 20mhz osc and 9dipsw+and 16f628A i want to dim 3 led output,
how can i make it ?

mister_e
- 26th February 2007, 22:16
If you're using the right USART setting for the right OSC speed, having properly set the PIC config fuses, added DEFINE OSC 20, i think your code will work.

google for PIC16F628 gave me
http://si-light.sourceforge.net/
http://www.qsl.net/n5tle/
http://www.epanorama.net/links/lights.html#dmx512
http://www.elektronicaforum.nl/dmx-bouwen-t644.html
http://www.epanorama.net/digipack/DMX_Pro/index.html

programmer07
- 27th February 2007, 10:25
Thanks mister ;
i saw that websites before and i know how to search "dmx" on the google yhanks for it.
i need a code for my project i have that code but 6 people says that it doesnt wrong there is some problem in it but you say that it will work?
did you understand tht what i need or what i want to say for my schema?

can you look to my code and give right code because it is not working my code is for 20 osc and also im sure my fisues are ok.
if you have another schema or code also you can give i can make it too for 512 or 256 adres no problem

mister_e
- 27th February 2007, 23:15
what do you have on hand to say it's not working? which console OR software?

skimask
- 27th February 2007, 23:24
Thanks mister ;
i saw that websites before and i know how to search "dmx" on the google yhanks for it.
i need a code for my project i have that code but 6 people says that it doesnt wrong there is some problem in it but you say that it will work?
did you understand tht what i need or what i want to say for my schema?

can you look to my code and give right code because it is not working my code is for 20 osc and also im sure my fisues are ok.
if you have another schema or code also you can give i can make it too for 512 or 256 adres no problem

Let's see your code and schematic. Also, which version of PBP are you using?

programmer07
- 28th February 2007, 00:12
my code ans schema is here begining didnt you see it?

skimask
- 28th February 2007, 00:20
my code ans schema is here begining didnt you see it?

I saw it, but I figured you might have modified the code according to mister_e's suggestion and added some troubleshooting and/or maybe changed the hardware a bit to make problem solving a bit easier somehow.
But we still don't know which version of PBP you are using...

programmer07
- 1st March 2007, 00:38
Yes i have made some changes on it that what mister_E says
bu i need example fr my schema to recevie data and adres from the transmitter
stil have problem to make control my leds to intensty and to setup dmx adress...
mister_e says that it must be 250000 baud
i have made it here but still have problem
CAN YOU LOOK WHERE IS MY PROBLEM :--(
HOW TO USE hserin here?
can you prepare it to my schematic i wii use only 3 chanel of leds to make control for intensty no more


'******************** INCLUDE FILES **********************
INCLUDE "modedefs.bas"
'******************** REGISTER **********************
DEFINE OSC 4
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER_SPBRG 129
DEFINE HSER_BAUD 250000
CMCON = 7 ' Disable analog comparator

DipAdrr VAR WORD ' for 512 adress Dip
DipAdr_L VAR DipAdrr.Byte0
DipAdr_H VAR DipAdrr.byte1

DmxAdrr VAR WORD ' Adres For 512
DmxAdr_L VAR DmxAdrr.Byte0
DmxAdr_H VAR DmxAdrr.Byte1

IntData VAR BYTE[4]
DmxData VAR BYTE
DmxChanel VAR BYTE
DmxCom VAR BYTE

Addr VAR BYTE
KesmeSayac VAR BYTE ' interupt count


Led_G VAR PORTB.0 ' Green Led
Led_R VAR PORTB.3 ' Red Led
Led_B VAR PORTB.7 ' Blue Led

DipAdr0 VAR PORTA.0 ' Dip Swicht 0
DipAdr1 VAR PORTA.1 ' Dip Swicht 1
DipAdr2 VAR PORTA.2 ' Dip Swicht 2
DipAdr3 VAR PORTA.3 ' Dip Swicht 3
DipAdr4 VAR PORTA.4 ' Dip Swicht 4
DipAdr5 VAR PORTB.4 ' Dip Swicht 5
DipAdr6 VAR PORTB.5 ' Dip Swicht 6
DipAdr7 VAR PORTB.6 ' Dip Swicht 7
DipAdr8 VAR PORTA.5 ' Dip Swicht 8

GIE VAR INTCON.7 ' Global İnterrupt Enable Bit
PEIE VAR INTCON.6 ' Çevresel İnterrupt Enable Bit
T0IE VAR INTCON.5 ' Timer0 İnterrupt Enable Bit
INTE VAR INTCON.4 ' PORTB İnterrupt Enable Bit
RBIE VAR INTCON.3 ' Up PORTB İnterrupt Enable Bit
T0IF VAR INTCON.2 ' Timer0 Flag Bit
INTF VAR INTCON.1 ' PORTB.0 Flag Bit
RBIF VAR INTCON.0 ' PORTB Flag Bit

RCIF VAR PIR1.5 ' Receiver Enable Bit
TXIF VAR PIR1.4 ' Transmit Enable Bit

SYNC VAR TXSTA.4 ' Usart Mode Select Bit 1=Senkron, 0= Asenkron

SPEN VAR RCSTA.7 ' Serial Port Enable Bit
RX9 VAR RCSTA.6 ' 9 Bit Receive Enable Bit
SREN VAR RCSTA.5 ' Single Receive Enable Bit
CREN VAR RCSTA.4 ' Continuous Receive Enable Bit
ADEN VAR RCSTA.3 ' Address Detect Enable Bit
FERR VAR RCSTA.2 ' Frame Error Bit
OERR VAR RCSTA.1 ' Overrun Error Bit
RX9D VAR RCSTA.0 ' 9 Bit Of Receive Bit

TRISA.0=1 ' IN
TRISA.1=1 ' IN
TRISA.2=1 ' IN
TRISA.3=1 ' IN
TRISA.4=1 ' IN
TRISA.5=1 ' IN

TRISB.0=0 ' OUT
TRISB.3=0 ' OUT
TRISB.4=1 ' IN
TRISB.5=1 ' IN
TRISB.6=1 ' IN
TRISB.7=0 ' OUT

Addr = 0
KesmeSayac = 0 ' interupt count = 0

PIE1.5 =1 ' Enable USART receive interrupt
INTCON.6 =1 ' Enable peripheral interrupt

ON INTERRUPT GoTo DmxKesme

Main : GoSub DipOku

DmxAdr_L = IntData[0]
DmxAdr_H = IntData[1]
DmxCom = IntData[2]
DmxChanel = IntData[3]

IF DmxAdrr = DipAdrr Then

IF DmxCom = "1" Then

IF DmxChanel = "1" Then
High Led_G
EndIF

IF DmxChanel = "2" Then
High Led_G
EndIF

IF DmxChanel = "3" Then
High Led_G
EndIF

EndIF

IF DmxCom = "0" Then

IF DmxChanel = "1" Then
Low Led_G
EndIF
IF DmxChanel = "2" Then
Low Led_G
EndIF
IF DmxChanel = "3" Then
Low Led_G
EndIF
EndIF
EndIF

GoTo Main

'******************** READ ADRESS**********************
DipOku :
DipAdrr.0 = DipAdr0
DipAdrr.1 = DipAdr1
DipAdrr.2 = DipAdr2
DipAdrr.3 = DipAdr3
DipAdrr.4 = DipAdr4
DipAdrr.5 = DipAdr5
DipAdrr.6 = DipAdr6
DipAdrr.7 = DipAdr7
DipAdrr.8 = DipAdr8
Return
'******************** INTERUPT**********************
Disable INTERRUPT
DmxKesme : DmxData = RCREG
IntData[Addr] = DmxData
IF Addr = 4 Then
Addr = 0
Else
Addr = Addr + 1
EndIF
RCSTA=$90
Resume
Enable INTERRUPT
End

skimask
- 1st March 2007, 00:55
We still don't know which PIC you're using...and once again, at 4mhz, you're probably not going to get 250kbps of anything, much less be able to process anything with that data and have any cycles left over for anything.

programmer07
- 1st March 2007, 14:21
sorrry i forgot it to say,
i use microcode studio and Pbp 2,47
and as a pic16f628A and 20Mhz

DEFINE OSC 20
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER_SPBRG 129
DEFINE HSER_BAUD 250000


many peoples say that it is impossible to receive dmx512 in pbp.i dont know it is true or not? and i see that usart interputs is very big problem to receive 512dmx.

is it possible to receive dmx512 in 250000 baudrate?

can you make a code example to me how can i use Hserin command to receive dmx512. you can see my schema that what i want to make i have 3 chanel on my devices and i will make intensty control

0 -255 data = %0 -%100 intentsy

programmer07
- 1st March 2007, 14:30
Dear mister_e thanks for you help you have said me so;
but they say that it is impossible to receive dmx in pbp code cause of usart interputs
is it true?

but can you send an example here how to receive dmx512 with "hserin" command?
you can look my schema and say cause i have 9 dip on my schema and it is with 3 leds (3 chanel adress).and i must make intensty for my leds

0-255 = %0 - %100 intensty for each led.
--------------------------------------------------------------------------------

DMX baudrate is 250 000 Baud, 9600 will never ever work.

AND as you dont use any HSERIN/HSEROUT, the DEFINE HSER_xxx are useless. You need to write the right value directly to the SPBRG, RCSTA, TXSTA register

AND @4MHZ... good luck to have a reliable 250K baud serial comm. 12MHZ and up will work.
-------------------------------------------------------------------------

mister_e
- 1st March 2007, 14:32
I already said...


AND as you dont use any HSERIN/HSEROUT, the DEFINE HSER_xxx are useless. You need to write the right value directly to the SPBRG, RCSTA, TXSTA register


so begin with...


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 4 ' 250 KBaud @ 20MHz, 0.0%

programmer07
- 1st March 2007, 20:36
Dear Mister_e;
yes many thereads in the forum but everybody has problem to receive dmx and nobody has succeed it..if you can writte and example here for us
i know i have to use "hserin" command and it must be 250000baud it is not my problem i know them how to make..

i want to see Code example to receive with "Hserin" Command.

You said to me that i have to use "Hserin" Commmand For DMX receive But you didnt Writte it here ,

How can i use it with 16f628A adn 20 mhz ;
I didnt build my own master.(Transmitter) i use normaly device for lighting deskControl.and it works with dmx protocol .

can you writte code here for how to receive it.
i have standart dmx512 control device .. i need 512 receiver and it must be 3 chanel for my 3 leds you can look to my schematic

ShoKre
- 12th March 2007, 01:04
if you create asm sub (you can see i.ex manolator source@4mhz) and call that sub every time when you want to make output, must be carefull, timings are critical read the dmx protocoll
another thing is dmx protocol is 250kb but is 11bit information with speciall startbit which is not standard. so forged using anny hserin or hseout exept if you can do some kind of hardware bit cutter/splitter-manipulator

sorry for my english, im not shure that i'm uderstundible

if someone is interested and able to programm DMX mini desk (i think can be done i.ex with 18f452) my wish is to see (and help)make those code (and schematic)

syscoder
- 21st March 2007, 10:55
hi friends i search in the forum and found many examples thanks. i have pic 16f876 , 20 mhz osc and 1 led ,i have dmx512 lighting desk too and i want to dimm a led on dmxadres 1 (0-255 to led intensty) but there is some problem on this code it is not working. i found this code in the forum and made it again for my pic but couldnt find the problem.can you look to my code and say what is my problem here?or you can send other example code to receive dmx ..

' PIC 16F876 - 20MHZ OSC

DEFINE OSC 20 ' 20 MHZ OSC
DEFINE HSER_TXSTA 24h ' Enable transmit
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_SPBRG 4 ' 250 000 Baud @ 20MHz, 0.0%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

ASM
ERRORLEVEL -306, -302
ENDASM

ADCON0 = 0
ADCON1 = 7

counter var word
idleflag var word
dummy var word
RCIF VAR BYTE
startcode var word
aminus var word
adress var word
x var word
level1 var word
adress = 1 ' My Start Adress


checkdmx:
counter = 1 ' Dummy variable
pulsin portC.7,0,counter 'Here looking for the break signal
if counter = 0 then
idleflag = 1 'either no dmx , or break was too long to count
'return
endif
if counter < 40 then checkdmx ' watching for "break"
dummy = RCREG
dummy = RCREG
SPBRG = 0
TXSTA.2 = 0
TXSTA.4 = 0
RCSTA.7 = 1
RCSTA.6 = 0
RCSTA.4 = 0
RCSTA.4 = 1

while RCIF = 0: wend
startcode = RCREG 'firs byte after break
if startcode <> 0 then checkdmx
aminus = adress -1

for x = 1 to aminus
while RCIF = 0: wend
dummy = RCREG
next x

level1 = RCREG
portC.1 = level1 'i want to dimm led on port c.1
RCSTA.7 = 0

goto checkdmx
return

DynamoBen
- 21st March 2007, 14:27
Stop posting in multiple threads!

syscoder
- 21st March 2007, 14:29
dear dynamoben here is a forum and we have to post something to learn.

i make my code change and send it back why is it problem for you here is a forum and we have to post something you may not help just looking for a people that wo will find my problem to receive data no more.

skimask
- 21st March 2007, 15:39
Stop posting in multiple threads!

How many other answers do we get to give before we completely give up?