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

#use RS232 BAD TIMMING ??

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







#use RS232 BAD TIMMING ??
PostPosted: Sat Sep 16, 2006 2:57 pm     Reply with quote

Hi !

I use this code to send data at 250KBaud, when a check with a scope i got
4US bit time for 1 and 2.8us for 0 ???

I have make many test with Usart ans software usart , i got 2.8us on 0 ?
i have try many Pic !!!

Thanks for your help !!!

#include <16f876>

#USE Delay(Clock=20000000)
#use rs232(baud=250000, xmit=PIN_c6, bits=9,errors)
#bit ninth_bit = RS232_ERRORS.7
#DEFINE H_START 10
#BYTE Port_B = 0x06
#BYTE Port_A = 0x05
#BYTE Port_C = 0x07
#byte port_d = 0x08
#byte port_e = 0x09
#define ints_per_second 2
#use fast_io(c)
#use fast_io(a)

byte secounds;
byte int_count;

byte Receive, i;
long address;
long aa;
byte b;
byte h_count;

#int_rtcc
clock_isr(){
byte a;
long b;
if(--int_count==0) {
//output_low(pin_a0);
//delay_us(88);
//output_high(pin_a0);
//delay_us(8);

putc(170);
putc(0);
int_count=ints_per_second;

}
}



main(){
byte a;
ninth_bit =1;
set_tris_a(00000);

//set_tris_c(00000000);

port_b_pullups(true);

int_count=ints_per_second;
set_rtcc(0);

setup_counters(rtcc_internal, rtcc_div_256);
enable_interrupts(int_rtcc);
enable_interrupts(global);

output_high(pin_c7);
start:

delay_ms(5);
goto start;



}
Ttelmah
Guest







PostPosted: Sun Sep 17, 2006 2:49 am     Reply with quote

Ignoring everything else, how are you getting the figure '2', for 'INTS_PER_SECOND'?. If you chip is running at 20MHz, as set in your delay statement, then the RTCC, should interrupt 76 times per second (20000000/(4*256*256)). If it is interrupting 2 times per second, then your system clock, is only 500KHz....
With only one pin given in the RS232 setup line, the soft UART will allways be selected. However the timings of both, are completely dependant, on your actual clock frequency matching the delay setting.
As seperate comments, use the 'code' button to post code. Also consider 'tidying' your programming style. Goto jumps are 99%unneccessary, and can encourage program layouts that are likely to fail. They should only be used when they bring a real advantage. When posting 'problem' code, remove the 'dross', but leave the working core. You have loads of variable declarations, and defines that are not used, but have left out the fuses, so the code as posted cannot run.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 17, 2006 2:54 pm     Reply with quote

I stripped your program down to essentials, compiled it with PCM 3.249,
and programmed it into a PicDem2-Plus board. I measured 4.18 us for
a "high" bit and 3.36 us for a "low" bit. That's with the software UART.
Here's the program I tested it with:
Code:
#include <16F877.H>
#fuses HS, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=250000, xmit=PIN_C6, bits=9,errors)
#bit ninth_bit = RS232_ERRORS.7
#use fast_io(c)

void main()
{
ninth_bit =1;

set_tris_c(0xBF);

while(1)
  {
   putc(0x01);
  }

}


Then I changed the #use rs232() statement so it would use the hardware
UART instead of a soft UART. I did this by adding the rcv pin:
Code:
#use rs232(baud=250000, xmit=PIN_C6, rcv=PIN_C7, bits=9,errors)

Now when I measure the waveform pulses, I get 3.97 us for either a
high bit or a low bit. Considering that the scope will be off a little bit
and that I'm setting the time measurement cursors by eye, that's pretty
good -- 4.0 us would be the perfect time.
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