Reading SERIN whilst running other operations


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    6

    Smile Reading SERIN whilst running other operations

    I have a simple program that listens on a port for serial commands using SERIN. It then activates one of 8 relays depending on the serial input.

    I need my PIC (currently a 16F84) to also be running another part of the program at the same time. (Ideal) However it seems that when my program reaches a SERIN command it just sits there, the whole program pauses and waits for data.

    I now need my pic to also be counting away in the background and activate a relay after a duration of no serial activity. I know PICs are not multithreaded (well atleast the 16F84).

    Is there a more advanced PIC that can do this? Ideally I need a solution that can fit into a 18Pin DIL.

    My question at this stage is, is it possible with an adjustment to my existing pbp code? If so, does anyone know of a working example of this kind of thing practice.

    Many Thanks,

    Dan
    Last edited by Dan_lay; - 29th October 2007 at 13:30.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    You may want to change to SERIN2 and then use the time out /wait.
    Code:
    SERIN2 PORT, BAUD,  TIME OUT, LABEL to goto, [WAIT(?) xyz]
    Or use an interrupt, but the time out will cause the code to jump someplace else after a given time if the wait character is not seen.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343

    Default

    Double post
    Last edited by SteveB; - 30th October 2007 at 18:59. Reason: Double post

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343

    Default If it were me....

    I'd use one of the following chips... 18F1220,18F1230,18F1320,18F1330. (the difference between these is programs space and 4 vs 2 timers).

    Why, you ask? For starters..
    - Cost wise they look about the same, maybe cheaper than the 16F84 (just from looking a Microchips Web site), and its pin compatible (MCLR, Vss, Vdd, OSC pins are the same).
    - They have harware Serial (USART) built in, allowing an interrupts or polling of the RX bit (more on this later, as it is the most valuable IMO).
    - It can run at a faster clock if needed to keep up with tasks and speed up the baud rate if needed
    - It has more memory available
    - It has more timers
    - It has an expanded instruction set (although this is likely transparent when using PBP)
    - And other minor things...

    Once I had this chip, I would use the built in hardware USART and either ...
    1) use Darrel Taylor's Instant Interrupts or
    2) Poll the RX bit flag a periodic intervals (based on buad rate and the tasks the uP is working).
    Either of these would allow for monitoring the serail comm "in the background" while the uP is accomplishing it's timing and control of the relays and other stuff.
    The timers can be set up to keep track of the duration of no serial activity, time changes in the relays, etc.

    Based on you rough outline, my basic plan of attack would be:
    - Get a heart beat (flash an led to make sure all is well with proto setup)
    - (I may set up a serail lcd to help in debugging/development if I had a spare pin and lcd)
    - Set up the basic USART and get comm working
    - Set up the USART interrupt/polling to catch the comm while blinking led
    - Set up the Timers for accureate timing
    - Finish of logic for relays to get them switching at the right times

    HTH,
    SteveB

Similar Threads

  1. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  2. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  3. Serin / Serin2 / Debugin Differences
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th January 2006, 06:32
  4. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts