PDA

View Full Version : Serin2 Timeout



tazntex
- 13th August 2008, 14:00
Would someone please explain in simple terms on how to use the Timeout with Serin2. The PBP manual says this:

"An optional Timeout and Label may be included to allow the program
to continue if a character is not received within a certain amount of time.
Timeout is specified in 1 millisecond units. If the serial input pin stays in
the idle state during the Timeout time, the program will exit the SERIN2
command and jump to Label."

Right now I am using this:

loop1:
SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return

Would I do something like this for timeout to be 10mS and to jump to label godosomething?
loop1:
SERIN2 serpin,16780,10, godosomething,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return

Also, is it also a good idea to use the flowpin?

Thanks Everyone

mackrackit
- 13th August 2008, 15:18
Your time out code looks correct.

The flow pin depends on your application. Myself, with the things I do, 9600 baud and lower, I have not had to use it.

tazntex
- 13th August 2008, 16:16
Thanks for the reply, is there anyway to set this up for 4800bps?

mackrackit
- 13th August 2008, 17:05
Look in the manual under SERIN2, it gives a formula and a sample table. Compare this to appendix A.

skimask
- 13th August 2008, 17:41
I'm beginning to think somebody doesn't have the little green book.
And if he/she does actually have the little green book, it hasn't been opened and/or read and/or studied much...

tazntex
- 13th August 2008, 18:08
Well, looking at SERIN2 and Appendix A, with the formula being (1000000/)-20
Appendix A states:
2400 Driven Inverted None 16780
9600** Driven Inverted None 16468
taking the formula and coming up with 188.3333333333etc...
I figure by looking at the examples 16780-188=16592.

SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
changed to this:
SERIN2 serpin,16592,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
So am I correct by saying 48000 bps would be 16592?

Thank you

skimask
- 13th August 2008, 18:41
Well, looking at SERIN2 and Appendix A, with the formula being (1000000/)-20
Appendix A states:
2400 Driven Inverted None 16780
9600** Driven Inverted None 16468
taking the formula and coming up with 188.3333333333etc...
I figure by looking at the examples 16780-188=16592.

SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
changed to this:
SERIN2 serpin,16592,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
So am I correct by saying 48000 bps would be 16592?

Thank you

That's what the PDF says (what about the little green book?).
A better explanation of the bits used in the SERIN2 mode number are in the SERIN2 section itself.

tazntex
- 13th August 2008, 19:07
The little green book?
That is what I am going by, I just wanted to make certain I was doing this right. The more I play with PBP the more questions I have. Just in case ya'll have wondered I have a lot a miles on my little green book, and I still have that dumb look on my face. But thanks to you and the rest of the people in here I am begining to be able to sort things out bit by bit.

Thanks

skimask
- 13th August 2008, 19:21
Ok, just checking...
But you really have to start thinking of PICs not as a teenager that can be told what to do ('cause that's what I see), but as a 6 year old that has to be told EXACTLY WHAT to do, WHEN to do it, HOW to do it, and to know yourself WHY he/she is doing what he/she is doing and HOW he/she is going to accomplish it.
Don't assume anything will 'just work' because until you really get to know what's what, chances are that it won't 'just work'.

And I wouldn't say 'dumb' either... I'd say ignorant.
In my mind dumb (and/or stupid) means somebody has tried to teach you and you've screwed it up.
Ignorant means you just plain don't know, never seen it before, never heard of it, never thought of it, and so on.
Like until right now, you are ignorant of the fact that I have a cat. If I have to keep telling you that I have a cat time and time again, now you're just dumb...
So 'dumb look'? Nah... Just make sure you've got a towel under your mouth before you drool and slobber all over your circuit boards :D

mackrackit
- 14th August 2008, 17:47
Well, looking at SERIN2 and Appendix A, with the formula being (1000000/)-20
Appendix A states:
2400 Driven Inverted None 16780
9600** Driven Inverted None 16468
taking the formula and coming up with 188.3333333333etc...
I figure by looking at the examples 16780-188=16592.

SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
changed to this:
SERIN2 serpin,16592,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
So am I correct by saying 48000 bps would be 16592?

Thank you
Nope.

The numbers for the mode setting have been converted to decimal. We need to look at this from a binary point of view. If you do not have a handle on base2, things will be difficult with computers. The computer only understands two things, ON and OFF as in a switch, and most times with micros we can get away with thinking of 8 switches in a group, (or pins)

As you know with you PIC, the group of 8 is represented as bits 0 - 7.
With the SERIN2 modes we are talking about 16 switches, bits 0 - 15.

The table at SERIN2 in the manual gives the first 12 (0-12)bits of the mode and a formula to find this number.


Baud 0-12 bits Binary
2400 396 0000110001100
4800 188 0000010111100

Now we have bits 13 - 15.
Bit 13 is for parity. 0=None 1=Even
Bit 14 is for conversion. 0=True 1=Inverted
Bit 15 is the Output. 0=Driven 1=Open

Go to appendix A and look at Mode Number 16780. We will build this from scratch.
Bit 15 is Driven = 0
Bit 14 is Inverted = 1
Bit 13 is No parity = 0
Take bits 0-12 from above 2400 baud and put it all together.
0100000110001100
and convert to Decimal = 16780

Now for Driven Inverted None 4800.
Bits 15 - 13
010
Bits 0-12 from above 4800
0000010111100
Put it together
0100000010111100
Convert to Decimal
16572 is the Mode Number for Driven Inverted None 4800 Baud.

I hope :)

Here is a page to do the conversions.
http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html

tazntex
- 14th August 2008, 19:19
Hello,
What about SEROUT2? I am using:
serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]

and I want to increase it to 4800bps. The manual speaks of this in SEROUT2 and Appendix A,
and I think I''ve got my bugs cornered up in my other post so I wanted to go a little faster.

serout2 serpin,16592,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]

16592 about what I've calculated for 4800bps, now what do I do with the synch, its value is 254 and do I have this formated right?

Thank you

Must be something to the address when I typed it, doesn't have a space

Archangel
- 14th August 2008, 19:43
Thanks Mackrackit,
nice little tutorial.

skimask
- 14th August 2008, 19:47
Hello,
What about SEROUT2? I am using:
OPEN/LOOK IN THE BOOK!
SERIN2 and SEROUT2 are the same!!!

And a little bit more reading would show that you could also save quite a bit of typing.

This line:
serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]

could act the same as:
serout2 serpin , mode , [ REP $55\5 , REP $AA\5 , synch , REP address\2 , REP keydata\2 , chk_sum ]

mackrackit
- 15th August 2008, 01:58
16592 about what I've calculated for 4800bps
But we are not talking about hand grenades :D


now what do I do with the synch, its value is 254 and do I have this formated right?

What do you think the synch does for you? And what does all of the $55,$AA do?

The $55,$AA s are what I would call the synch(ronizing) part. This prepares the internal workings of the receiver to a "neutral" state ready to receive "highs" and "lows".

I do not see what your synch is doing for you. You could use it as the wait variable, but then you will most likely want a time-out then to go with it.

In your case I would "synch" the receiver with the $55,$AA s and send the remaining data dropping the variable holding 254.

Play with it :)

tazntex
- 15th August 2008, 15:30
Thanks for the suggestion from both of you. I started out with an example from Bruce's website, Rentron, and I my thinking was the 254 was the qualifier. So, I thought by using a qualifier one tx work be matched to its own rx then if I built two neither would interfere or operate the other. The main question I was asking was Using SERIN2 baud being 4800bps the mode would be 16572. On the receiver I would use this:
SERIN2 serpin,16572,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return

What I would like to know is using SERIN at 4800bps changing the above line for SEROUT it does not work. I see in the manual what is says for the calcultion etc for SEROUT2 but not for SEROUT. If I do this:
SEROUT serpin,16572,[wait(254),address1,address2,mydata1,mydata2,chk_su m]

Hmmm,....I hope this make sense, haven't had my coffee yet.

Thanks

BTW, Skimask, I see your point in using colons. Finding mistakes, typos etc is easier.

skimask
- 15th August 2008, 15:40
What I would like to know is using SERIN at 4800bps changing the above line for SEROUT it does not work. I see in the manual what is says for the calcultion etc for SEROUT2 but not for SEROUT. If I do this:
SEROUT serpin,16572,[wait(254),address1,address2,mydata1,mydata2,chk_su m]


And yet again, it's in the book!

SERIN/SEROUT use one style of mode, SERIN2/SEROUT2 use a different style of mode. They are wholly different...

It's in the book!