DMX project for controlling flexible LED strip.

Thread Starter

loesvan

Joined Sep 23, 2011
28
Hello,
I have made a project for controlling RGB flexible LED strip. It's a three channel DMX controller that i want to put to give some color to my business. It uses a PIC16F628A with a code that i downloaded from the web. It all works perfectly, the only problem is that when the outputs are low, the leds vibrate, they are not stable. The potentiometre scale goes from 0 to 255. From 0 to 50 i get the vibrations and from there up it's perfect.
Any help on how to make this work properly will be really appreciated.

Many thanks, Ana
 

Attachments

Thread Starter

loesvan

Joined Sep 23, 2011
28
Just to be clear, by vibrate do you mean you notice a change in the light intensity that is coming out, the LED is flickering, or the strip is physically moving?
Hello,
Yes, the LEDs are flickering, but only when the level is low, there is a change in the light intensity.
Sorry my English is not very good and it's the first time here.
Thanks a lot
Ana
 

Attachments

Thread Starter

loesvan

Joined Sep 23, 2011
28
I have sent a video. I don't know if i did it right.
If the program is using pulse width modulation, PWM, can you increase the frequency?

Do not currently has access to a computer to see the code.
Hi,
I have already tried increasing the frequency and other hundreds of test but i can't get a solution. I have been trying for months and on this moment i am blocked i don't know what to do.
Please see attached video
Thanks
 

Attachments

Can you provide a schematic of the setup? What are you using for the LEDs? How are you communicating with the LEDs?

I have included the code in the message by using INSERT (+) then CODE (</>).


Code:
 __CONFIG    _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC  &    _LVP_OFF
list    P=16F628A
#INCLUDE <P16F628a.INC>

#DEFINE    OUT1    PORTB,1
#DEFINE    OUT2    PORTB,5
#DEFINE    OUT3    PORTB,4
#DEFINE    OUT4    PORTB,6
#DEFINE    OUT5    PORTB,3
#DEFINE    RX    PORTB,7




#DEFINE    BREAK    DMX_reg,0
#DEFINE    STARTCODE    DMX_reg,1
#DEFINE    MOVED    DMX_reg,2
#DEFINE    ADDR9    DMX_reg,3
#DEFINE    RC9    DMX_reg,4

DMX_reg EQU 020h

Reg1    EQU     021h
Reg2    EQU     022h
Reg3    EQU    023h
Reg4    EQU    024h
Reg5    EQU    025h

Count    EQU    030h
W_SAVE    EQU    031h
S_SAVE    EQU    032h
P_SAVE    EQU    033h
pwmcounter    EQU    034h
flag    EQU    02Ah
D_ADDR    EQU    02Bh
temp    EQU    02Ch
R_ADDR    EQU    02Dh
Offset    EQU    02Eh
temp2    EQU    02Fh

ORG 00h
GOTO INIT

ORG 04h
MOVWF    W_SAVE    ;save context,
MOVF    STATUS,W    ;save  STATUS, PCLATH & W
MOVWF    S_SAVE
MOVF   PCLATH,W
MOVWF  P_SAVE
GOTO   INTHANDLER
INIT

MOVLW    0x07    ;turn analog comparators off
MOVWF    CMCON
CLRF    PORTA
CLRF    PORTB

BSF    STATUS,RP0    ;Select Bank1
CLRF    TRISA    ;porta output
CLRF    TRISB    ;portb output
BSF    TRISB,1    ;B1 input (UART Recieve)

MOVLW    04h
MOVWF    SPBRG    ;Set baud rate
BSF    TXSTA,BRGH    ;high speed
BCF    TXSTA,SYNC    ;Async connection
CLRF    PIE1    ;clear other interrupts
BSF    PIE1,RCIE    ;Set recieve interrupt
BCF    STATUS,RP0    ;Return to bank0
BSF    RCSTA,RX9    ;Enable 9bit data

MOVF    RCREG,W    ;clear RCREG FIFO
MOVF    RCREG,W
MOVF    RCREG,W
BSF    RCSTA,CREN    ;Enable recieve
BSF    RCSTA,SPEN    ;Enable UART
BSF    INTCON,PEIE    ;Enable interrupts
BSF    INTCON,GIE

CLRF    Reg1
CLRF    Reg2
CLRF    Reg3
CLRF    Reg4
CLRF    Reg5

CLRF    D_ADDR    ;set our dmx adress to 0 (mogelijkheid voor dipswitch???)
BCF    ADDR9

GOTO MAIN

MAIN
BCF    RX
MOVLW    0FFh
MOVWF    pwmcounter
BCF    OUT1
BCF    OUT2
BCF    OUT3
BCF    OUT4
BCF    OUT5


CALL    PWM_CYCLE

GOTO    MAIN

PWM_CYCLE
MOVF    Reg1,W
XORWF    pwmcounter,W
BTFSC    STATUS,Z
BSF    OUT1

MOVF    Reg2,W
XORWF    pwmcounter,W
BTFSC    STATUS,Z
BSF    OUT2

MOVF    Reg3,W
XORWF    pwmcounter,W
BTFSC    STATUS,Z
BSF    OUT3

MOVF    Reg4,W
XORWF    pwmcounter,W
BTFSC    STATUS,Z
BSF    OUT4

MOVF    Reg5,W
XORWF    pwmcounter,W
BTFSC    STATUS,Z
BSF    OUT5

DECFSZ    pwmcounter
GOTO    PWM_CYCLE
RETURN

INTRETURN
MOVF    P_SAVE,W    ;restore context
MOVWF    PCLATH
MOVF    S_SAVE,W
MOVWF    STATUS
SWAPF    W_SAVE,F
SWAPF    W_SAVE,W
RETFIE

INTHANDLER
BTFSS    PIR1,RCIF
GOTO    INTRETURN
GOTO    DMX

DMX
BSF    PORTA,0

BTFSC    RCSTA,OERR
GOTO    OVERRUN

BTFSC     RCSTA,FERR
GOTO     FRAME

BTFSS     BREAK
GOTO     RET
BTFSS    STARTCODE    ;has a startcode passed ?
GOTO    SC    ;yes: go check for valid startcode
 
BTFSC    STARTCODE
GOTO    CHANNEL

RET
MOVF    RCREG,W
GOTO    INTRETURN

OVERRUN
BCF    RCSTA,SPEN
BSF    RCSTA,SPEN
MOVF    RCREG,W
GOTO    LAST

FRAME
BCF    BREAK
BCF    STARTCODE
BCF    RC9
CLRF    R_ADDR
CLRF    Offset
BTFSS    RCSTA,RX9D
BSF    BREAK
MOVF    RCREG,W
GOTO    INTRETURN

SC
MOVF    RCREG,W
XORLW    00h
BTFSC    STATUS,Z
BSF    STARTCODE
GOTO    INTRETURN

INCREASE
INCF    R_ADDR   
BTFSC    STATUS,Z
BSF    RC9
RETURN

CHANNEL

MOVF    Offset,W
XORLW    00h    ;check if offset != 0
BTFSS    STATUS,Z
GOTO    CHAN

MOVF    R_ADDR,W    ;else: check if chans match
XORWF    D_ADDR,W
BTFSC    STATUS,Z
GOTO    NINTH    ;if so: check for 9th bit

CALL    INCREASE
GOTO    RET

NINTH
BTFSC    ADDR9
GOTO    TRUE
MOVF    RCREG,W
GOTO    FALSE

TRUE
BTFSC    RC9
GOTO    CHAN
CALL    INCREASE
GOTO    RET

FALSE
BTFSS    RC9
GOTO    CHAN
CALL    INCREASE
GOTO    RET

CHAN
BSF    RX
INCF    Offset
MOVF    Offset,W
XORLW    01h    ;check if count = 0
BTFSC    STATUS,Z
GOTO    CHAN1

MOVF    Offset,W
XORLW    02h
BTFSC    STATUS,Z
GOTO    CHAN2

MOVF    Offset,W
XORLW    03h
BTFSC    STATUS,Z
GOTO    CHAN3

MOVF    Offset,W
XORLW    04h
BTFSC    STATUS,Z
GOTO    CHAN4

MOVF    Offset,W
XORLW    05h
BTFSC    STATUS,Z
GOTO    CHAN5


MOVF    Offset,W
XORLW    10h    ; was 05h
BTFSC    STATUS,Z
GOTO    LAST

CHAN1
MOVF    RCREG,W
MOVWF    Reg1
CALL    INCREASE
GOTO    INTRETURN

CHAN2
MOVF    RCREG,W
MOVWF    Reg2
CALL    INCREASE
GOTO    INTRETURN

CHAN3
MOVF    RCREG,W
MOVWF    Reg3
CALL    INCREASE
GOTO    INTRETURN

CHAN4
MOVF    RCREG,W
MOVWF    Reg4
CALL    INCREASE
GOTO    INTRETURN

CHAN5
MOVF    RCREG,W
MOVWF    Reg5
CALL    INCREASE
GOTO    INTRETURN



LAST

BCF    BREAK
BCF    STARTCODE
CLRF    Offset
GOTO    INTRETURN
END
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
I am sure that the problem is with the code. I have used different LEDs and all have the same problem. The communication with the LEDs is the normal four wires (common, red, green, blue) you can see on the video that i used a piece of normal led strip directly to the controller.
I send a diagram.

Ana
 

Attachments

Do you see the flicker when only a single color is used?

LED strips come in all varieties. The latest one I am using uses SPI to send individual 24 bit RGB information individually to each LED in the strip.
 

djsfantasi

Joined Apr 11, 2010
9,163
The TS has stated that the "vibrations" occur when the PWM signal is between 0-50... Is that 0-50 Hz? Then there is nothing you can do, because those low frequencies are in the range that the human brain can see. Even if it were not Hz, it could in the range of visible frequencies when driving LEDs. Personally, I would use some constant as my lower level limit, to avoid getting into the visible range.
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
The TS has stated that the "vibrations" occur when the PWM signal is between 0-50... Is that 0-50 Hz? Then there is nothing you can do, because those low frequencies are in the range that the human brain can see. Even if it were not Hz, it could in the range of visible frequencies when driving LEDs. Personally, I would use some constant as my lower level limit, to avoid getting into the visible range.
0 to 50 is the level of the potentiometer scale of the DMX table. The level is from 0 to 255. On 0, the LEDs are off and on 255 the LEDs are at maximum level. That is how you regulate the brightness of the LEDs. It has nothing to do with the PWM frequency.
Thanks
Ana
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
Do you see the flicker when only a single color is used?

LED strips come in all varieties. The latest one I am using uses SPI to send individual 24 bit RGB information individually to each LED in the strip.
It happens with all the LED strips and with the tree colors. The problem is with the ASM code.
Ana
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
I have been doing some test and i found out that the flickering problem is produced by the interrupts. I inserted a loop in the ASM code just after the label "Main" so that one of the outputs will light the LEDs very dim, without having anything to do with DMX and the LEDs still flickers. If i disconnect the interrupts (INTCON,GIE) the LEDs Stops flickering.
Can someone please help me.
Thanks Ana

This is the loop i inserted for testing:
Main
MOVF 1,W
XORWF 255,W
BTFSC STATUS,Z
BSF OUT2
BCF OUT2
GOTO Main
 

MMcLaren

Joined Feb 14, 2010
861
The Microchip "Using a PIC Microcontroller for DMX512 Communication" application note (mentioned on the Spanish Forum that you mentioned in your other thread) was very helpful.

After reading the application note and studying the program, I don't think the program will make a good DMX512 Receiver. Basically, the software PWM loop, which needs about ~5900 cycles to complete, is getting interrupted every 200 or so instruction cycles when receiving a 512-byte 250-kilobaud DMX data frame. This is causing the flickering you see at low duty cycle values. Unfortunately, there is no "easy fix" for this program with this hardware (PIC16F628A).

Cheerful regards, Mike
 
Last edited:
How often does the device connected to the MAX485 chip send messages?

Do you have proper terminations on the RS485 channel? Look at the MAX485 datasheet, I am not very familiar with that.
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
The Microchip "Using a PIC Microcontroller for DMX512 Communication" application note (mentioned on the Spanish Forum that you mentioned in your other thread) was very helpful.

After reading the application note and studying the program, I don't think the program will make a good DMX512 Receiver. Basically, the software PWM loop, which needs about ~5900 cycles to complete, is getting interrupted every 200 or so instruction cycles when receiving a 512-byte 250-kilobaud DMX data frame. This is causing the flickering you see at low duty cycle values. Unfortunately, there is no "easy fix" for this program with this hardware (PIC16F628A).

Cheerful regards, Mike
Hello Mike, Do you mean that it's not possible to eliminate the flickering with this PIC and this code? Do you know ware i can get a DMX ASM working code? All the codes i tried apart from this one dosen't work.
Ana
 

Thread Starter

loesvan

Joined Sep 23, 2011
28
How often does the device connected to the MAX485 chip send messages?

Do you have proper terminations on the RS485 channel? Look at the MAX485 datasheet, I am not very familiar with that.
I don't understand what you mean with proper terminations. You can see the connections on the diagram. The problem is with the DMX software.
Thanks a lot Ana
 

Damian S.

Joined Jun 5, 2017
4
Hi Ana,

if the interrupts cause this flickering as Mike elaborated above, there is not much you can do about it with this microcontroller. If you want somthing simple I'd recommend using WS2812 LED strips. They have a one wire protocol and generate their own PWM signal, you just have to feed them the data (24bit RGB). There is a good C library that makes use of ASM code for the proper timing. I used it in some of my projects already, works great on an ARM M0 and the author tested it on Atmel MCUs and Arduino. It may also work on a PIC but I am not familiar with those. The code is here: https://github.com/cpldcpu/light_ws2812
 
Top