Searching \ for '[PIC]: Max bit bang serial on 4Mhz 16F876' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/ios.htm?key=serial
Search entire site for: 'Max bit bang serial on 4Mhz 16F876'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Max bit bang serial on 4Mhz 16F876'
2003\03\25@184107 by Andy Shaw

flavicon
face
Folks,
Before I go off and waste a bunch of time trying to do the impossible (but
hey it may be fun), does anyone have any advice on what is the fastest half
duplex rs323 comms I can expect to get using software only on a 4MHz 16f876
(using a resonator not a crystal)?

I'm currently using the code created by Andy N1YEW and posted on piclist.com
and have this working fine at 19200 baud, but if possible I would like to
run a little faster. I know I should probably be using the built in hardware
but the board layout (not mine) will not allow it. I could also switch to a
higher speed but again I would like to avoid changes to the board. The way
things are I can probably dedicate the entire cpu to the serial code while
transmitting/receiving with the exception of a TMR0 roll over interrupt that
has been coded with minimal register save and just a simple increment of a
counter (approx 5 instructions long), the interrupt occurs every 65535
instructions (TMR0 is using divide by 256 pre-scaler).

Thanks for any help

Andy

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\03\25@185146 by andrew

picon face
38400 should be easily done, cut all the delays in half =P
maybe even 115200 but that would need like rewriting the whole code..

-andrew
{Original Message removed}

2003\03\25@190456 by Mike Harrison

flavicon
face
It depends a lot on what constraints there are from other requirements of your system - rates as
high as 115K2 are possible at 4MHz if you don't mind it using up almost all your CPU time doing
serial comms.

On Tue, 25 Mar 2003 23:40:18 -0000, you wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\03\25@192827 by Andy Shaw

flavicon
face
115K sounds much better than I expected! Anyone got any sample code for I/O
at this speed?

Andrew a big thanks for making your code available. I used it to replace the
inbuilt CCS C compiler serial code, that worked fine at 9600 but I couldn't
get it to work at 19200, your code worked straight out of the box! Oh and if
anyone is interested I'm using this to control a home built cnc machine....
Take a look at http://www.gloomy-place.com/cnc.htm

Thanks again

Andy

{Original Message removed}

2003\03\25@195629 by Scott Dattalo

face
flavicon
face
On Tue, 25 Mar 2003, Andy Shaw wrote:

> Folks,
> Before I go off and waste a bunch of time trying to do the impossible (but
> hey it may be fun), does anyone have any advice on what is the fastest half
> duplex rs323 comms I can expect to get using software only on a 4MHz 16f876
> (using a resonator not a crystal)?
>
> I'm currently using the code created by Andy N1YEW and posted on piclist.com
> and have this working fine at 19200 baud, but if possible I would like to
> run a little faster. I know I should probably be using the built in hardware
> but the board layout (not mine) will not allow it. I could also switch to a
> higher speed but again I would like to avoid changes to the board. The way
> things are I can probably dedicate the entire cpu to the serial code while
> transmitting/receiving with the exception of a TMR0 roll over interrupt that
> has been coded with minimal register save and just a simple increment of a
> counter (approx 5 instructions long), the interrupt occurs every 65535
> instructions (TMR0 is using divide by 256 pre-scaler).

Receiving will be harder, but transmitting is easily doable upto
115.2kbaud. I'd do something like this:

wait_for_tmr0:

   incfsz   TMR0,W
    goto    ready_to_send

   goto     wait_for_tmr0

ready_to_send:

   movf     port_shadow,W

   ;Start bit

   andlw    ~(1<<bTX_PIN)
   movwf    IOPORT

   CALL     delay_4

   iorlw    (1<<bTX_PIN)
   btfsc    tx_byte,0         ; bit 0
    andlw   ~(1<<bTX_PIN)

   movwf    IOPORT

   CALL     delay_5

   iorlw    (1<<bTX_PIN)
   btfsc    tx_byte,1          ; bit 1
    andlw   ~(1<<bTX_PIN)

   movwf    IOPORT

...

   ; stop bit

   CALL     delay_7

   iorlw    (1<<bTX_PIN)
   movwf    IOPORT

   return

delay_7   nop
delay_6   nop
delay_5   nop
delay_4   return


115.2 kBaud ~ 8.7uS per bit. If you dither the bit times with 8 and 9us
you can average about 8.5uS per bit and be okay.

If you situate your RX pin on either bit 7 or bit 0 of your IOPORT, then
consider this:

Search_for_start_bit
    btfsc IOPORT,7
     goto Search_for_start_bit


    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,F

    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,F
    RLF   IOPORT,W
    RLF   rx_sample1,W

That's good for about 2 bits. You'd need to repeat this code (for
rx_sample2,...) to get the other 8 bits. You'll average about 5 samples
per bit and need to then perform some clever bit decoding. It's not a
trivial piece of code (and I ain't got the time to write it right now!).

However, this snippet might be useful

   incf  x,W      ; clear consecutive 1's
   andwf x.W      ;

e.g. if x == 0xf7, then after these two instructions x will equal 0xf0.


Scott

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\03\26@072556 by Olin Lathrop

face picon face
> Before I go off and waste a bunch of time trying to do the impossible
> (but hey it may be fun), does anyone have any advice on what is the
> fastest half duplex rs323 comms I can expect to get using software only
> on a 4MHz 16f876 (using a resonator not a crystal)?

I once did a 9600 baud software UART on a 16C62A running at 160KHz.  That
was pushing the limit because it worked for transmitting, but receiving
was unreliable because of the measurement jitter on the leading edge of
the start bit.

Scaling that up to 4MHz oscillator comes out to 240Kbaud.  That means
115.2Kbaud should be quite doable assuming your oscillator is accurate
enough.  My code required constants for the oscillator frequency and the
desired baud rate, and a bunch of assembly time computations automatically
produced the code.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\03\26@073426 by Olin Lathrop

face picon face
> Oh and if anyone is interested I'm using this to
> control a home built cnc machine

If this is a one off, use a PIC with two UARTs or an external UART, or
even something like a 16F628 talking to the main PIC and acting like an
external UART.

> ... Take a look at http://www.gloomy-place.com/cnc.htm

Pretty cool!


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...