CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DMX Slave device

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

DMX Slave device
PostPosted: Thu Apr 20, 2017 4:18 am     Reply with quote

In one of my devices I'm using a receiving routine that I do not fully satisfy, and I wanted to improve the product using CCS's DMX libraries. Then the Hardware is working.
With CCS routines I can not receive DMX data and in debug I do not enter the interrupt.
Does anyone have a tip?

Code:

/////////////////////////////////////////////////////////////////////////
////           DERIVATE       ex_dmx_slave.c                         ////
/////////////////////////////////////////////////////////////////////////

#include <24EP32GP204.h>

#device ICD=TRUE
#device ICSP=2

#fuses NOWDT
#use delay(clock=140MHz,crystal=8MHz)

#pin_select U2TX=PIN_C8
#pin_select U2RX=PIN_B4
#use rs232(UART2, baud=115200, stream=UART_PORT2)
//#use rs232(UART1,baud=9600, stream=PC)

#pin_select U1RX=PIN_C6


//#use pwm(CCP1, timer=2, frequency=5000, duty=0)

//Setup Tick timer for DMX Driver
#use timer(timer=1, tick=1us, bits=16)

typedef unsigned int16 TICK;

TICK GetTickDifference(TICK Current, TICK Previous)
{
   return(Current - Previous);
}

//Required Macros for DMX Driver when using it for a slave device
#define DMX_TICK                    TICK
#define DMXGetTick()                get_ticks()
#define DMXGetTickDifference(x, y)  GetTickDifference(x, y)
#define DMX_TICKS_PER_MS            (TICKS_PER_SECOND  / 1000)

//Setup DMX Driver Settings
#define DMX_TYPE           DMX_SLAVE_DEVICE
#define DMX_INT            INT_RDA
#define DMX_RCV            PIN_C6
#define DMX_START_CHANNEL  1
#define DMX_CHANNELS       2  //16 bit LSB first





//Include the DMX Driver
#include <dmx.c>

void main()
{

   unsigned int16 PWMDuty;
   unsigned int16 pPWMDuty = 0;
   
   delay_ms(100);
   
   //printf("\r\nex_dmx_slave.c\r\n");
   putchar('R',UART_PORT2);
   putchar('O',UART_PORT2);
   putchar('B',UART_PORT2);
   putchar('Y',UART_PORT2);
   //Initialize the DMX Driver
   DMXInit();
   
   //Enable Global Interrupts
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      //Get for new DMX Data
      if(DMXKbhit())
      {

         putchar('Y',UART_PORT2);


         //Get new DMX Data
         DMXGetd(&PWMDuty, DMX_CHANNELS);

         if(PWMDuty != pPWMDuty)
         {
            if(PWMDuty > 1000)
               PWMDuty = 1000;
            putchar((((PWMDuty>>8) & 0xFF)),UART_PORT2);
            putchar(((PWMDuty & 0xFF)),UART_PORT2);
//            pwm_set_duty_percent(PWMDuty);

            pPWMDuty = PWMDuty;
         }
      }
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 20, 2017 6:45 am     Reply with quote

OK, it's be 2 decades since I built/used DMX but back then it was 250KB and a PIC UART could easily be setup to run DMX so I don't know why you've got a timer and other code doing what the HW UART can....

Jay
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

DMX Slave device dont't work PIC24EP32GP
PostPosted: Thu Apr 20, 2017 6:56 am     Reply with quote

As you can see from the posted code, it's exactly the official CCS example, where I just changed the processor and set the peripherals I'm using, if I re-run everything properly, I'll integrate it into the project.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Apr 20, 2017 8:35 am     Reply with quote

CCS dropped that example, many years ago.
What DMX protocol are you using?. The original CCS example, was for an early DMX512 variant, not the current DMX512-A.
The example has never been updated....
DMX512-A, is quite easy to do with the hardware UART. What you have to do, is set it up to send at 250000bps, and select 9bit operation. DMX uses 8bits, with 2 stop bits, and to cheat the UART into doing this, you use 9bits, and set the 9th bit in the data you send. This gives the required extra stop bit.
The reason the timer was used, was to handle the timings for the break marker at the start of the packet.
Honestly, just write your own. This is not an example you should be using.
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

dmx 512-A
PostPosted: Thu Apr 20, 2017 9:18 am     Reply with quote

I use DMX512-A "ANSI E1.11-2008 (R2013)"
Is there an example of an updated code sample for correct reception of characters?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 20, 2017 5:07 pm     Reply with quote

Have a read of Microchip's AN1659 DMX512a, you can download the sources from them too. You WILL have to convert into CCS C, fairly easy to do. Probably less than 2 coffee pots will get you 'up and running'.

I know I have my code here 'somewhere'.. but after 20+ years..it'd be quicker just to cut new code !

Jay
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

dmx 512-A receiver
PostPosted: Fri Apr 21, 2017 1:47 am     Reply with quote

I downloaded the AN1659, now I try to implement the receive routine. Let's see if it works.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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