PDA

View Full Version : DMX receive issue



NoahLD
- 29th July 2009, 03:05
I consider myself a newbie with PIC programming but have been using dmx devices for years. It's now time to try and build my own. I have done a few projects with microcontrollers but most of my projects have been stand alone PWM and ADC projects.
I've got my USITT /ESTA DMX info book and code that sort of works.
I'm just trying to receive the data and look at it on my serial display. For now, I'm just trying to receive channel one. I'll graduate up to counters and dip switches later.
When I receive the data, the numbers come in correct until I get to 3%, then it hangs up but recovers at 5%. Then it hangs up from 14% on up to 19. There are other places that it hangs up all the way up to 100.
I have tested my controller (A Swisson DMX tester) and looked at it on my scope.
It gets weirder. When I take channel two up to 4% (not 1,2,or 3, just 4 and some other numbers above that) the code works perfectly for channel one.
Timing issue?
Missing break detection?
Thanks for your help...........
Here's my code:

It's on a 16F876A



'************************************************* ***************
'* Name : DMX21LCD.BAS *
'* Author : Noah Davis *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'* Date : 7/28/2009 *
'* Version : 21.0 *
'* Notes : *
'* : *
'************************************************* ***************
init:

DEFINE OSC 20
Include "modedefs.bas"


DEFINE CHAR_PACING 1000
define HSER_TXSTA 24H
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1
TXSTA.2 = 1 'brgh = 0 1= high speed
SPBRG = 4

Symbol DmxIn = PORTC.7
Symbol TestLed = PORTA.0

counter var byte
BreakDet var word
dummy var word
startcode var byte
newlevel1 var byte
ADCON1 =%00000111 'Turns the A/D converters to digital

main:


pulsin DmxIn,0,BreakDet 'measure the break
if breakdet < 40 then main 'if break is less than 80uS then try again
dummy = RCREG
dummy = RCREG
RCSTA.7 = 1 'sets SPEN
RCSTA.4 = 0 'Clear CREN
RCSTA.4 = 1 'Sets CREN
while PIR1.5 = 0 'wait for USART receive flag
wend
startcode = RCREG 'that lovely 0 start code
while PIR1.5 = 0 'wait for channel one
wend
newlevel1 = RCREG ' my data
RCSTA.7 = 0 'shut off the USART
RCSTA.4 = 0 'Clear CREN
Gosub SendCommand
goto main

SendCommand:
serout PORTC.6,T9600,[$FE,$01] ' clear the screen
Serout PORTC.6,T9600,[#newlevel1] 'send data to screen
return

NoahLD
- 29th July 2009, 16:59
I should start by saying thanks to folks like JEC for posting their code snippets to help get me started.
When I changed the BreakDet variable to byte sized, everything worked fine. I don't know why it worked but I do know that the proper break length would not need to be measured with a ruler that goes up to 65535.
I assumed you use the largest variable that will get the job done but I was wrong.
Perhaps someone can explain how to properly select the variable size.
Thanks folks.

mister_e
- 30th July 2009, 05:12
If you use DEFINE, you need to use HSERIN/HSEROUT unless, there's no big chance that your USART will be configured properly. However, with DMX, you want to stay away of HSERIN... so you'll need to manually configure the USART registerS manually. RCSTA, SPBRG, TXSTA.

Next thing... there's several method to detect the DMX break and the start code.. pulsin MAY work.. but usually detecting a framing error is more valuable. There's a few Appnote on Microchip website about that. The one I remember of is AN1076.

JEC
- 30th July 2009, 22:02
If you use DEFINE, you need to use HSERIN/HSEROUT unless, there's no big chance that your USART will be configured properly. However, with DMX, you want to stay away of HSERIN... so you'll need to manually configure the USART registerS manually. RCSTA, SPBRG, TXSTA.

Next thing... there's several method to detect the DMX break and the start code.. pulsin MAY work.. but usually detecting a framing error is more valuable. There's a few Appnote on Microchip website about that. The one I remember of is AN1076.

Agreed on all counts. HSERIN won't work very well for what you're trying to do.

Many ways to skin this particular cat, and PBP's access to the processor's registers makes this easy.

tweety
- 27th August 2014, 10:59
Hello, I am doing a project for a light which is used to dim/ brightness of LEDs controlled from a DMX 512 protocol .we r desidn our DMX receiver controller.for a single zone software works ok.but for multiple zone i don't know how to address dimmer

AvionicsMaster1
- 27th August 2014, 13:51
Why not start a new thread with all your info instead of reviving a very old one?

Please don't post in multiple places the same question.

It's also very helpful for you to tell us what version of PBP you're using, post as much of your code as possible and a schematic. There are very smart people here who'll help but their not clairvoyant. At least I don't think they are.