PDA

View Full Version : Strange happenings in FullDuplexSerial



william chan
07-20-2009, 09:34 PM
I don't know why, but when I change the receive buffer size from 16 to 24 bytes, the transmitted bytes using the 2 transistor circuit become erratic.
When I change both buffer sizes back to 16, the transmit works well.
Should the buffer sizes be multiples of a certain number?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my (http://www.fd.com.my)
www.mercedes.com.my (http://www.mercedes.com.my)

BradC
07-20-2009, 09:39 PM
william chan said...
I don't know why, but when I change the receive buffer size from 16 to 24 bytes, the transmitted bytes using the 2 transistor circuit become erratic.
When I change both buffer sizes back to 16, the transmit works well.
Should the buffer sizes be multiples of a certain number?


Aside from changing those numbers in the tx & rx buffer size, what other changes did you make to the object to let it properly mask and wrap the buffers?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<This space for rent>

Nick Mueller
07-20-2009, 10:11 PM
Full duplex serial only takes powers of two and you'll have to tweek the ASM to to get rid of the magic numbers.


Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO (http://www.yadro.de)

william chan
07-21-2009, 03:58 PM
Thanks nick.
That was the answer I needed.

I think there should be a comment near the buffer settings to warn the user to use only powers of two.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my (http://www.fd.com.my)
www.mercedes.com.my (http://www.mercedes.com.my)

william chan
07-29-2009, 06:09 PM
I am really confused now....
I am running Propeller at 40mHz and 19.2k baud.

I set both the receive and transmit buffers to 32 bytes each.
The transmit no longer works. Isn't 32 a magic number?

I set both buffers back to 16 bytes and everything works again.
I double checked and triple checked.

What could be wrong?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my (http://www.fd.com.my)
www.mercedes.com.my (http://www.mercedes.com.my)

Nick Mueller
07-29-2009, 06:28 PM
Did you change the magic numbers?
It's not enough just to change the buffer size, you'll also have to look for the masks ($F)!

Frankly speaking, thats an example of very bad coding-sytle. Instead of declaring a single constant like bufferLen = 16, there are several incarnations with some deviation that could be derived from that constand (for example "bufferLen - 1").

"Magic Numbers":
The meaning is, that there are pure numbers spread in the code that aren't depending on some constant. In this example, it's the number "16" or the matching mask $F


> 40mHz

Thats damned slow! http://forums.parallax.com/images/smilies/wink.gif


Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO (http://www.yadro.de)

Post Edited (Nick Mueller) : 7/29/2009 10:35:33 AM GMT

JonnyMac
07-29-2009, 10:54 PM
The attached update seems to work fine. I marked all the lines (8 of them) I changed (with *) -- it's possible you may have missed one or two when you attempted the update.

Mike Green
07-29-2009, 11:19 PM
There are several "improved" versions of FullDuplexSerial that use named constants for the "magic" values so make it easy to change the buffer sizes to other powers of two. There's also a serial driver that uses cog memory for the buffers.

Nick Mueller
07-29-2009, 11:32 PM
Here's a better explanation than mine:
<http://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_const ants>


Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO (http://www.yadro.de)