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 CCS Technical Support

uart speed problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mulab
Guest







uart speed problem
PostPosted: Tue Apr 30, 2002 5:25 am     Reply with quote

I'm using UART at 250KBaud for DMX512 application.

The transmit is done changing Uart Speed but the first
change has no effect, the output is always at 250Kb.


#include <18C452.h)

#use rs232(baud=250000, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=9, BRGH1OK)


main
{
....
set_uart_speed(96150);
putc(0); ////this is done at 250Kb!!!
////the assembler done correctly

set_uart_speed(250000);
for(i=0; i<512; i++)
{
putc(channel[i]);

}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 4073
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: uart speed problem
PostPosted: Tue Apr 30, 2002 11:57 am     Reply with quote

I did an application a while back using a 16F876 as a DMX receiver to I2C transmiter to interface our product line to DMX. For testing the performance of the product I wrote some code to generate a DMX stream. I believe that you are trying to generate the break signal or "Mark" (I think that is the proper term). The following is some of the code that I used. I usually try not to use the CCS functions but I think you should be able to see how I accomplished this. CCS changed their compiler so if you use the notation *REG you will have to cast it like (int)*REG = Somevalue. If you have any questions please ask.

Mark

void main(void)
{
UINT8 index = 0; /* index */

/* initialize variables first, since initializing pic
will allow interrupts to begin occurring */
Initialize_Variables();

Init_PIC();

/* read the shift registers */
Read_Inputs();


/* set levels */
memset(levels,0,sizeof(levels));

/* Start sending the DMX stream */
Send_Break = TRUE;
Send_Start_Code = FALSE;

/* This is the main loop code */
while (TRUE)
{
restart_wdt();

/************************************************************************
* Dynamic Options *
************************************************************************/

if (Send_Break && bit_test(*TXSTA, 1))
{
DATA_LED_ON();
RS485_TRANSMIT_ENABLE();
/* serial port disable */
bit_clear(*RCSTA,SPEN);
setup_timer_1(T1_DISABLED);
bit_clear(*PIR1, TMR1IF);
bit_clear(*PIE1, TXIE);
/* Setup Timer1 for 88us break signal
Timer1 increments every .2us the 47 is the interrupt lag */
set_timer1(0xFFFF-(440 - 47));
bit_clear(*PORTC, 0x06);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
bit_set(*PIE1, TMR1IE);
Send_Break = FALSE;
}

else if (Send_Start_Code)
{
Send_Start_Code = FALSE;
delay_us(3);

/* Send start code */
*TXREG = 0;

/* serial port enable */
bit_set(*RCSTA,SPEN);

/* Start transmission */
bit_set(*TXSTA,TXEN);
bit_set(*TXSTA,6);
bit_set(*TXSTA,0);
bit_set(*PIE1, TXIE);
}

/* See if it is time to read the switch inputs */
else if (!Switch_Timeout)
{
Read_Inputs();
/* Read the switch inputs every 2 secs */
Switch_Timeout = 20;
}
else if (!JUMPER_LK2_BOTTOM_OFF())
{
memset(levels,255,sizeof(levels));
}
else if (!JUMPER_LK2_TOP_OFF())
{
memset(levels,0,sizeof(levels));
}
else if (!Delay_Timeout && (Max_Dimmers > 0))
{
switch (Shift_Reg_Inputs.data.i2c)
{
case 0:
memset(levels,0,sizeof(levels));
levels[index] = 255;
++index;
if (index >= Max_Dimmers)
index = 0;
break;
case 1:
memset(levels,0,sizeof(levels));
levels[index] = 255;
if (!index)
index = Max_Dimmers;
--index;
break;
case 2:
if (index >= Max_Dimmers)
{
memset(levels,0,sizeof(levels));
index = 0;
}
else
{
levels[index] = 255;
++index;
}
break;
default:
memset(levels,0,sizeof(levels));
levels[index] = 255;
++index;
if (index >= Max_Dimmers)
index = 0;
break;
}
Delay_Timeout = Delay_Time;
}

} /* end of forever loop */

}



/****************************************************************************
* NAME: Tx_Data
* DESCRIPTION: Transmits a byte using the UART to a DMX universe
* PARAMETERS: none
* GLOBALS: UINT8 Tx_Index (IO) transmit buffer pointer
* UINT8 Tx_Buffer (IO) transmit buffer
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#INT_TBE
void Tx_Data(void)
{
static UINT8 tx_index = 0;

while (bit_test(*INTCON,0x07))
bit_clear(*INTCON,0x07);

DATA_LED_OFF();
if (!Max_Dimmers)
{
bit_clear(*PIE1, TXIE);
tx_index = 0;
Send_Break = TRUE;

}
else
{
*TXREG = levels[tx_index];
bit_set(*TXSTA,TXEN);
/* Transmit nine data bits, one is used for the stop bit */
bit_set(*TXSTA,6);
bit_set(*TXSTA,0);
++tx_index;
if (tx_index >= Max_Dimmers)
{
/* Disable the interrupt if we are done transmitting */
bit_clear(*PIE1, TXIE);
tx_index = 0;
Send_Break = TRUE;
}
}
}

/****************************************************************************
* NAME: Timer1_ISR
* DESCRIPTION:
* PARAMETERS: none
* GLOBALS: none
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#INT_TIMER1
void Timer1_ISR(void)
{
while (bit_test(*INTCON, 0x07)) /* make sure interrupts were */
bit_clear(*INTCON, 0x07); /* disabled. */

/* Disable Timer1 int */
setup_timer_1(T1_DISABLED);

bit_set(*PORTC, 0x06);
Send_Start_Code = TRUE;

}

:=I'm using UART at 250KBaud for DMX512 application.
:=
:=The transmit is done changing Uart Speed but the first
:=change has no effect, the output is always at 250Kb.
:=
:=
:=#include <18C452.h)
:=
:=#use rs232(baud=250000, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=9, BRGH1OK)
:=
:=
:=main
:={
:= ....
:= set_uart_speed(96150);
:= putc(0); ////this is done at 250Kb!!!
:= ////the assembler done correctly
:=
:= set_uart_speed(250000);
:= for(i=0; i<512; i++)
:= {
:= putc(channel[i]);
:=
:= }
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 4077
mulab
Guest







Re: uart speed problem
PostPosted: Thu May 02, 2002 3:25 am     Reply with quote

Thank you fo reply,

Really I'm tryng to C solution to replace my old assembler
based code.
While waiting for a message reply I have found this solution:

set_uart_speed(96150);
putc(0); //this is done at 96.15Kb!!!
putc(0); //I thing this byte and following
//flushes tx buffer
putc(0); //this is done at 250Kb, but is ok
//(dmx stream start code)

set_uart_speed(250000);
for(i=0; i<512; i++)
{
putc(channel[i]);
}

This generate a dmx stream with break time over 88 us and
mab time over 8 us.
I'm not understand if this is done ok due to hardware serial
buffer flushing.

:=I did an application a while back using a 16F876 as a DMX receiver to I2C transmiter to interface our product line to DMX. For testing the performance of the product I wrote some code to generate a DMX stream. I believe that you are trying to generate the break signal or "Mark" (I think that is the proper term). The following is some of the code that I used. I usually try not to use the CCS functions but I think you should be able to see how I accomplished this. CCS changed their compiler so if you use the notation *REG you will have to cast it like (int)*REG = Somevalue. If you have any questions please ask.
:=
:=Mark
:=
:=void main(void)
:={
:= UINT8 index = 0; /* index */
:=
:= /* initialize variables first, since initializing pic
:= will allow interrupts to begin occurring */
:= Initialize_Variables();
:=
:= Init_PIC();
:=
:= /* read the shift registers */
:= Read_Inputs();
:=
:=
:= /* set levels */
:= memset(levels,0,sizeof(levels));
:=
:= /* Start sending the DMX stream */
:= Send_Break = TRUE;
:= Send_Start_Code = FALSE;
:=
:= /* This is the main loop code */
:= while (TRUE)
:= {
:= restart_wdt();
:=
:= /************************************************************************
:= * Dynamic Options *
:= ************************************************************************/
:=
:= if (Send_Break && bit_test(*TXSTA, 1))
:= {
:= DATA_LED_ON();
:= RS485_TRANSMIT_ENABLE();
:= /* serial port disable */
:= bit_clear(*RCSTA,SPEN);
:= setup_timer_1(T1_DISABLED);
:= bit_clear(*PIR1, TMR1IF);
:= bit_clear(*PIE1, TXIE);
:= /* Setup Timer1 for 88us break signal
:= Timer1 increments every .2us the 47 is the interrupt lag */
:= set_timer1(0xFFFF-(440 - 47));
:= bit_clear(*PORTC, 0x06);
:= setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
:= bit_set(*PIE1, TMR1IE);
:= Send_Break = FALSE;
:= }
:=
:= else if (Send_Start_Code)
:= {
:= Send_Start_Code = FALSE;
:= delay_us(3);
:=
:= /* Send start code */
:= *TXREG = 0;
:=
:= /* serial port enable */
:= bit_set(*RCSTA,SPEN);
:=
:= /* Start transmission */
:= bit_set(*TXSTA,TXEN);
:= bit_set(*TXSTA,6);
:= bit_set(*TXSTA,0);
:= bit_set(*PIE1, TXIE);
:= }
:=
:= /* See if it is time to read the switch inputs */
:= else if (!Switch_Timeout)
:= {
:= Read_Inputs();
:= /* Read the switch inputs every 2 secs */
:= Switch_Timeout = 20;
:= }
:= else if (!JUMPER_LK2_BOTTOM_OFF())
:= {
:= memset(levels,255,sizeof(levels));
:= }
:= else if (!JUMPER_LK2_TOP_OFF())
:= {
:= memset(levels,0,sizeof(levels));
:= }
:= else if (!Delay_Timeout && (Max_Dimmers > 0))
:= {
:= switch (Shift_Reg_Inputs.data.i2c)
:= {
:= case 0:
:= memset(levels,0,sizeof(levels));
:= levels[index] = 255;
:= ++index;
:= if (index >= Max_Dimmers)
:= index = 0;
:= break;
:= case 1:
:= memset(levels,0,sizeof(levels));
:= levels[index] = 255;
:= if (!index)
:= index = Max_Dimmers;
:= --index;
:= break;
:= case 2:
:= if (index >= Max_Dimmers)
:= {
:= memset(levels,0,sizeof(levels));
:= index = 0;
:= }
:= else
:= {
:= levels[index] = 255;
:= ++index;
:= }
:= break;
:= default:
:= memset(levels,0,sizeof(levels));
:= levels[index] = 255;
:= ++index;
:= if (index >= Max_Dimmers)
:= index = 0;
:= break;
:= }
:= Delay_Timeout = Delay_Time;
:= }
:=
:= } /* end of forever loop */
:=
:=}
:=
:=
:=
:=/****************************************************************************
:=* NAME: Tx_Data
:=* DESCRIPTION: Transmits a byte using the UART to a DMX universe
:=* PARAMETERS: none
:=* GLOBALS: UINT8 Tx_Index (IO) transmit buffer pointer
:=* UINT8 Tx_Buffer (IO) transmit buffer
:=* RETURN: none
:=* ALGORITHM: none
:=* NOTES: none
:=*****************************************************************************/
:=#INT_TBE
:=void Tx_Data(void)
:={
:= static UINT8 tx_index = 0;
:=
:= while (bit_test(*INTCON,0x07))
:= bit_clear(*INTCON,0x07);
:=
:= DATA_LED_OFF();
:= if (!Max_Dimmers)
:= {
:= bit_clear(*PIE1, TXIE);
:= tx_index = 0;
:= Send_Break = TRUE;
:=
:= }
:= else
:= {
:= *TXREG = levels[tx_index];
:= bit_set(*TXSTA,TXEN);
:= /* Transmit nine data bits, one is used for the stop bit */
:= bit_set(*TXSTA,6);
:= bit_set(*TXSTA,0);
:= ++tx_index;
:= if (tx_index >= Max_Dimmers)
:= {
:= /* Disable the interrupt if we are done transmitting */
:= bit_clear(*PIE1, TXIE);
:= tx_index = 0;
:= Send_Break = TRUE;
:= }
:= }
:=}
:=
:=/****************************************************************************
:=* NAME: Timer1_ISR
:=* DESCRIPTION:
:=* PARAMETERS: none
:=* GLOBALS: none
:=* RETURN: none
:=* ALGORITHM: none
:=* NOTES: none
:=*****************************************************************************/
:=#INT_TIMER1
:=void Timer1_ISR(void)
:={
:= while (bit_test(*INTCON, 0x07)) /* make sure interrupts were */
:= bit_clear(*INTCON, 0x07); /* disabled. */
:=
:= /* Disable Timer1 int */
:= setup_timer_1(T1_DISABLED);
:=
:= bit_set(*PORTC, 0x06);
:= Send_Start_Code = TRUE;
:=
:=}
:=
:=:=I'm using UART at 250KBaud for DMX512 application.
:=:=
:=:=The transmit is done changing Uart Speed but the first
:=:=change has no effect, the output is always at 250Kb.
:=:=
:=:=
:=:=#include <18C452.h)
:=:=
:=:=#use rs232(baud=250000, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=9, BRGH1OK)
:=:=
:=:=
:=:=main
:=:={
:=:= ....
:=:= set_uart_speed(96150);
:=:= putc(0); ////this is done at 250Kb!!!
:=:= ////the assembler done correctly
:=:=
:=:= set_uart_speed(250000);
:=:= for(i=0; i<512; i++)
:=:= {
:=:= putc(channel[i]);
:=:=
:=:= }
:=:=
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 4107
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