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

putc / getc execution time?

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







putc / getc execution time?
PostPosted: Fri Sep 20, 2002 11:30 am     Reply with quote

At a given baud rate, char length and what not, how do i work out how long it takes to read in or send a single char using the Hardware USART on the '877?

I'm wanting to do somthing productive with all the delay_us(xx)'s and have stuff recived and sent while waiting (damn those LCD screens are sloooooow)

TIA
___________________________
This message was ported from CCS's old forum
Original Post ID: 7223
Tomi
Guest







Re: putc / getc execution time?
PostPosted: Fri Sep 20, 2002 12:25 pm     Reply with quote

If you not use interrupts then getc() time is unpredictable; the byte time after the falling edge of the start bit. The putc() function waits to empty the output shift register, the time is the byte time.
The byte time is the sum of the:
start bit
information bits
optional parity bit
stop bit(s)
so the byte time is calculated as:
(total bit number)/baudrate
i.e. 9600 Bd 8N1 (1 start bit, 8 bit data, no parity, 1 stop bit) is 10 bits, so the byte time is:
10/9600 = 0,00104166 seconds what is 1.04 msec.

If you use interrupts (int_rda for receive and int_tbe for transmit) then the receive and transmit time is in the microsecond range.


:=At a given baud rate, char length and what not, how do i work out how long it takes to read in or send a single char using the Hardware USART on the '877?
:=
:=I'm wanting to do somthing productive with all the delay_us(xx)'s and have stuff recived and sent while waiting (damn those LCD screens are sloooooow)
:=
:=TIA
___________________________
This message was ported from CCS's old forum
Original Post ID: 7226
Shep
Guest







Re: putc / getc execution time?
PostPosted: Fri Sep 20, 2002 4:29 pm     Reply with quote

so INT_RDA could be used instead of KBhit(), i see that now in the manual.

What isn't making a whole lot of sence to me right now it the interrupt transmit buffer empty... it interrupts when there isn't any data to send? hows that useful???

anywho i'll be working in the 56700 baud rate range, so the delay could be used to send bytes. I assume the timming is the time to send the 10 bits + a few instructions around that (+the time to check my fifo for out going data etc.)

Thanks for the advice.

:=If you not use interrupts then getc() time is unpredictable; the byte time after the falling edge of the start bit. The putc() function waits to empty the output shift register, the time is the byte time.
:=The byte time is the sum of the:
:=start bit
:=information bits
:=optional parity bit
:=stop bit(s)
:=so the byte time is calculated as:
:=(total bit number)/baudrate
:=i.e. 9600 Bd 8N1 (1 start bit, 8 bit data, no parity, 1 stop bit) is 10 bits, so the byte time is:
:=10/9600 = 0,00104166 seconds what is 1.04 msec.
:=
:=If you use interrupts (int_rda for receive and int_tbe for transmit) then the receive and transmit time is in the microsecond range.
___________________________
This message was ported from CCS's old forum
Original Post ID: 7230
Tomi
Guest







Re: putc / getc execution time?
PostPosted: Sat Sep 21, 2002 12:43 am     Reply with quote

:=What isn't making a whole lot of sence to me right now it the interrupt transmit buffer empty... it interrupts when there isn't any data to send? hows that useful???

Transmit buffer empty means that you can push the next byte to send into the transmitter circuit. So you can push a byte into buffer and return immediately. INT_TBE fires when the byte is transmitted out. Here is a small example (for V2.xxx and RS-485 bus):

#include <16F877.h>
#fuses XT,WDT,PUT,NOPROTECT,NOBROWNOUT,NOLVP
#id 1,0,0,0
#use delay (clock=2457600,restart_wdt)
#use rs232 (baud=19200,xmit=PIN_C6,rcv=PIN_C7)
char out_str[20];
char idx,tosendidx;

void SaveNext(char be)
{
out_str[idx++] = be; // save the value
out_str[idx] = 0; // terminate the line with \0
}

#int_tbe
void tbe_transmit()
{
char toSend;
toSend = out_str[tosendidx++]; // get the next char, save it into a local variable
if (toSend) { // if it is NOT the terminating \0 character
output_high(PIN_C5); // turn on the transmitter (RS485)
*0x19 = toSend; // send it out if it is not the terminating \0
} else {
output_low(PIN_C5); // turn off the transmitter (RS485)
Disable_interrupts(INT_TBE); // disable any further transmit ITs
}
}

void main()
{
char k, length;

Enable_interrupts(GLOBAL);
k = 0;
while (1) {
Restart_wdt();
k++;

/* Initialize the next sending */
idx = 0; // set string puffer pointer to zero
tosendidx = 0; // the first char position to send
printf(SaveNext,"Loop# \%u\r\n",k); // fill out the string
length = idx; // optional: to get the string length

// The transmit will start at the next line
Enable_interrupts(INT_TBE); // enable the transmit IT
/* At this point - because the transmit buffer is actually empty-
the program enters into INT_TBE immediately !!! */

// optional synchronizing
while (tosendidx < length) Restart_wdt(); // wait until the last non-zero char is sent
}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 7234
Shep
Guest







Re: putc / getc execution time?
PostPosted: Sat Sep 21, 2002 6:48 am     Reply with quote

ahhh, i see, thanks for the help, most useful.
(it's times like thess that an oscilliscope would be REALLY useful!)

:=Transmit buffer empty means that you can push the next byte to send into the transmitter circuit. So you can push a byte into buffer and return immediately. INT_TBE fires when the byte is transmitted out. Here is a small example (for V2.xxx and RS-485 bus):
:=
:=#include <16F877.h>
:=#fuses XT,WDT,PUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#id 1,0,0,0
:=#use delay (clock=2457600,restart_wdt)
:=#use rs232 (baud=19200,xmit=PIN_C6,rcv=PIN_C7)
:=char out_str[20];
:=char idx,tosendidx;
:=
:=void SaveNext(char be)
:={
:=out_str[idx++] = be; // save the value
:=out_str[idx] = 0; // terminate the line with \0
:=}
:=
:=#int_tbe
:=void tbe_transmit()
:={
:=char toSend;
:=toSend = out_str[tosendidx++]; // get the next char, save it into a local variable
:=if (toSend) { // if it is NOT the terminating \0 character
:=output_high(PIN_C5); // turn on the transmitter (RS485)
:=*0x19 = toSend; // send it out if it is not the terminating \0
:=} else {
:=output_low(PIN_C5); // turn off the transmitter (RS485)
:=Disable_interrupts(INT_TBE); // disable any further transmit ITs
:=}
:=}
:=
:=void main()
:={
:=char k, length;
:=
:=Enable_interrupts(GLOBAL);
:=k = 0;
:=while (1) {
:=Restart_wdt();
:=k++;
:=
:=/* Initialize the next sending */
:=idx = 0; // set string puffer pointer to zero
:=tosendidx = 0; // the first char position to send
:=printf(SaveNext,"Loop# \%u\r\n",k); // fill out the string
:=length = idx; // optional: to get the string length
:=
:=// The transmit will start at the next line
:=Enable_interrupts(INT_TBE); // enable the transmit IT
:=/* At this point - because the transmit buffer is actually empty-
:=the program enters into INT_TBE immediately !!! */
:=
:=// optional synchronizing
:=while (tosendidx < length) Restart_wdt(); // wait until the last non-zero char is sent
:=}
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 7236
Shep
Guest







Re: putc / getc execution time?
PostPosted: Mon Sep 23, 2002 11:31 am     Reply with quote

Just to get this stright in my head...

This precedure (below) when the interrupt is enabled, will execute if there is data in my buffer, then will exit after tranferring the data from my software buffer into the USARTs hardware buffer... then, when the hardware has completed sending the byte the interupt will trigger again and so-on until my buffer is empty.

To clarfy, the excution will NOT sit in the ISR for the duration of the sending of the byte?

TIA

<pre>
#INT_TBE void TBEInterrupt() // when the hardware transmit buffer is empty...
{
if (DataTX.SpaceTaken > 0) // ...and the software buffer has contents
PutC(FifoRead(&DataTX)); // send data
else
Disable_Interrupts(INT_TBE); // then disable interupt when all data is sent
}
</pre>
___________________________
This message was ported from CCS's old forum
Original Post ID: 7254
Tomi
Guest







Re: putc / getc execution time?
PostPosted: Tue Sep 24, 2002 11:57 am     Reply with quote

You can check it in the list file but usually a putc() call waits for the output shift register emptied (but I didn't check it in the last 2 years Smile ).
But if you want to use interrupt-driven transmit then it is the best if the program NOT sit in the ISR while the physical transmit is in progress (this is the soul of the IT-driven transmit; and this is the reason why I didn't use putc() in my ISR example; the line "*0x19 = toSend;" is equivalent with putc() but doesn't contain any waits).

:=To clarfy, the excution will NOT sit in the ISR for the duration of the sending of the byte?
:=
:=TIA
:=
:=<pre>
:=#INT_TBE void TBEInterrupt() // when the hardware transmit buffer is empty...
:={
:= if (DataTX.SpaceTaken > 0) // ...and the software buffer has contents
:= PutC(FifoRead(&DataTX)); // send data
:= else
:= Disable_Interrupts(INT_TBE); // then disable interupt when all data is sent
:=}
:=</pre>
___________________________
This message was ported from CCS's old forum
Original Post ID: 7280
Shep
Guest







Re: putc / getc execution time?
PostPosted: Tue Sep 24, 2002 12:14 pm     Reply with quote

Right, i see. Not eay to find this info - would be nice if they mentioned this in the manual.

i take it *0x19 is a pointer to a register which contains the byte to be sent.

Thanks for you help. :)

:=You can check it in the list file but usually a putc() call waits for the output shift register emptied (but I didn't check it in the last 2 years <img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0"> ).
:=But if you want to use interrupt-driven transmit then it is the best if the program NOT sit in the ISR while the physical transmit is in progress (this is the soul of the IT-driven transmit; and this is the reason why I didn't use putc() in my ISR example; the line "*0x19 = toSend;" is equivalent with putc() but doesn't contain any waits).
___________________________
This message was ported from CCS's old forum
Original Post ID: 7281
Tomi
Guest







Re: putc / getc execution time?
PostPosted: Tue Sep 24, 2002 1:48 pm     Reply with quote

:=i take it *0x19 is a pointer to a register which contains the byte to be sent.

Exactly. The Transmit Buffer Register (TXREG) is at address 0x19 which is a pointer in C so you can access it by a *
Note that you can access it also using:
#byte TXREG = 0x19
TXREG = toSend;
___________________________
This message was ported from CCS's old forum
Original Post ID: 7287
andy gorrie
Guest







Re: putc / getc execution time?
PostPosted: Mon Oct 07, 2002 6:19 am     Reply with quote

sounds better than the putc command but can this be used with other pins?
we need to use the following 2 rs232 setups in our prog.
#use RS232(Baud=9600,Xmit=PIN_B2,Rcv=PIN_B5,bits=8,parity=N) // S/M OUT, M/S IN

or
#use RS232(Baud=9600,Xmit=PIN_B3,Rcv=PIN_B4,bits=8,parity=N) // M/S OUT, S/M IN

depending on the mode configuration of the s/w
to make things more complex the tx must take place every 50ms so the write to port (putc or *0x19c write) is inside a timer interrupt


:=
:=:=i take it *0x19 is a pointer to a register which contains the byte to be sent.
:=
:=Exactly. The Transmit Buffer Register (TXREG) is at address 0x19 which is a pointer in C so you can access it by a *
:=Note that you can access it also using:
:=#byte TXREG = 0x19
:=TXREG = toSend;
___________________________
This message was ported from CCS's old forum
Original Post ID: 7524
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