CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DMX512 Control
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 04, 2011 8:48 pm     Reply with quote

I also suggest you take a look at dyeatman's post, DMX-online.com, it seems to have all the info you'll need to get your communication set up correctly and it even tells you the timing requirements.
_________________
Vinnie Ryan
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 9:45 pm     Reply with quote

Dear all
CAN ANYONE... Please let me know where I am making mistake? Still my DMX is not receiving the signal.

Code:




#include <16F876A.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,PROTECT
#use delay(clock=4000000)

#byte PORTA=0x05
#byte TRISA=0x85

#bit DMXOUT=PORTA.0

#byte CH1=255

#bit d1=CH1.0
#bit d2=CH1.1
#bit d3=CH1.2
#bit d4=CH1.3
#bit d5=CH1.4
#bit d6=CH1.5
#bit d7=CH1.6
#bit d8=CH1.7

void sendbreak(void);

int j,k;
int i;


void main(void)
{
set_tris_a(0x00);
PORTA=0x00;
DMXOUT=1;
delay_ms(2000);  /// Idle

   while(1)
   {
      sendbreak();
               for(j=0;j<=64;j++)
               {
               DMXOUT=0; //SC StartBit
               delay_us(3); //SC / StartBit
               
                           for(k=0; k<=7; k++)
                           {
                                 switch(k)
                                     {
                                      case 0:
                                         DMXOUT=d1;
                                             break;
                                      case 1:
                                             DMXOUT=d2;
                                             break;
                                      case 2:
                                             DMXOUT=d3;
                                             break;
                                      case 3:
                                             DMXOUT=d4;
                                             break;
                                      case 4:
                                             DMXOUT=d5;
                                             break;
                                      case 5:
                                             DMXOUT=d6;
                                             break;
                                   case 6:
                                             DMXOUT=d7;
                                             break;
                                      case 7: 
                                             DMXOUT=d8;
                                             break;
                                      default:
                                       break;
                                      }
                              delay_us(3);
                     
                           }
               
               DMXOUT=1; //SC StopBit
               delay_us(8); //SC / StopBit
               
               DMXOUT=1; // Mark time between Frame
               delay_us(5);  //Mark time between Frame
            }
   
      
   
   }
}



void sendbreak(void)
{
DMXOUT=1; // Idle
delay_ms(500); // Idle
DMXOUT=0;

delay_us(99);
DMXOUT=1;       // MAB
delay_us(8);   //MAB

DMXOUT=0; //sc sTARTbIT
delay_us(3); //sc / sTARTBIT

delay_us(32);

DMXOUT=1; //sc StopBit
delay_us(8); //sc / StopBit

DMXOUT=1; // MTBF
delay_us(5);  //MTBF



return;

}


Thousands of thanks
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 10:20 pm     Reply with quote

Dear Vinnie Ryan,

Yes. That is the manual they supplied along with the board. Unfortunately they do not give much information on it. It has an RX-LED that will blink on receiving the data. When I compile the assembly code that I specified already, it shows that it is receiving the signal. But not with my code. As you have seen... I just tried to give the same data for all the 65 channels for testing.

Asa you can see in this manual http://www.laserpic.com/Product_galvo/LP30K_ch25D_TC_manual.pdf there is a DIP SWITCH and I have to turn on Switch 10 for DMX control and the board waits for the signal. As far as I understood from the manual... they have 25 channels and I think I can use the values they had given in the 512 column to control appropriate function.

The only thing I am planning to do for now is to control the horizontal and vertical movement of the scanners.

I use this information to write the code. http://www.dmx512-online.com/packt.html

Thanks
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 11:08 pm     Reply with quote

Dear Vinnie Ryan,
Please refer to my previous post.... Should I need the break between 25 channel data ? I think i have messed up everything now Confused

Thanks
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 11:32 pm     Reply with quote

Dear Vinnie Ryan,

And Finally......! This code works. I can see the RX LED BLINKING on the BOARD. Thank you very much for your information so far. This is the working code.

Code:

#include <16F876A.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,PROTECT
#use delay(clock=4000000)

#byte PORTA=0x05
#byte TRISA=0x85

#bit DMXOUT=PORTA.0

#byte CH1=255

#bit d1=CH1.0
#bit d2=CH1.1
#bit d3=CH1.2
#bit d4=CH1.3
#bit d5=CH1.4
#bit d6=CH1.5
#bit d7=CH1.6
#bit d8=CH1.7

void sendbreak(void);

int j,k;
int i;


void main(void)
{
set_tris_a(0x00);
PORTA=0x00;
DMXOUT=1;
delay_ms(2000);  /// Idle

   while(1)
   {
      sendbreak();
               for(j=0;j<=64;j++)
               {
               DMXOUT=0; //SC StartBit
               delay_us(3); //SC / StartBit
               
                           for(k=0; k<=7; k++)
                           {
                                 switch(k)
                                     {
                                      case 0:
                                         DMXOUT=d1;
                                             break;
                                      case 1:
                                             DMXOUT=d2;
                                             break;
                                      case 2:
                                             DMXOUT=d3;
                                             break;
                                      case 3:
                                             DMXOUT=d4;
                                             break;
                                      case 4:
                                             DMXOUT=d5;
                                             break;
                                      case 5:
                                             DMXOUT=d6;
                                             break;
                                   case 6:
                                             DMXOUT=d7;
                                             break;
                                      case 7: 
                                             DMXOUT=d8;
                                             break;
                                      default:
                                       break;
                                      }
                              delay_us(3);
                     
                           }
               
               DMXOUT=1; //SC StopBit
               delay_us(8); //SC / StopBit
               
               DMXOUT=1; // Mark time between Frame
               delay_us(5);  //Mark time between Frame
            }
   
      
   
   }
}



void sendbreak(void)
{
DMXOUT=1; // Idle
delay_us(100); // Idle
DMXOUT=0;

delay_us(99);
DMXOUT=1;       // MAB
delay_us(8);   //MAB

DMXOUT=0; //sc sTARTbIT
delay_us(3); //sc / sTARTBIT

delay_us(30);

DMXOUT=1; //sc StopBit
delay_us(8); //sc / StopBit

DMXOUT=1; // MTBF
delay_us(4);  //MTBF



return;

}



Still I need to make myself clear on certain things..... As you can see in the manual... there is something like.

Quote:


when address is 1000 0000 01
this means is 1 x 1 = 1, the same you must select DMXchannel 1 for you Start channel, DMXchannel25 for your End channel
when address os 0100 2000 01
this means is 1 x 2 + 1 x 16 = 18, the same you must select DMXchannel 18 for you Start channel,
DMXchannel 42 for your End channel


What do they mean to tell. Where did they get the Channel 42 from ???? I have only one question now... How should I send the channel data to make vertical / horizontal movements ?

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 05, 2011 6:51 am     Reply with quote

The address they are talking about is the BASE address of the board.
DMX512 spec allows for 512 addresses
Your board has 24 addresses on it

So if you program the DIP switch for address 18, your board will use addresses 18,19,20,...41,42 ( 24 contiguous addresses)

If you code the DIP switch to 1, then it'll use adresses 1.....25.

It's important to NOT have 2 devices with the same base addresses! Say you have a fog machine and your laser. If coded with the same address EVERY command you send to the laser would also go to the fog machine. NOT a good idea!

Every 'channel' controls a 'function' on the device. In the manual there will be a table of channels(1..24) and range of data( 0 to 255) along with a description of what they do. You have to create a list of channels and data that then goes to the device. Right now, your 'list' is just
#byte CH1=255

#bit d1=CH1.0
#bit d2=CH1.1
#bit d3=CH1.2
#bit d4=CH1.3
#bit d5=CH1.4
#bit d6=CH1.5
#bit d7=CH1.6
#bit d8=CH1.7

but can go up to
#byte CH24= xxx

where xxx is the value you want for that channel for your board.

You'll need to have a 'main' loop that read the data for every channel and send the data out.

Just think of it as a train with 24 boxcars going round and round a circular track forever.

You're making good progress, just be sure to backup all your programs and build up from them !
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Sat Feb 05, 2011 11:16 pm     Reply with quote

Dear temtronic

The below code is what I have done recently. I have the turned on Switch 1 and having channel selection of 1 - 25, and also Switch 10, DMX control mode. You have mentioned ....

Quote:
In the manual there will be a table of channels(1..24)


But I can see channel numbers up to 25 in the board. Forgive me if I am wrong. With the below code... It has to do an Auto up move with the speed 192. But it does not do so. I also tried this way... send data to move up wait for 500 ms and send to Auto down move. Does nothing. I can only see a small vibrating like movement. But not up and down.

I am sending a beak once it completes 25 channel data. Is that required or can I simply send 1 - 25 and again 1-25 without break in between????

I am still worried if my code is correct and confused if my code is wrong or I am not sending the data in the correct way.
Code:

#byte PORTA=0x05
#byte TRISA=0x85

#bit DMXOUT=PORTA.0

#byte CH1=0

#bit d1=CH1.0
#bit d2=CH1.1
#bit d3=CH1.2
#bit d4=CH1.3
#bit d5=CH1.4
#bit d6=CH1.5
#bit d7=CH1.6
#bit d8=CH1.7

void sendbreak(void);
void senddmx(void);

int j,k;
int i;

int8 DATA_DMX[25]={200,6,0,192,0,
               0,0,0,0,0,
               0,0,0,0,0,
               0,0,0,0,0};

void main(void)
{
set_tris_a(0x00);
PORTA=0x00;
DMXOUT=1;
delay_ms(2000);  /// Idle

   while(1)
   {
    senddmx();
   }
}



void sendbreak(void)
{
DMXOUT=1; // Idle
delay_us(100); // Idle
DMXOUT=0;

delay_us(99);
DMXOUT=1;       // MAB
delay_us(8);   //MAB

DMXOUT=0; //sc sTARTbIT
delay_us(3); //sc / sTARTBIT

delay_us(30);

DMXOUT=1; //sc StopBit
delay_us(8); //sc / StopBit

DMXOUT=1; // MTBF
delay_us(4);  //MTBF
return;

}

void senddmx(void)
{
 sendbreak();
               for(j=1;j<=25;j++)
               {
            CH1=DATA_DMX[j];
               DMXOUT=0; //SC StartBit
               delay_us(3); //SC / StartBit
               
                           for(k=0; k<=7; k++)
                           {
                                 switch(k)
                                     {
                                      case 0:
                                         DMXOUT=d1;
                                             break;
                                      case 1:
                                             DMXOUT=d2;
                                             break;
                                      case 2:
                                             DMXOUT=d3;
                                             break;
                                      case 3:
                                             DMXOUT=d4;
                                             break;
                                      case 4:
                                             DMXOUT=d5;
                                             break;
                                      case 5:
                                             DMXOUT=d6;
                                             break;
                                   case 6:
                                             DMXOUT=d7;
                                             break;
                                      case 7: 
                                             DMXOUT=d8;
                                             break;
                                      default:
                                       break;
                                      }
                              delay_us(3);
                     
                           }
               
               DMXOUT=1; //SC StopBit
               delay_us(8); //SC / StopBit
               
               DMXOUT=1; // Mark time between Frame
               delay_us(5);  //Mark time between Frame
            }
}

Thank you so much.
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 06, 2011 9:32 am     Reply with quote

Please refer to the DMX512 timing chart(in a previous reply, http://www.dmx512-online.com/packt.html ) for the bit sequence.

Your function ...sendbreak() appears to be in error.

I'd rename it 'preamble' or 'breakmab' to better describe what it does and only include code for break and mab control.
This is only called ONCE per control loop(packet), in your case a loop(packet) would be 25 channels for your device.
You can even break it down into their separate functions, break and mab.
This might be easier to understand and less confusing, easier to 'see' what is happening with the datastream.

Since every channel needs a start bit..8 databits..2 stop bits, I'd keep this code together as a function(), say 'sendchanneldata()'.

The final function would be the MTBP, signalling the end of the packet.


The overall delay for the 'packet', I'd delay for 500ms or 1,000 ms to better 'scope out' the pulse train on a scope if you have one.

I'm sure once you break it down and recode you'll see how it works.

If I had one of those boards I'd do all the code, looks like a neat project !!
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Sun Feb 06, 2011 9:29 pm     Reply with quote

I understand. Thank you for pointing it out. I have made the Break, Mab and SC in one function.

Code:


void sendbreak_mab_sc(void)
{
DMXOUT=1; // Mark time between Packet - Idle
delay_us(500);  //Mark time between Packet - Idle

DMXOUT=0; // Break
delay_us(100); //Break

DMXOUT=1;       // MAB
delay_us(8);   //MAB

/*****************************************/
/* Start Code --- SC */
/*****************************************/

DMXOUT=0; delay_us(3);  // 1 Start Bit
for(k=0; k<=7; k++)   {DMXOUT=0;delay_us(3);}
DMXOUT=1;delay_us(3); DMXOUT=1; delay_us(3); // Stop Bit

return;

}

void sendchanneldata(void)
{

               
                  sendbreak_mab_sc();
               for(j=1;j<=25;j++)
               {
               DMXOUT=1; // Mark time between Frame
               delay_us(3);  //Mark time between Frame
            
               CH1=data_DMX[j];
         
               DMXOUT=0; delay_us(3);  // 1 Start Bit
               
                           for(k=0; k<=7; k++)
                           {
                                 switch(k)
                                     {
                                      case 0:
                                         DMXOUT=d1;
                                             break;
                                      case 1:
                                             DMXOUT=d2;
                                             break;
                                      case 2:
                                             DMXOUT=d3;
                                             break;
                                      case 3:
                                             DMXOUT=d4;
                                             break;
                                      case 4:
                                             DMXOUT=d5;
                                             break;
                                      case 5:
                                             DMXOUT=d6;
                                             break;
                                   case 6:
                                             DMXOUT=d7;
                                             break;
                                      case 7: 
                                             DMXOUT=d8;
                                             break;
                                      default:
                                       break;
                                      }
                              delay_us(3);
                     
                           }

               DMXOUT=1;delay_us(3); DMXOUT=1; delay_us(3); /* Stop Bits */
            
      
            }
   
}


But still i am in trouble. Dont know why....!!!!
Sad I am very sad. Experts like mark are here... but I dont get advice from any of them too.... Sad
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 07, 2011 6:45 am     Reply with quote

You sem to be misreading the DMX512 information.
As documented in the reference in the 2nd or 3rd reply...
it goes as follows...

IDLE...hi

BREAK...lo(80-100us)

MAB...hi(8 us)

Channel data ( up to 512 channels, your board uses 24 or 25)
consisiting of

Start code low..4us
data bits 8 ..4us each
Stop bits..4 us
2nd Stop bit .. 4 us
MTBF..hi..50us

MTBP..hi..100us or more

Channel data is repeated for every channel you have( 24 or 25 for you) to control.

Your function
void sendbreak_mab_sc(void)

is sending one start code( start bit) for the entire packet, not correct.

remove it from the function.

You may find it easier to understand if you create the following functions.

idle()
break()
mab()
sendchanneldata()
mtbf()
mtbp()


Each function controls the DMXout line only for what it is required to do.

Your sendchanneldata() function may need delays in the coding as each bit MUST be 4us wide.

If you look at the listing file (ilename.lst) it'll show you the details.

hope this helps
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Mon Feb 07, 2011 9:23 am     Reply with quote

Thank you. I admit that I make lot of mistakes. To make myself clear... I have one question. The website speaks about the timing of the refresh rate. In that it is shows only one SC data (44us wide) and the channel data. I dont think SC has to be sent for every channel data.

http://www.dmx512-online.com/packt.html

Quote:
The following is a mathematical layout of the typical DMX512(1990) timing :-

[(88)+(12)+(44)+(CHL*44)+(CHL*MTBF)+(MTBP)] microsecs

Where CHL is the no of Channels under consideration.

The ideal timing ( this is purely my personal opinion) :-

[(120)+(12)+(44)+(CHL*44)+(0)+(50)] microsecs

For 512 channels my timing would be 22754 microsecs.
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 07, 2011 11:07 am     Reply with quote

yup, you're right, see what reading something a zillion times does !!!

SC is really the first channel,but all the data is zeros. So you only have 511 available channels for your use...

I admit it's been a long time since I built DMX hardware(all Z80 based).
and I built similar systems before DMX was 'mainstream' and used similar bit banging serial streams.

The refresh rate is the overall time it takes to send data to all 512 channels, but in your case just 24 of them.So your refresh rate will be faster.
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Mon Feb 07, 2011 9:40 pm     Reply with quote

I really wonder if anyone could please check and correct me if I am making any mistakes. I have pasted a piece of code that does bitbanging for DMX512. Is that the way the 8 bits has to be sent or should I make any other changes? Please guide me through.... I am almost working on this with every possible method for nearly a week without luck.
Code:

               sendbreak_mab_sc();
               for(j=1;j<=25;j++)
               {
               DMXOUT=1; // Mark time between Frame
               delay_us(3);  //Mark time between Frame
             
               CH1=data_DMX[j];
         
               DMXOUT=0; delay_us(3);  // 1 Start Bit
               
                           for(k=0; k<=7; k++)
                           {
                                 switch(k)
                                     {
                                      case 0:
                                         DMXOUT=d1;
                                             break;
                                      case 1:
                                             DMXOUT=d2;
                                             break;
                                      case 2:
                                             DMXOUT=d3;
                                             break;
                                      case 3:
                                             DMXOUT=d4;
                                             break;
                                      case 4:
                                             DMXOUT=d5;
                                             break;
                                      case 5:
                                             DMXOUT=d6;
                                             break;
                                   case 6:
                                             DMXOUT=d7;
                                             break;
                                      case 7: 
                                             DMXOUT=d8;
                                             break;
                                      default:
                                       break;
                                      }
                              delay_us(3);
                     
                           }

               DMXOUT=1;delay_us(3); DMXOUT=1; delay_us(3); /* Stop Bits */
             
       
            }
   
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Tue Feb 08, 2011 2:30 am     Reply with quote

Dear temtronic
Am I making mistakes with the bit banging part. Is the for loop correct to send the eight bits of data? Or should I make some HI / LO in between?

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 08, 2011 7:23 am     Reply with quote

One problem may be timing. The DMX spec says each bit needs to be 4usecs wide.A PIC running at 4MHz will execute most instructions in 1 usec, so DMXOUT=1 will be 1 usec+ delay_us(3) will give you the right bit width.
You could look at the listing file and calculate the timings, or use MPLAB.
If you have access to a scope, put in on the DMX pin and view the pulse train, coparing it to what the DMX spec is.
Just have data for one or two channels for the test.

You may have timing issues with the 'switch' statement in breaking down the command byte and sending it out,again the scope will quickly tell you.

If you run the PIC at 20MHz, you'll have time to decode the command and then send it out.

Unfortunately I do not have your board to 'play' with ,nor any other DMX stuff.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group