dmx receiver

General discussion on mikroC.
Post Reply
Author
Message
pfiff
Posts: 11
Joined: 04 Jul 2006 11:32

dmx receiver

#1 Post by pfiff » 06 Jul 2006 11:26

Hi people,
i have an dmx receiver which works not correctly.
The data which i get from the receiver i want put out on a lcd.
the first 3 Bytes are exactly, but the 4th Byte and the following Bytes aren't on the channels which i send from an extern Dmx Transmitter.

This is my code:

Code: Select all

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include "math.h"
#include "stdlib.h"
#include "string.h"

void waitBreakEnd(void);
#pragma interrupt_handler dmx_receiver_ISR 

//#define FRAMING_ERROR 0x20    // Flag to check for parity error

int dmxcount;
BYTE master;
BYTE bRxData;
BYTE bRxData1;
BYTE bRxData2;
BYTE ch0, ch1, ch2, ch3, ch4, ch5, ch6;

void channels (WORD Data)
{
	if(dmxcount == 0)		//look for start code
	{
		if(Data == 0x00)	
		{
			ch0 = Data;
			dmxcount++;
			return;
		}
	}
	else if(dmxcount == 1)		//channel 1 (master)
	{
		ch1 = Data;
		dmxcount++;
		master = Data;
	}
	else if(dmxcount == 2)		// red
	{
		ch2 = Data;
		dmxcount++;
		pwmred_WritePulseWidth(Data * master);
	}
	else if(dmxcount == 3)		// green
	{
		ch3 = Data;
		dmxcount++;
		pwmgreen_WritePulseWidth(Data * master);
	}
	else if(dmxcount == 4)		// blue
	{
		ch4 = Data;
		dmxcount++;
		pwmblue_WritePulseWidth(Data * master);
	}
	
	else if(dmxcount == 5)		// orange
	{
		ch5 = Data;
		dmxcount++;
		pwmorange_WritePulseWidth(Data * master);
	}
	else if(dmxcount == 6)		// white
	{
		ch6 = Data;
		dmxcount++;
		pwmwhite_WritePulseWidth(Data * master);
	}

	//--------- hier kommt dann strobe
}

void waitBreakEnd(void)
{
	while(!(PRT0DR & 0x40)){}
}

void dmx_receiver_ISR (void)
{
	static BYTE bRxStatus = 0;
	static WORD bRxData = 0;
	bRxStatus = dmx_receiver_bReadRxStatus();	//read receiver status
	
	if(bRxStatus & dmx_receiver_RX_FRAMING_ERROR)	//check for start of dmx packet
	{
		dmxcount = 0; 
		dmx_receiver_Stop();
		waitBreakEnd();
		bRxData = dmx_receiver_bReadRxData();		//read receiver data
		dmx_receiver_Start(dmx_receiver_PARITY_NONE); 
		return;
	}
	
	bRxData = dmx_receiver_bReadRxData();		//read receiver data
		
	channels(bRxData);
	
	
}	

void main()
{
	char intRet0[8];
	char intRet1[8];
	char intRet2[8];
	char intRet3[8];
	char intRet4[8];
	char intRet5[8];
	int test = 0;
   	LCD_1_Start();
	LCD_1_Init();
//	LCD_1_PrCString("Dmxreceiver");
	M8C_EnableGInt; 
	dmx_receiver_EnableInt(); 		//enable Rx interrupt
    dmx_receiver_Start(dmx_receiver_PARITY_NONE);		//start receiver with no parity check
	pwmred_Start();
	pwmgreen_Start();
	pwmblue_Start();
	pwmorange_Start();
	pwmwhite_Start();
//	pwmred_WritePeriod(65535);
//	pwmgreen_WritePeriod(65535);
//	pwmblue_WritePeriod(65535);
//	pwmorange_WritePeriod(65535);
//	pwmwhite_WritePeriod(65535);
	
	
	
	PRT0DR &= ~0x20;
   	while (1)
	{
   
//		LCD_1_Position(0,0);
//		LCD_1_PrCString("Ch0");
//		LCD_1_Position(1,0);
//		itoa(intRet0, (int)ch0, 10); 
//		LCD_1_PrString(intRet0); 

		LCD_1_Position(0,0);
		LCD_1_PrCString("Mas");
		LCD_1_Position(1,0);
		itoa(intRet1, (int)ch1, 10); 
		LCD_1_PrString(intRet1); 
		
		LCD_1_Position(0,3);
		LCD_1_PrCString("rot");
		LCD_1_Position(1,3);
		itoa(intRet2, (int)ch2, 10); 
		LCD_1_PrString(intRet2);
		
		LCD_1_Position(0,6);
		LCD_1_PrCString("gre");
		LCD_1_Position(1,6);
		itoa(intRet3, (int)ch3, 10); 
		LCD_1_PrString(intRet3);  
		
		LCD_1_Position(0,9);
		LCD_1_PrCString("blu");
		LCD_1_Position(1,9);
		itoa(intRet4, (int)ch4, 10); 
		LCD_1_PrString(intRet4);  
		
		LCD_1_Position(0,12);
		LCD_1_PrCString("ora");
		LCD_1_Position(1,12);
		itoa(intRet5, (int)ch5, 10); 
		LCD_1_PrString(intRet5);  
 		  



	}
   
   
}
thanks for all replies,
pfiff

phantom9999
Posts: 67
Joined: 03 Jul 2006 08:04

dmx receiver

#2 Post by phantom9999 » 09 Jul 2006 21:48

I was trying to compile your code to see if i could help. :cry: But it seems that you have extra include files that are not located on my system. Is there anyway i could get a hold of them, so i can test it out also. :idea: Or maybe my setting for the project are not correct. Processor, Mhz, Etc :?:

pfiff
Posts: 11
Joined: 04 Jul 2006 11:32

#3 Post by pfiff » 10 Jul 2006 06:55

Hi pahantom9999,
thanks for your reply, but i have solved this problem by myself. The problem was, that after i receive a byte i multiply a 16 bit value and this takes a lot of time.

pwmred_WritePulseWidth(Data * master);

Now i receive all bytes and then i multiply and write the pulse width of the pwms.

I have another problem:
i want to implement a strobe channel, channel 7.
my idea was using a counter, start it, set the port of my color high, when the counter is over, i set the port low.
10 % of Period time on, 90% of Period time off.
The problem is, i must strobe from 1 Hz to 25Hz.
The data, which i get from channel 7 must be the speed of the strobe.
dmx value 1 is 1 Hz, 255 is 25Hz, between this levels it must be linear.

Do you have any idea??

Thanks,
pfiff

phantom9999
Posts: 67
Joined: 03 Jul 2006 08:04

#4 Post by phantom9999 » 11 Jul 2006 05:42

Im kinda new to Mikro so bear with me. From reading you code, it dosent look like you using a Interrupts, You could use TMR0 ot TMR1 you interupt timer to do this function in the background. I have seen several posted code that uses the interrupts as a way to pulse all output to get everything in sync for AC timing for Zero Cross Dimming. Im sure something like that can be done.

Take a look at this link. This might help
http://www.mikroe.com/forum/viewtopic.p ... ght=dmx%2A


What is you application, what chip are you using and what are all the pins tied to.

What are you using for a pic and with what setting ( mhz,pinouts,etc. ). I would like to still see if i can get you code to compile on my system.

Post Reply

Return to “mikroC General”