|
|
View previous topic :: View next topic |
Author |
Message |
cylence
Joined: 21 Feb 2006 Posts: 3 Location: Planet Earth
|
Time padding on RS232 |
Posted: Tue Feb 21, 2006 10:24 am |
|
|
I am trying to simulate a particular serial protocol (DMX512, used by stage lighting equipment) using the USART
of the PIC16F877. The bps speed is at 250KHz (1 bit = 4u sec. wide).
I need to manually craft the packets so they can be 100% compatible with the equipment.
Obviously the idle state for the serial communication is always a "high" state.
I need to put the level to a low state for at least 88 uSec (20 bits), this is
the "break code" of the packet according to the DMX protocol. Here is a simplified sample of my code to acheive this :
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
do
{
output_C(0x0); //low state
delay_us(128); //Break code delay.
putc(0xA); //sample data
}
while(1);
}
in my ".h" I have the following :
#include <16F877.h>
#device ICD=TRUE
#device adc=8
#fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, LVP, NOCPD, NOWRT, DEBUG
#use delay(clock=20000000)
#use rs232(baud=250000,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
Note that I need to programm a 128 usec delay in order to acheive an actual 88 usec delay at the output, wich is the
execution latency (around 40 usec).
My problem is that the USART does my "time padding" but not at the correct state. I need it to be at a low state for that
period of time but the USART always outputs it at 1.
Can someone let me know how to override this or even tell me if its feasable to override the state of the serial pin while
idling or a better way to acheive this ? Your help would be greatly appreciated.
Thank you. _________________ Gravity Works. |
|
|
cylence
Joined: 21 Feb 2006 Posts: 3 Location: Planet Earth
|
|
Posted: Tue Feb 21, 2006 10:47 am |
|
|
Yes, I am actually using a 75176 transceiver at the output of my PIC USART.
Transceiver works well, my problem is with the logic state of my time padding. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Feb 21, 2006 10:59 am |
|
|
There are several ways to do this. Here is a couple:
1. You can take control of the TX pin away from the UART and do the break yourself.
2. You can change to baud rate of the UART to a lower rate and send a 0x00 character. Once the character has gone you can then change the rate back again.
Quote: |
Note that I need to programm a 128 usec delay in order to acheive an actual 88 usec delay at the output, wich is the execution latency (around 40 usec). |
This does not make sense - I assume you have missed something in the explanation. For example, has this been done to enable the previous character to be serialized out?
If so then the way to do this is monitor the state of the TRMT bit in the TXSTA register to wait until the Transmit Shift Register (TSR) is empty. When empty then set the output low, delay 88us, set the output high. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
cylence
Joined: 21 Feb 2006 Posts: 3 Location: Planet Earth
|
|
Posted: Tue Feb 21, 2006 11:49 am |
|
|
I'm guessing I should use the "SET_UART_SPEED()" command to reduce the transmit speed, right ?
Also how can I take the controll away from the UART ? Do you have some example code ?
As for my latency explanation, I didn't program this to serialize a previous character.
I have probably misunderstood some concepts. I simply noticed on my logic analyser that when I tried to
output a level to a certain amount of time, the result displayed was always shorter than the time
programmed. So I streched it to 128 usec to be able to see a delay of 88 usec on my logic analyser. This is surely not
the best way to acheive it, but its all I've came up with so far.
Thanx in advance ;) |
|
|
Guest
|
|
|
|
|
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
|