Shop OBEX P1 Docs P2 Docs Learn Events
one cog doing multiple UARTs — Parallax Forums

one cog doing multiple UARTs

rich314rich314 Posts: 1
edited 2006-09-22 05:27 in Propeller 1
Is is resonable to have one cog doing multiple UARTs concurently?

That is init a COG to setup UART0 for output on pin-x and UART1 on pin-y.

Next send bytes to the UART COG from another COG, for for either UART to send or recieve, and UART COG takes care of both seial stream setting flags when ready/busy.

Does one COG have enough perfomance to run multiple UARTS?
Is there a way to signal ready/busy/done between COGs?

Thank you for your time.
Obviously i am COG ignorant.

cheer,
rich

Post Edited By Moderator (Chris Savage (Parallax)) : 9/26/2006 10:37:49 PM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-09-22 04:53
    Rich,

    Yes, absolutely. It would probably need to be done in assembly to be fast enough. But as long as each input can be sampled regularly at some reasonable multiple of the baud rate (3x being the minimum), and each output serviced at the baud rate, it will work.

    The handshaking between cogs can be done with pointers into the I/O buffers, which will reside in hub memory.

    -Phil

    P.S. You may want to edit your original post with a title, so the subject matter appears on the forum page.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-09-22 04:58
    If you are using 9600 baud, the time for each bit is 104uS (1/9600).

    Running a cog at 80Mhz, gives you 20MIPs in Assembler.

    At 20MIPs, 2080 instructions can be performed in the span of 1 bit.

    A typical hardware UART has a clock 16x the baud rate for sampling the data.

    At that, you still perform 161 instuctions between each sample (if you even want to worry about sampling that much)

    I'd say there's sufficient time there to get at least a few UARTS in one cog, though dealing with multiple streams will get a little tricky.

    Depending how you use your I/O, you can always dedicate some line for inter-cog signalling. A slower way is to use a global variable in shared RAM, but then you have to deal with the Hubs timing.

    -my 2 cents
    Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
    AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-22 05:05
    It would be possible to have one cog provide several UARTs if they were running at the same speed (Baud) and the routines were written in assembly. It makes the coding much much more complicated and requires much higher performance to do more than one UART at the same time. For example, you can provide a half-duplex UART (transmit or receive, but not both at once) written in SPIN that runs up to 9600 Baud. In assembly language, you could handle in excess of 1MHz. By setting up time slots for each UART, you could probably handle 4 full duplex UARTs at 9600 Baud in a cog. As is true of any COG to COG communication, it has to be done through the common HUB memory. Each UART would probably have a buffer, maybe 16 characters along with status/configuration information. Any transferring of data between COGs would be done by one or more other COGs, probably in SPIN.

    I don't recommend doing multiple serial channels this way unless it can't be done reasonably any other way. It's so much easier to do it when you devote a single COG to the task and the code already exists in both SPIN and assembly.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-09-22 05:27
    Accommodating multiple baud rates would not be that difficult. You just need to service each I/O at the maximum rate and decrement a counter for each one. When the counter reaches zero, do something and reset the counter; if not, wait for the next tick and move on to the next I/O. Further throughput can be realized by interleaving the outputs, which only need to be serviced at the actual baudrate -- not a multiple. To do four I/Os at 4x baud for the inputs and 9600 baud max would require a complete loop-thru at 38.4KHz or 520 instructions for four input service routines and one output service routine -- about 100 instructions per "tick". This is well within the realm of reason.

    -Phil
Sign In or Register to comment.