Professional Documents
Culture Documents
DMX protocol
Goto page 1, 2 Next
Author Message
Dave
You want to receive or transmit? Which PIC are you using? What speed are you running? How
Joined: 07 Sep 2003
Posts: 3511 many dimmers do you need to respond to?
Location: Atlanta, GA
PS: Do you work for a lighting control company? Is so, which one? I work for Lithonia Lighting.
Thanks Mark
Joined: 07 Oct 2003
Posts: 76 I do not work for a lighting company just my own personal interest.
Location: England I designed the dimmer using a 12f629 using the internal clock. it has a 0-10v control input. I
wish now to convert it to dim by means of the DMX512 protocol so it will - recieve only. I
understand that I will have to go to a chip with more code space and resources to implement
this. I basically need detailed timing, packet information etc. Any code would be well recieved to
help me on my way!
Thanks again.
Dave
Best wishes
1 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
Humberto
I will post a couple of snippets when I get a chance. But basically I read the spec and wrote the
Joined: 07 Sep 2003
Posts: 3511 software from it.
Location: Atlanta, GA
Here is the receive routine. It has been a while since I wrote this, but it seems there was a break
Joined: 07 Sep 2003
Posts: 3511 or mark signal at the start of the DMX stream. I use the framing error to check for this. I
Location: Atlanta, GA removed all (I think) of the code that would not benefit you.
Code:
void Interrupt_USART_Rx(void)
{
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define WAIT_FOR_DATA 3
#define RECEIVE_DATA 4
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
2 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
/* Check for a framing error */
if (rcsta.bits.FERR)
{
/* If we did receive a framing error, make sure that the data is 0.
This means that we did Rx the break signal for at least 44us. */
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
/* Check for a framing error. If we receive one then we need to wait
until we receive a good data byte before we begin looking for our
Break signal */
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
/* The start code for our data packet should always start with 0. */
else
{
if (!data)
{
/* Initialize our index to our Rx buffer. */
Rx_Index = 0;
3 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
}
break;
// default:
/* Unknown start code */
}
}
return;
}
i.d.teece@hull.ac.uk
I used the USITT DMX512/1990 AMX192 standard. I only have a printed copy. I did a quick
Joined: 07 Sep 2003
Posts: 3511 check on the web and could find it in pdf form anywhere. It looks like they want you to buy it.
Location: Atlanta, GA Not sure how I got it. One of our marketing managers handed it to me several years back when
we decided that we needed a DMX interface into our system.
The question I then have is how can you generate a break and a mark-after-break when using
the usart? The only thing I can think of is to grab control of the C6 pin, make it an output, and
write to it directly then make it a usart output again, but this seams ineffecient, there must be a
better way.
jmann wrote:
Here is a good link with the most important details of DMX:
http://www.euro-pa.be/dmx.html
The question I then have is how can you generate a break and a mark-after-break when
using the usart? The only thing I can think of is to grab control of the C6 pin, make it an
output, and write to it directly then make it a usart output again, but this seams ineffecient,
there must be a better way.
Directly controlling the output bit is quite normal, and not 'inefficient'. The alternative, is to
reprogram the UART baud rate to a much slower value, and send a '0' byte. The downside to
this, is that if any data is received while doing this, it will be garbaged. CCS supports a
command to change the baud rate 'on the fly', so this approach is very simple in code terms,
and does not require any waits.
Best Wishes
4 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
High intensity levels it is not a problem, I thing is for the logarithim response of eye.
How anyone found this problem? How I can solve that?
The first Idea is implement the resolution but it is not easy becasue dmx send 8 bits.
For more details Here is my code:
Code:
/************************************************************************
* FUSES *
* NOPROTECT=Code not protected from reading *
* CCP2C1=CCP2 input/output multiplexed with RC1 *
* NODEBUG=No Debug mode for ICD *
* BORV20=Brownout reset at 2.0V *
* MCLR=Master Clear pin enabled *
* Habilitamos el pin de clear *
* NOWDT=No Watch Dog Timer *
* INTRC_IO=Internal RC Osc, no CLKOUT *
* NOIESO=Internal External Switch Over mode disabled *
* NOFCMEN=Fail-safe clock monitor disabled *
* Desabilitamos la opcion de deteccion de que cuando hay una perdida *
* de clock externo el clock interno proporciona los clock al sistema*
* NOBROWNOUT=Reset when brownout detected *
************************************************************************/
#fuses NOPROTECT,CCP2C1,NODEBUG,MCLR,NOWDT,INTRC_IO,NOBROWNOUT
#include <16F767.h>
#use delay(clock=4000000) //Indicamos al compilador que los retardos los calcule
//en funcion de una base de tiempos con un clock de 4Mhz
#include <string.h>
#include <stdio.h>
/************************************************************************
* Puertos I/O *
************************************************************************/
struct PA_pin_map {
boolean unusedRA0; //bit 0
boolean unusedRA1;
boolean unusedRA2;
boolean unusedRA3;
boolean unusedRA4;
boolean unusedRA5; //bit 4
} Puerto_A;
#byte Puerto_A = 5
struct PB_pin_map {
boolean unusedRB0; //bit 0
boolean unusedRB1;
boolean unusedRB2;
boolean unusedRB3;
boolean unusedRB4;
boolean unusedRB5;
boolean unusedRB6;
boolean unusedRB7; //bit8
} Puerto_B;
#byte Puerto_B = 6
struct PC_pin_map {
boolean unusedRC0; //bit 0
boolean unusedRC1;
boolean unusedRC2;
boolean unusedRC3;
boolean unusedRC4;
boolean test_osc;
boolean unusedRC6;
boolean rx; //bit8
} Puerto_C;
#byte Puerto_C = 7
#CASE
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
/************************************************************************
* Registros USART *
************************************************************************/
5 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
/************************************************************************
* Variables globales *
************************************************************************/
int1 Check_levels=0;
/************************************************************************
* Declaracion de funciones *
************************************************************************/
void Interrupt_USART_Rx(void);
/************************************************************************
* Rutina de atencion a la interrupcion *
************************************************************************/
#int_rda
void Interrupt_USART_Rx(void)
{
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define RECEIVE_DATA 3
/*Definimos una union que es como una struct pero con la diferencia de
que sus componentes se almacenan en la misma posicion de memoria.
Esto significa que el byte rcsta.byte esta formado por 8 bits los cuales
hemos definido idénticos a los bits del registro de estado de la usart: RCSTA */
union
{
unsigned char byte;
struct {
unsigned char RX9D:1; //bit0
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1; //bit7
} bits ;
}rcsta;
while (RCIF) //Nos quedamos leyendo el dato tanto tiempo como este presente
{
/*Leemos el registro de estado de la usart y se lo asignamos
al byte rcsta.byte. Leemos el dato */
rcsta.byte = RCSTA;
data = RCREG;
6 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
if (rcsta.bits.FERR) //Miramos si hay un error de trama
{
/*Si recibimos un error de trama, hay que asegurarse que el dato es 0.
Esto significa que hemos recibido una señal de break de como mínimo 44us.
Hay que acordarse que trabajamos a 250Kbits lo cual implica un tbit de 4us
SI enviamos 11 bits( start+8bit datos+2stop)esto son 44us*/
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
/*Comprobamos si hay error en la trama. Si recibimos un error
tenemos que esperar a recibir un byte correcto antes de que
empezemos a buscar nuestra señal de break */
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
/* El byte de start de nuestro paquete siempre empieza por 0. */
else
{
if (!data)
{
/*Inicializamos nuestro índice a nuestro buffer de recepcion */
ptr_Rx = Rx_Buffer;
/*En este punto debermos determinar donde de la trama DMX queremos empezar
a recibir datos basandonos en una direccion de offset. Este primer programa
solo contempla recoger los tres primeros canales*/
Rx_State = RECEIVE_DATA;
}
}
break;
case RECEIVE_DATA:
/*Comprobamos si hay error de trama. Si nosotros recivimos un error de trama
esto puede ser el inicio de un nuevo paquete o un verdadero error de trama */
if (rcsta.bits.FERR)
{
/* Si es el inicio de un nuevo paquete el dato debe ser 0 sino es un error
en la trama */
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
/* ALmacenamos el dato recibido en el buffer de recepcion */
*ptr_Rx=data;
ptr_Rx++;
/*Comprobamos si hemos recibido todos nuestros datos */
if(ptr_Rx > &Rx_Buffer[MAX_PWMS-1] )
{
/* Hemos recibido todos los datos*/
Check_levels=1;
Rx_State= WAIT_FOR_BREAK;
}
}
break;
}
}
return;
}
/************************************************************************
* Programa Principal *
7 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
************************************************************************/
int8 i;
/////////////////////////////////////////
while (1)
{
/*Despues de cada paquete, el receptor actualiza este flag para
permitirnos detectar un cambio.*/
if (Check_levels)
{
Check_levels=0;
DMX_Levels[0]=Rx_Buffer[0];
DMX_Levels[1]=Rx_Buffer[1];
DMX_Levels[2]=Rx_Buffer[2];
set_pwm1_duty(DMX_Levels[0]); //CANAL 1 ->CCP1 (PIN 13) RC2
set_pwm2_duty(DMX_Levels[1]); //CANAL 2 ->CCP2 (PIN 12) RC1
set_pwm3_duty(DMX_Levels[2]); //CANAL 3 ->CCP3 (PIN 26) RC3
8 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
thanks!!
Last edited by marquez on Wed Mar 30, 2005 1:36 am; edited 1 time in total
Code:
/************************************************************************
* FUSES *
* NOPROTECT=Code not protected from reading *
* CCP2C1=CCP2 input/output multiplexed with RC1 *
* NODEBUG=No Debug mode for ICD *
* BORV20=Brownout reset at 2.0V *
* MCLR=Master Clear pin enabled *
* Habilitamos el pin de clear *
* NOWDT=No Watch Dog Timer *
* INTRC_IO=Internal RC Osc, no CLKOUT *
* NOIESO=Internal External Switch Over mode disabled *
* NOFCMEN=Fail-safe clock monitor disabled *
* Desabilitamos la opcion de deteccion de que cuando hay una perdida *
* de clock externo el clock interno proporciona los clock al sistema*
* NOBROWNOUT=Reset when brownout detected *
************************************************************************/
#fuses NOPROTECT,CCP2C1,NODEBUG,MCLR,NOWDT,INTRC_IO,NOBROWNOUT
#include <16F767.h>
#use delay(clock=4000000) //Indicamos al compilador que los retardos los calcule
//en funcion de una base de tiempos con un clock de 4Mhz
#include <string.h>
#include <stdio.h>
/************************************************************************
* Puertos I/O *
************************************************************************/
struct PA_pin_map {
boolean unusedRA0; //bit 0
boolean unusedRA1;
boolean unusedRA2;
boolean unusedRA3;
boolean unusedRA4;
boolean unusedRA5; //bit 4
} Puerto_A;
#byte Puerto_A = 5
struct PB_pin_map {
boolean unusedRB0; //bit 0
boolean unusedRB1;
boolean unusedRB2;
boolean unusedRB3;
boolean unusedRB4;
boolean unusedRB5;
boolean unusedRB6;
boolean unusedRB7; //bit8
} Puerto_B;
#byte Puerto_B = 6
struct PC_pin_map {
boolean unusedRC0; //bit 0
boolean unusedRC1;
boolean unusedRC2;
boolean unusedRC3;
boolean unusedRC4;
boolean test_osc;
boolean unusedRC6;
boolean rx; //bit8
} Puerto_C;
#byte Puerto_C = 7
9 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
#CASE
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
/************************************************************************
* Registros USART *
************************************************************************/
/************************************************************************
* Variables globales *
************************************************************************/
int1 Check_levels=0;
/************************************************************************
* Declaracion de funciones *
************************************************************************/
void Interrupt_USART_Rx(void);
/************************************************************************
* Rutina de atencion a la interrupcion *
************************************************************************/
#int_rda
void Interrupt_USART_Rx(void)
{
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define RECEIVE_DATA 3
/*Definimos una union que es como una struct pero con la diferencia de
que sus componentes se almacenan en la misma posicion de memoria.
Esto significa que el byte rcsta.byte esta formado por 8 bits los cuales
hemos definido idénticos a los bits del registro de estado de la usart: RCSTA */
union
{
unsigned char byte;
struct {
unsigned char RX9D:1; //bit0
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
10 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
while (RCIF) //Nos quedamos leyendo el dato tanto tiempo como este presente
{
/*Leemos el registro de estado de la usart y se lo asignamos
al byte rcsta.byte. Leemos el dato */
rcsta.byte = RCSTA;
data = RCREG;
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
if (rcsta.bits.FERR) //Miramos si hay un error de trama
{
/*Si recibimos un error de trama, hay que asegurarse que el dato es 0.
Esto significa que hemos recibido una señal de break de como mínimo 44us.
Hay que acordarse que trabajamos a 250Kbits lo cual implica un tbit de 4us
SI enviamos 11 bits( start+8bit datos+2stop)esto son 44us*/
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
/*Comprobamos si hay error en la trama. Si recibimos un error
tenemos que esperar a recibir un byte correcto antes de que
empezemos a buscar nuestra señal de break */
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
/* El byte de start de nuestro paquete siempre empieza por 0. */
else
{
if (!data)
{
/*Inicializamos nuestro índice a nuestro buffer de recepcion */
ptr_Rx = Rx_Buffer;
/*En este punto debermos determinar donde de la trama DMX queremos empezar
a recibir datos basandonos en una direccion de offset. Este primer programa
solo contempla recoger los tres primeros canales*/
Rx_State = RECEIVE_DATA;
}
}
break;
case RECEIVE_DATA:
/*Comprobamos si hay error de trama. Si nosotros recivimos un error de trama
esto puede ser el inicio de un nuevo paquete o un verdadero error de trama */
if (rcsta.bits.FERR)
{
/* Si es el inicio de un nuevo paquete el dato debe ser 0 sino es un error
en la trama */
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
/* ALmacenamos el dato recibido en el buffer de recepcion */
*ptr_Rx=data;
ptr_Rx++;
/*Comprobamos si hemos recibido todos nuestros datos */
11 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
}
break;
}
}
return;
}
/************************************************************************
* Programa Principal *
************************************************************************/
int8 i;
/////////////////////////////////////////
while (1)
{
/*Despues de cada paquete, el receptor actualiza este flag para
permitirnos detectar un cambio.*/
if (Check_levels)
{
12 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
Check_levels=0;
DMX_Levels[0]=Rx_Buffer[0];
DMX_Levels[1]=Rx_Buffer[1];
DMX_Levels[2]=Rx_Buffer[2];
set_pwm1_duty(DMX_Levels[0]); //CANAL 1 ->CCP1 (PIN 13) RC2
set_pwm2_duty(DMX_Levels[1]); //CANAL 2 ->CCP2 (PIN 12) RC1
set_pwm3_duty(DMX_Levels[2]); //CANAL 3 ->CCP3 (PIN 26) RC3
thanks!!
Code:
/************************************************************************
* FUSES *
* NOPROTECT=Code not protected from reading *
* CCP2C1=CCP2 input/output multiplexed with RC1 *
* NODEBUG=No Debug mode for ICD *
* BORV20=Brownout reset at 2.0V *
* MCLR=Master Clear pin enabled *
* Habilitamos el pin de clear *
* NOWDT=No Watch Dog Timer *
* INTRC_IO=Internal RC Osc, no CLKOUT *
* NOIESO=Internal External Switch Over mode disabled *
* NOFCMEN=Fail-safe clock monitor disabled *
* Desabilitamos la opcion de deteccion de que cuando hay una perdida *
* de clock externo el clock interno proporciona los clock al sistema*
* NOBROWNOUT=Reset when brownout detected *
************************************************************************/
#fuses NOPROTECT,CCP2C1,NODEBUG,MCLR,NOWDT,INTRC_IO,NOBROWNOUT
#include <16F767.h>
#use delay(clock=4000000) //Indicamos al compilador que los retardos los calcule
//en funcion de una base de tiempos con un clock de 4Mhz
#include <string.h>
#include <stdio.h>
/************************************************************************
* Puertos I/O *
************************************************************************/
struct PA_pin_map {
boolean unusedRA0; //bit 0
boolean unusedRA1;
boolean unusedRA2;
boolean unusedRA3;
boolean unusedRA4;
boolean unusedRA5; //bit 4
} Puerto_A;
#byte Puerto_A = 5
struct PB_pin_map {
boolean unusedRB0; //bit 0
boolean unusedRB1;
boolean unusedRB2;
boolean unusedRB3;
boolean unusedRB4;
boolean unusedRB5;
boolean unusedRB6;
boolean unusedRB7; //bit8
13 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
} Puerto_B;
#byte Puerto_B = 6
struct PC_pin_map {
boolean unusedRC0; //bit 0
boolean unusedRC1;
boolean unusedRC2;
boolean unusedRC3;
boolean unusedRC4;
boolean test_osc;
boolean unusedRC6;
boolean rx; //bit8
} Puerto_C;
#byte Puerto_C = 7
#CASE
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
/************************************************************************
* Registros USART *
************************************************************************/
/************************************************************************
* Variables globales *
************************************************************************/
int1 Check_levels=0;
/************************************************************************
* Declaracion de funciones *
************************************************************************/
void Interrupt_USART_Rx(void);
/************************************************************************
* Rutina de atencion a la interrupcion *
************************************************************************/
#int_rda
void Interrupt_USART_Rx(void)
{
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define RECEIVE_DATA 3
14 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
/*Definimos una union que es como una struct pero con la diferencia de
que sus componentes se almacenan en la misma posicion de memoria.
Esto significa que el byte rcsta.byte esta formado por 8 bits los cuales
hemos definido idénticos a los bits del registro de estado de la usart: RCSTA */
union
{
unsigned char byte;
struct {
unsigned char RX9D:1; //bit0
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1; //bit7
} bits ;
}rcsta;
while (RCIF) //Nos quedamos leyendo el dato tanto tiempo como este presente
{
/*Leemos el registro de estado de la usart y se lo asignamos
al byte rcsta.byte. Leemos el dato */
rcsta.byte = RCSTA;
data = RCREG;
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
if (rcsta.bits.FERR) //Miramos si hay un error de trama
{
/*Si recibimos un error de trama, hay que asegurarse que el dato es 0.
Esto significa que hemos recibido una señal de break de como mínimo 44us.
Hay que acordarse que trabajamos a 250Kbits lo cual implica un tbit de 4us
SI enviamos 11 bits( start+8bit datos+2stop)esto son 44us*/
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
/*Comprobamos si hay error en la trama. Si recibimos un error
tenemos que esperar a recibir un byte correcto antes de que
empezemos a buscar nuestra señal de break */
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
/* El byte de start de nuestro paquete siempre empieza por 0. */
else
{
if (!data)
{
/*Inicializamos nuestro índice a nuestro buffer de recepcion */
ptr_Rx = Rx_Buffer;
/*En este punto debermos determinar donde de la trama DMX queremos empezar
a recibir datos basandonos en una direccion de offset. Este primer programa
solo contempla recoger los tres primeros canales*/
Rx_State = RECEIVE_DATA;
}
}
break;
case RECEIVE_DATA:
/*Comprobamos si hay error de trama. Si nosotros recivimos un error de trama
esto puede ser el inicio de un nuevo paquete o un verdadero error de trama */
15 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
if (rcsta.bits.FERR)
{
/* Si es el inicio de un nuevo paquete el dato debe ser 0 sino es un error
en la trama */
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
/* ALmacenamos el dato recibido en el buffer de recepcion */
*ptr_Rx=data;
ptr_Rx++;
/*Comprobamos si hemos recibido todos nuestros datos */
if(ptr_Rx > &Rx_Buffer[MAX_PWMS-1] )
{
/* Hemos recibido todos los datos*/
Check_levels=1;
Rx_State= WAIT_FOR_BREAK;
}
}
break;
}
}
return;
}
/************************************************************************
* Programa Principal *
************************************************************************/
int8 i;
/////////////////////////////////////////
16 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
set_pwm3_duty(127);
delay_ms(1000);
/////////////////////////////////////////
while (1)
{
/*Despues de cada paquete, el receptor actualiza este flag para
permitirnos detectar un cambio.*/
if (Check_levels)
{
Check_levels=0;
DMX_Levels[0]=Rx_Buffer[0];
DMX_Levels[1]=Rx_Buffer[1];
DMX_Levels[2]=Rx_Buffer[2];
set_pwm1_duty(DMX_Levels[0]); //CANAL 1 ->CCP1 (PIN 13) RC2
set_pwm2_duty(DMX_Levels[1]); //CANAL 2 ->CCP2 (PIN 12) RC1
set_pwm3_duty(DMX_Levels[2]); //CANAL 3 ->CCP3 (PIN 26) RC3
thanks!!
Don't use the actual DMX value. Instead, have a lookup table of 256 entries (0-255). This will
Joined: 07 Sep 2003
Posts: 3511 allow you to adjust the curve. The PWM is a 10 bit value, you can use all ten bits but that alone
Location: Atlanta, GA won't get you the smoothest response. Instead, allow your value to reach the desired value over
a given amount of time. What I mean is say your curve is like
Code:
curve[256] = {0,4,8,12,16,20,...}
you can still use the values in between
Code:
current_value = curve[0];
new_value = curve[3];
............
while(1)
{
delaysometime();
if (new_value < current_value)
{
current_value--;
set_pwm(current_value);
}
else if (new_value > current_value)
{
current_value++;
set_pwm(current_value);
}
}
Note the above code isn't complete or really even code but will give you some idea of what the
heck I am talking about. BTW, I work for a lighting company and this is how I handle dimming.
If you are intending to make a product and sell it, be sure to check out the patents regarding
pwm's controlling LEDs.
17 от 18 01.3.2007 г. 11:03
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&highlight=inte...
frequency modulation) . The reasons are, that LEds don´t have linear response and PWM are a
linear modulation. PFM is not linear and for this reason can be better.
Someone know how to make a PFM (manteining pulse with and change frequency)?
thanks!
18 от 18 01.3.2007 г. 11:03