Dmx Solved !!!!!!!


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default DMX code snippets

    OK - Here are some bits and pieces from code which runs nicely on an 'F88 @ 16 MHz:

    * * * *

    DEFINE OSC 16
    DEFINE HSER_BAUD 250000
    DEFINE HSER_CLROERR 1

    * * * *
    This next routine is called on a gosub from my main housekeeping loop:
    * * * *

    checkdmx:

    counter = 1 'just a dummy variable
    pulsin target,0,counter 'here I'm 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
    'if you get here, an active low pulse was detected, but it was too short.
    'probably just part of the datastream. So go back and look again.

    'otherwise, a valid break was found and it's time to read the start code

    RCREG = dummy 'clear out any garbage which may be in the USART
    RCREG = dummy
    SPBRG = 0
    TXSTA.2 = 0 'brgh = 0
    TXSTA.4 = 0
    RCSTA.7 = 1
    RCSTA.6 = 0 'setting 8 bit receive mode, no parity, etc
    RCSTA.4 = 0 'check the datasheet to see what all these bits do
    RCSTA.4 = 1 'now, the USART is on and ready to receive

    while RCIF = 0:wend 'hover here after break, before start code

    startcode = RCREG 'This is the first byte received after the break

    if startcode <> 0 then 'do your own stuff here on a non-zero code

    aminus = address1 - 1 'address1 is my target address

    for x = 1 to aminus 'set up a loop to count almost to the address
    while RCIF = 0:WEND 'sit here until a byte is received
    dummy = RCREG 'stash the byte somewhere unimportant
    next x

    hserin [newlevel1] 'This is your target channel data

    RCSTA.7 = 0 'turn off the USART

    return

  2. #2
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Thanks!

    Thanks, John, for your help! I will be coding my gizmo in the next few days and those snippets will be very helpful in getting it up and running!

    I'll let you know how it goes...

    Thanks again--

    --Alan

  3. #3
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Smile Success!! (mostly)

    Hi John--

    Well, I got it working, and its working fast, solid, stable and it is a really beautiful thing! Thank you so much for your help!

    I am having one problem... I used your code as-is, and I defined a starting address before starting the loop that calls checkdmx. The problem is there's a one channel offset-- if I program in channel 5 as my target address, the device actually reads the data coming in on channel 6. If I define channel 1, it reports what's coming in on channel 2. I can't get DMX channel 1. I can't set my starting address to 0 to compensate, or when we do the subtraction that sets aminus it would underflow and seek the wrong address. What do you think is causing this? I realize I could rewrite the code to trap out this error, but since you know your code works the way you wrote it I'm wondering what could be happening here.

    I also have a question-- you determine the start code by reading RCREG right after the bit is set indicating that something came into the USART following the start break with the statement startcode = rcreg. If that's all it takes to read the start code as a valid numerical byte, why do you need to use the hserin[newlevel1] statement at all? I realize my inexperience and lack of understanding about the USART is probably why I don't get it, but I am curious.

    Thanks again for all your help, it has truly been invaluable!

    --Alan

  4. #4
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default Dmx

    Two thoughts...

    First, I made a typo when I posted the original code:

    RCREG = dummy is bad. It should be
    dummy = RCREG to clear out the buffer.

    As far as catching the early data goes, it's probably more elegant to do something like

    while x < aminus
    'wait for a byte
    'discard it
    'increment x
    WEND

    This way, if aminus = 0 and your address = 1, the trashing routine is skipped altogether.

    ...

    And you're exactly right - there's no reason why you should need to use HSERIN at all to grab the last byte. I was experimenting back and forth reading the registers and using HSERIN. Once I got it stable, I didn't change everything to match.

    So you can leave it, or change it to say

    newlevel1 = RCREG

    Either way, it should work fine.

    Curious - what are you building?

    John

  5. #5
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default DMX Continued

    Hi John--

    I tried the While:wend loop you recommended to compensate for the adrress offset, but it didn't fix it... what DID fix it was getting rid of the HSERIN command-- when I changed that to newlevel1 = rcreg, it zeroed in on the correct address! I'm wondering if the HSERIN statement has some overhead that causes it to miss that first target byte?

    Regarding what I'm building, I replied to you offlist, so look for a message there.

    Thanks again--

    --Alan

    PS: Are there any gotchas if I want to use the USART to transmit DMX?

Similar Threads

  1. DMX receive issue
    By NoahLD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th August 2014, 13:51
  2. Simple 4 channel DMX controller
    By eggman in forum Code Examples
    Replies: 19
    Last Post: - 18th July 2012, 01:40
  3. Dmx
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th November 2008, 07:56
  4. Big Problem in PBP To receive DMX
    By programmer07 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th March 2007, 18:49
  5. DMX & PicBasic coding problem
    By magicmarty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2004, 15:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts