PDA

View Full Version : Skip incoming bytes in SERIN



Alexey
- 24th July 2010, 03:50
Hi Guys,

Could someone advise please how can I skip some bytes when read a stream using SERIN? The chip I use does not support serin2 or hserin and it's program memory is too small, but I noticed that skipping bytes by using something like
SERIN PORT,MODE,["CHAR"],BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE
uses too much program memory for skipping bytes. Is there a better way?

Thank you,
Alexey

mackrackit
- 24th July 2010, 04:21
Welcome to the forum.


The chip I use does not support serin2 or hserin
What chip are you using?
It may not have a USART but I can not think why SERIN2 would not work on any chip.

Alexey
- 24th July 2010, 04:39
Hi Mackrackit,

Thank you.

It is PIC16HV540.

it has only 512 words of program memory, 25 bytes or RAM (enough for only three variables) and nothing else. BUT it is 15 volt chip including full 8 bit 15 volt port B (actually I use only two lines of them)

mackrackit
- 24th July 2010, 04:47
It is PIC16HV540.

it has only 512 words of program memory, 25 bytes or RAM (enough for only three variables) and nothing else. BUT it is 15 volt chip including full 8 bit 15 volt port B (actually I use only two lines of them)

Oh....
I will need to think about that one...

mackrackit
- 24th July 2010, 12:24
This is interesting. I have never used a chip this "small"....

What does the data stream look like and what part do you want to skip? Then what do you want to do with it?

Alexey
- 24th July 2010, 22:12
it is a repeating string and the bytes I need are located 9 bytes after symbol 85. Ideally there are 7 bytes I want to know but I have room only for three variables, so I may have to read them one by one every next sycle or use only the first one as it is most important and I only need to ignite a warning LED at certain read value. Now I do it this way:
SERIN PORTB.3,T2400,4000,CLR,[85],VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR

Skipping 9 bytes cost me 45 words of memory which is near 9% of what I have totally

Yes, this chip is very small, but I could not find another one with at least one 15 volt port (regular or open drain) to read and write serial data directly

mackrackit
- 25th July 2010, 07:33
Well I am stuck...
Why not use another chip and a MAX232? Then the data could be pulled into an array.

Darrel Taylor
- 25th July 2010, 08:45
SERIN PORTB.3,T2400,4000,CLR,[85],VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR,VAR

Skipping 9 bytes cost me 45 words of memory which is near 9% of what I have totally

Hi Alexey,

This program compiles to 124 words with a 16HV540.

INCLUDE "modedefs.bas"

RX VAR PORTB.3
B0 VAR BYTE

SERIN RX, T2400,[85]

This one is 154 words.
INCLUDE "modedefs.bas"

RX VAR PORTB.3
B0 VAR BYTE

SERIN RX, T2400,[85],B0,B0,B0,B0,B0,B0,B0,B0,B0,B0


But this one using DEBUGIN is only 75 words.

DEFINE DEBUGIN_REG PORTB ' Debugin pin port
DEFINE DEBUGIN_BIT 3 ' Debugin pin bit
DEFINE DEBUGIN_MODE 0 ' Debugin mode: 0 = True, 1 = Inverted
DEFINE DEBUG_BAUD 2400 ' Debug baud rate

B0 VAR BYTE
MyData VAR BYTE

DEBUGIN [WAIT(85)] ' wait for 85
FOR B0 = 1 TO 9
DEBUGIN [MyDATA] ' skip 9 bytes
NEXT B0
DEBUGIN [MyDATA] ' get the desired byte

IF only I had a 16HV540 to test it on. :rolleyes:

mackrackit
- 25th July 2010, 10:02
Thanks again Darrel,
I never even thought to try DEBUGIN and I certainly did not realize how compact it is.
Another entry in the note book.

Darrel Taylor
- 25th July 2010, 22:20
For the longest time I completely ignored the DEBUG/DEBUGIN statements because it just seemed too much like a Basic Stamp command. :p

Then I saw Bruce using them a lot and took another look.

They really are better than SERIN/OUT, SERIN2/OUT2.
As long as you only need one baud rate and fixed pins ... which fits probably 90% of the usual serial programs.

Smaller, faster ... better.

aratti
- 25th July 2010, 22:43
Hi Darrel, with a loop of 10 cycles the last MyData will contain the desired byte saving one line instruction. (Assume something less than 75 words)



DEFINE DEBUGIN_REG PORTB ' Debugin pin port
DEFINE DEBUGIN_BIT 3 ' Debugin pin bit
DEFINE DEBUGIN_MODE 0 ' Debugin mode: 0 = True, 1 = Inverted
DEFINE DEBUG_BAUD 2400 ' Debug baud rate

B0 VAR BYTE
MyData VAR BYTE

DEBUGIN [WAIT(85)] ' wait for 85
FOR B0 = 0 TO 9
DEBUGIN [MyDATA] ' skip 9 bytes
NEXT B0
'Last MyDATA will contain the desired byte

Darrel Taylor
- 25th July 2010, 22:53
Hi Darrel, with a loop of 10 cycles the last MyData will contain the desired byte saving one line instruction. (Assume something less than 75 words)


Excellent!
Didn't see that.

And the compiler says ... drumroll ... 72 words.
Aww, I thought it would save more than 3. :)

Bruce
- 25th July 2010, 23:32
If you're not using Timer0, set it up for external clock, strap T0CKI to ground, and you have yourself a spare byte variable.

Alexey
- 26th July 2010, 03:20
Wow! Gentlemen,

Thank you for such great help. This saved me 94 of 512 words of memory, so I now can think about adding some other features. Will try how it works in reality this week and let you know.

Another option could be going with another chip and additional driver chip to interface to a 14 Volt serial I/O line, but this makes the electrical schematic bigger, so I prefer to stay with this chip if possible.

My understanding is that using DEBUG I will still be able to use the same pin as output before and after the DEBUG.

Will need to learn more about the TIMER0 and how to configure to save space for one more variable because although I can live without it, it is still good to have. I have to use resonator for having precision timing, not sure it makes a difference or not.

Thanks again!

Thanks again

Alexey
- 3rd August 2010, 05:21
Hello Gentlemen,
Checked the Debugin with PIC16F540 and yes, your advise works great, I could read the port and output high and low impulses into it between the serial input.

Could not find out so far how to reduce use of RAM to get space for one more variable, but at least have enough memory for code now.

Thank you very much

HenrikOlsson
- 3rd August 2010, 07:17
Hi,
I think that is what Bruce was trying to help you with. TMR0 has a byte sized register that you can read and write just like any other variable. If you don't use TMR0 for its intended purposes you can "borrow" its register and use as a normal variable.

So instead of declaring B0 as a BYTE and use that you simply use the TMR0 "variable".

MyData VAR BYTE

DEBUGIN [WAIT(85)] ' wait for 85
FOR TMR0 = 0 TO 9
DEBUGIN [MyDATA] ' skip 9 bytes
NEXT TMR0
'Last MyDATA will contain the desired byte

If you want you can create an alias for TMR0 like any other variable:

B0 VAR TMR0 Now reading and writing B0 will actually read and write TMR0. Personally I think spelling out TMR0 in the code better shows what is actually going on though.

I hope that helps and that it is what Bruce was thinking.

/Henrik.

Alexey
- 4th August 2010, 06:18
Thank you Henrik, Bruce,

Yes, Bruce was trying to advise this, but I am not as smart in micro controllers as you guys are, so I was going a wrong way thinking there is a way to configure timer somehow and prevent PBP from using some RAM for things related to the timer.

Thank you for clarifying this for me