PDA

View Full Version : Reading SERIN whilst running other operations



Dan_lay
- 29th October 2007, 14:28
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

mackrackit
- 29th October 2007, 22:48
You may want to change to SERIN2 and then use the time out /wait.


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.

SteveB
- 30th October 2007, 19:53
Double post

SteveB
- 30th October 2007, 19:58
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 (http://www.picbasic.co.uk/forum/showthread.php?t=3251) 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