DMX solution

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
SIGNIN STARTUPS
Posts: 2
Joined: Fri Oct 10, 2008 7:48 pm

DMX solution

Post by SIGNIN STARTUPS »

Hello everybody, and I think a lot of you are going to read this topic.

I am one of many that try to make a DMX receiver for RGB LED lighting , let's say. I read here some posts, but didnt find a real solution or how this problem can be solve.
But I DID IT. It took me some days because I'm not a profesional programmer, but I work with Flowcode from 10 monts ( done a lot of projects with it ), have some background knowledge of some PASCAL ( learned at 14 years age ... 12 years ago ) and verry litle C. From the begining I'm telling you that I WILL NOT GIVE THE SOURCE CODE, but I was thinking that is good to give you some advice.

So lets put the problem. DMX ??? ... you know what is DMX. Lets use PIC16F88 for example.
250000 baud rate - if you look at the PDF of PIC16F88 at the BRG ( baud rate generator ) section you will se that we will need to CLOCK the micro at 16000000 Hz. NO NEED for 20000000 Hz clock.

min 88 ms of BREAK ( 0 logic ) -> min 8 ms of MAB ( 1 logic ) -> serial frames
a serial frame is composed of 11 pulses : 1 - START BIT ( 0 logic )
2 - 9: 8 bits = DATA BITS
9 - 11 - 2 STOP BITS ( 1 logic )
between frames there is MTBF - Mark time between frames min 1 pulse ( 1 logic )
first frame is known as START CODE , wich has DATA=0, then begins the frames wich have DATA for CH1, CH2, CH3 ... CH512

First thing ... YOU CANT RECEIVE DMX only using flow charts from Flocode ( RS232 macro )... you have to use some " C code " :mrgreen:

You have to know how to set the UART baud rate at 250000, then how to set for receiving - use the pdf of PIC. Let's suppose the hardware it is done, and you start receive the DMX.
Most important thing is to know when the BREAK starts ... this is the part wher you do the sincronization of the receiver with the transceiver. HOW can we do that?
So we know that the break is 0 logic. The USART see the first O logic of the break to be the START BIT. then the next 8 bits to be DATA - wich is O ... then? instead of 2 STOP BITS 1 logis , there is only o logic. Hmmm .. USART " say " that this is a FRAME ERROR.
So the method ao detecting the BREAK is to detect the first FRAME ERROR.
Another methos is to set the USART in 9BIT MODE ( 1 START BIT, 8 DATA BITS, 9th BIT, and 1 STOP BIT ( 1 logic also ). when the USART detects first 0 of the BREAK he thinks that is a START BIT .. then DATA then 9th BIT .. Hmmm ... CHECK if the 9th bit is 0 or 1. if it is 0 the this detection is for sure the begining of the BREAK.

OK.. we have now the START of the BREAK.. But when is it end? Of couse it's end at the begining of MAB .here is min 2 BITS 1 logic. here is a verry delicate situation.

if the BREAK consist of multiple pulses of 11 ( wich is the lenght of a frame ) the first frame that gives no error is the end of BREAK and MAB. How can we find that?
- After we find the BREAK with the first frame error we loop for finding the next errors until we find NO ERROR. there is the end of the BREAK .. and the MAB looks for the USART like that 2 STOP BITS from a frame ... so this frame has a 0 START BIT from the BREAK ... next 8 data BITS 0 from the BREAK ( here the BREAK ENDS ) and next 2 STOP BITS wich are the MAB. here is a NO ERROR frame that has DATA = 0. you have to discard this " non using " data ... leave it.
- If we use the 9th BIT mode .. and we find the first 9th BIT 0 wich tell's the beginig of the BREAk .. then we loop and chech the 9-th bit until we find the first one that is 1 logic. This is the firs BIT of the MAB .. we have an END OF THE BREAK . THIS two method are good only if BREAK + MAB are multiple of 11 pulses.

But what if the BREAK+MAB is not multiple of 11 BITS ( I relly dont know if that is alowed ). Hmmm ... we can detect the start of the BREAK. But then? ... lets say we have another FRAME ERROR ( frame has 11 BITS) so total of 22 BITS ( 0 logic ). This is the min of BREAK alowed - 22 pulses. .. SO we are in the frame error detection loop. then after MAB, it begins a 0 logic- START BIT , 8 DATA=0 and 2 STOP BITS ... here is the START CODE... no error , the 9th bit is 1 ... al is OK ... so you have to discard this data and begin receiving chanel data. But hey, up we've done the same algoritm and we didnt detect the START CODE frame. We only detect the end of the BREAK and MAB.
Let me give you another example . BREAK has 23 pulses , MAB 2 .. then the rest
fisrst frame - 11 pulses of 0 -> FRAME ERROR
2 nd frame - 11 pulses of 0 - > FRAME ERROR
3 rd frame - we had 22 o fro BREAK until now.. so 0, MAB. START CODE wich id o => 01100000000 - HEY this looks like a frame ERROR : 0 - START BIT , 11000000 - DATA , 00 2 STOP BIT or 9th BIT and STOP BIT. so this is a situation where we dont detect the START CODE frame. pfff this can get us o lot of problems
if the BREAK would be 32 pulses we will have 2 frame of 0, then 10 of LOW 0 , and 1 HIGH BIT. so we have 01 STOP BITS .. ERROR again.

Conlusion: depends of the BREAK length we can find the end of the BREAK / or the START CODE or even nothing of these two, in some situations, with the same algoritm ... Hehe ... thid can cause a lot of problems.

Solution: We use a litle hardware help. set another pin from the PIC toghether with the RX pin ( put a 4,7 K resistor between them ) to be an input pin.
we detect the BREAK ... OK easy .. then a lot of 0 begin to show until the BREAK is end.. We can find that using THIS INPUT PIN. put him in a loop and check it until you find the first HIGH BIT . This is the first BIT from MAB .. so we have an end of the BREAK here ... it is so easy and " no mistake " thing to do. Then we cand know for sure that next LOW 0 BIT is going to be the begining of the START CODE .. WE HAVE a sincronization gentelmans :lol: .

After you detect the MAB with pin input you can use the RS232 macro from Flocode to get the DATA ( first one is the START CODE wich you have to discard, the is the CH1, CH2 .. etc.)
My storry ends here. And I repeat .. NO SOURCE CODE .
I hope this story will help you.

proton
Flowcode V4 User
Posts: 50
Joined: Sun Feb 03, 2008 10:14 pm
Has thanked: 1 time

Re: DMX solution

Post by proton »

The problem will come about when you jump out of the PWM macro to recieve the DMX the LEDS will flicker on or off ! :roll:

SIGNIN STARTUPS
Posts: 2
Joined: Fri Oct 10, 2008 7:48 pm

Re: DMX solution

Post by SIGNIN STARTUPS »

There is no PWM macro, you just use TMR0 interrupt, and all will be fine. When i get DATA with USART, i dont use any interrupts, so I can use it to light the LED's .For example I can light 3 RGB pixels with 16F88, and is working just fine.. no flicker.
I'm a little doubt about my story now... because after a few test , the actual method to receive DMX, sound like this:

I set up baud rate at 250000
I put the USART in receiving mode and begin receiving
I wait until the USART gives me a frame error - now I know is the strat of the break
and after that I check until the first time i have no frame error, and when I have no frame error it means that this is the START CODE.. and i discard this data
after that all is easy.
This is the method I'm using now and it works just fine.

About your flicker . there are 2 possibilityes:
1. you dont have the correct 250000 baud rate, but this is not so hard to set .. so I dont think you have some problems with this
2 . your code doesn't detect corectly the START CODE frame, wich means that some times it does work fine , and sometimes you have a desynchronization, and the leds are off for a short time... until next time he detects the correct START CODE. try to send DMX only for 32 CH ... then for 256 CH .. if the flicker is different , then this is the reason. Or if you have a led on CH1 and send data 255, try to raise the next CH at 255 ( 2, 3 , 4 ,5 ..... ) and you will see that the flicker begins to show more rarely, maby never.This mean you have a problem with the code ... you are not sinchronizing your receiver verry well.

You can send me your code , and I will take a look, and give you some suggestions.

proton
Flowcode V4 User
Posts: 50
Joined: Sun Feb 03, 2008 10:14 pm
Has thanked: 1 time

Re: DMX solution

Post by proton »

OK thanks, cast your eyes over this program

Thanks
full_colour1.fcf
(6.5 KiB) Downloaded 997 times

Post Reply