Vous êtes sur la page 1sur 6

CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

FAQ Forum Help Official CCS Support Search Register

Profile Log in to check your private messages Log in

DMX protocol
Goto page Previous 1, 2

CCS Forum Index -> General CCS C Discussion

View previous topic :: View next topic

Author Message

Mark Posted: Wed Mar 30, 2005 7:36 am

Just use a curve, it will be easier.


Joined: 07 Sep 2003
Posts: 3511
Location: Atlanta, GA But to do what you want, use the CCP module and generate an interrupt of match. You will
have 2 CCP values. The "ON" value which is your pulse and the "OFF" value which will control
the frequency. Keeping the ON time the same and vary the OFF time will change the frequency. I
would also throw away that 4MHz osc and run at 20MHz.

marquez select channel in dmx


Posted: Thu Apr 14, 2005 8:14 am

Joined: 05 Jan 2005 Hi everybody,


Posts: 2
Location: spain I just Implement a dmx receiver that works fine for the 3 first channels, but when I would like to
choose one channel I have problems.
Can anyone help me? I based my code In Mark code (thanks again mark)

Here is the actual 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 *
************************************************************************/

#include <16F767.h>
#fuses NOPROTECT,CCP2C1,NODEBUG,MCLR,NOWDT,HS,NOBROWNOUT
//#use delay(clock=4000000) #use delay(clock=16000000)
#include <string.h>
#include <stdio.h>
/************************************************************************
* Puertos I/O *
************************************************************************/

struct PA_pin_map {
boolean unusedRA0; //bit 0

1 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

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; //canal pwm
boolean unusedRB6;
boolean unusedRB7; //bit8
} Puerto_B;
#byte Puerto_B = 6

struct PC_pin_map {
boolean unusedRC0; //bit 0
boolean unusedRC1; //canal pwm
boolean PWM1; //canal pwm
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 *
************************************************************************/

#byte SPBRG = 0x99


#byte RCSTA = 0x18 //Registro de recepcion de la usart
#byte TXSTA = 0x98
#byte RCREG = 0x1a
#byte PIR1 = 0x0c
#byte PIE1 = 0x8c
#byte INTCON = 0x0b

#bit SPEN = RCSTA.7 //Serial port enable bit


#bit RX9 = RCSTA.6 // 9-bit receive enable
#bit SREN = RCSTA.5 //En modo asyncrono no se tiene en cuenta
#bit CREN = RCSTA.4 // Continuos receive enable bit
#bit ADDEN = RCSTA.3
#bit FERR = RCSTA.2 //Frame error bit
#bit OERR = RCSTA.1 //Overrun error bit
#bit RX9D = RCSTA.0 //El noveno bit

#bit BRGH = TXSTA.2


#bit SYNC = TXSTA.4

#bit RCIF = PIR1.5


#bit RCIE = PIE1.5
#bit GIE = INTCON.7
#bit PEIE = INTCON.6

/************************************************************************
* Variables globales *
************************************************************************/

#define MAX_PWMS 32 //Queremos almacenar 3 valores (RGB)

unsigned int DMX_512_Offset = 5;

/*Rx Buffer for dmx stream */


int8 Rx_Buffer[MAX_PWMS];

/*Current levels -0 to 255 */


int8 DMX_Levels[MAX_PWMS];

int1 Check_levels=0;

2 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

/************************************************************************
* Declaracion de funciones *
************************************************************************/

void Interrupt_USART_Rx(void);

int16 calcul_duty1(int8 level1, int16 current_value1);


int16 calcul_duty2(int8 level2, int16 current_value2);
int16 calcul_duty3(int8 level3, int16 current_value3);
/************************************************************************
* 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_INT 3
#define RECEIVE_DATA 4

/* Maquina de estados para determinar el inicio de la trama dmx*/


static int8 Rx_State = WAIT_FOR_BREAK;

int8 data; //El dato que estamos recibiendo

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;

/* ÍNDICE AL BUFFER DE RECEPCION */


static int8 *ptr_Rx; //de 1 a 64

static unsigned int DMX_512_Count = 0;

while (RCIF) {

rcsta.byte = RCSTA;
data = RCREG;

if (rcsta.bits.OERR) //Miramos si hay un buffer overrun


{
//Si hay Overrun entonces hay que resetear la lógica de recepcion
CREN = 0;
CREN = 1;
Rx_State = WAIT_FOR_NEXT_BYTE;
return;
}

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
{
if (!data)
Rx_State = WAIT_FOR_START;
}
break;

case WAIT_FOR_START:
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;

3 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

else
{
if (!data)
{
if(DMX_512_Offset==1)
{
ptr_Rx=Rx_Buffer;
Rx_State = RECEIVE_DATA;
}
else
{
Rx_State = RECEIVE_DATA_INT;
DMX_512_Count=1;
}
}
}
break;

case RECEIVE_DATA_INT:
if (rcsta.bits.FERR)
{
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
DMX_512_Count++;
if( DMX_512_Count == DMX_512_Offset)
{
ptr_Rx=Rx_Buffer;
Rx_State = RECEIVE_DATA;
}

}
break;

case RECEIVE_DATA:
if (rcsta.bits.FERR)
{
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
*ptr_Rx=data;
ptr_Rx++;
if( ptr_Rx > &Rx_Buffer[MAX_PWMS-1] )
{
Rx_State= WAIT_FOR_BREAK;
Check_levels=1;
}

}
break;

}
}
return;
}

/************************************************************************
* Programa Principal *
************************************************************************/

void main (void) {

int8 i;
int1 exit; //var used para salir de bucles
//////////////////Configuramos los puertos ////////////////////////
set_tris_a(0x00);
set_tris_b(0x00);
set_tris_c(0b10000000);

//setup_oscillator(OSC_INTRC|OSC_4MHZ); //pone el oscilador interno a 4Mhz

//un 1 es como entrada y 0 como salida


/////////////////////////////////////////
/*
SPBRG=0x00; // SPBRG=0 implica que a 4Mhz el baudrate=250.000
BRGH=1; // BRGH=1 implica High speed para 4Mhz
SYNC=0; // enable aSYNChronous reception

4 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

SPEN=1; // serial port enabled - rc7/rx/dt , rc6/tx/ck pins as serial port pins
*/
SPBRG=0x00; // SPBRG=0 implica que a 16Mhz el baudrate=250.000
BRGH=0; // BRGH=0 implica Low speed.
SYNC=0; // enable aSYNChronous reception
SPEN=1; // serial port enabled - rc7/rx/dt , rc6/tx/ck pins as serial port pins

/////////////////////////////////////////

RX9=1; // 9 bit reception


CREN=1; // enable reception
ADDEN=0;
FERR=1;
OERR=1;
/////////////////////////////////////////
delay_ms(3000);
///////////////////////////////////////////////////////////////////
//// Configuramos los tres PWM ////
///////////////////////////////////////////////////////////////////

setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,255,1); //1khz a 16Mhz

//// Inicializamos los tres pwm ////


//PONEMOS LA ANCHURA DE PULSO A LA MITAD
set_pwm1_duty(127);
set_pwm2_duty(127);
set_pwm3_duty(127);
delay_ms(1000);
/////////////////////////////////////////

GIE=1; // enable all interrupts


PEIE=1; // enable peripheral interrupts
RCIE=1; // enable receive interrupt

current_value1=valorpwm1[0] ;
current_value2=valorpwm1[0] ;
current_value3=valorpwm1[0] ;//Inicializamos con un valor de duty de 0 -> leds off
exit=0;
while (1)
{
if (Check_levels)
{
Check_levels=0;
level1=Rx_Buffer[DMX_512_Offset-1];
level2=Rx_Buffer[DMX_512_Offset];
level3=Rx_Buffer[DMX_512_Offset];

calcul_duty1(level1,current_value1);
calcul_duty2(level2,current_value2);
calcul_duty3(level3,current_value3);

} //cierra check levels


current_value1=new_value1;
current_value2=new_value2;
current_value3=new_value3;
}//cierra while(1)

}//cierra main

thanks!

Mark Posted: Thu Apr 14, 2005 3:02 pm

What's the problem? What are you trying to do? It doesn't appear that you posted all the code.
Joined: 07 Sep 2003
Posts: 3511 But none of this looks right
Location: Atlanta, GA Code:

current_value1=valorpwm1[0] ;
current_value2=valorpwm1[0] ;
current_value3=valorpwm1[0] ;//Inicializamos con un valor de duty de 0 -> leds off

Show all the current values be initialized to valorpwm1[0]?

Code:

5 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...

exit=0;
while (1)
{
if (Check_levels)
{
Check_levels=0;
level1=Rx_Buffer[DMX_512_Offset-1];
level2=Rx_Buffer[DMX_512_Offset];
level3=Rx_Buffer[DMX_512_Offset];

What this about? DMX_512_Offset is the DMX channel to start with. With a value of 5, you will
not receive channels 1-4. So Rx_Buffer[0] will contain channel 5's level. Your code sets level1 =
channel 9 and level2 and level3 = channel 10? I don't think this is what you want.

Code:

calcul_duty1(level1,current_value1);
calcul_duty2(level2,current_value2);
calcul_duty3(level3,current_value3);

} //cierra check levels


current_value1=new_value1;
current_value2=new_value2;
current_value3=new_value3;
}//cierra while(1)

}//cierra main

Don't know what this is for nor to I have the code for it.

Guest dmx decoder


Posted: Mon Mar 13, 2006 11:59 pm

there r a dmx decoder:dm118

http://www.freeweb.com.tw/sd/upload/product/File/Product/DM118X%20_SD.pdf

http://www.skylinedynamics.com/

Display posts from previous: All Posts Oldest First Go

All times are GMT - 6 Hours


CCS Forum Index -> General CCS C Discussion
Goto page Previous 1, 2
Page 2 of 2

Jump to: General CCS C Discussion Go

You can post new topics in this forum


You can 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

6 от 6 01.3.2007 г. 11:05

Vous aimerez peut-être aussi