@bptrinc & OR @bptr OR I've looked at this too long

After removing all but the bare essentials from my project I still have the problem. The first character I send into the 20M2 through an ICL232 (MAX232 equivalent) goes through fine. The following characters are mangled. I've tried different 20M2 frequencies, different chips and different baud rates all with the same result. According to my O'scope and logic analyzer the data is going through the ICL232 chip fine and shows up on the 20M2 input pin very clean. And noise doesn't seem to be the issue for another reason, namely, the output is always the same, but always wrong (after the first correct character). I had this code working with a different prototype but I must have done something that I just don't see after I adapted it to this project.

It's just two serial cables, one going in and the other coming out. I've tested the two serial ports I'm using with this project by crossing them back-to-back (without my circuit in between) and data goes both ways nicely so my serial ports seem to be good.

What am I missing? Any help would be appreciated.

Code:
#picaxe 20M2
#no_data
#terminal off

'--------------------------------setup---------------------------------------
SETFREQ m32
dirsB = %11111111
dirsC = %11111011
SYMBOL char	= b0			; character holder for IO

'--------------------------------I/0-----------------------------------------
SYMBOL LoopOut 	= B.6			;Serial out to Blue cable
SYMBOL C40SerIn	= C.2			;HW Serial TX to C40
SYMBOL C40baud = T38400_32	;C40 Serial baud rate xxxx,N,8,1 @ 16 MHz

'-------------------------------init-----------------------------------------
init:
pause 1000 				;wait for something to initialize
high LoopOut
'---------------------------------main------------------------------------------
main:
	gosub getInputString
	gosub textToBlue
	pause 1000
goto main			' main loop

'----------------------------getInputString-------------------------------------
getInputString:
bptr = 28         			' begin storing data at location 28 just above b27
serin C40SerIn,C40baud,@bptrinc' no timeut; so wait for the FIRST CHAR
serin [800], C40SerIn, C40baud, @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
			            	' and all that inputs <= FOURTY MORE CHARS
@bptr = 0        		      	' 0 is the end of transmission marker,
bptr = 28        		      	' Reset byte pointer to the first location
return

'------------------------------textToBlue---------------------------------------
textToBlue:
do until @bptr = 0            	' loop until we reach the EOT character(0)
    char = @bptrinc           	' get each byte
    serout LoopOut,C40baud,(char);send chr to Blue Cable
loop                          		' done looping
return
 
While you say you have tried different baud rates, have you tried a low speed such as 600 or 1200 baud as a test.

My though (=guess) is that with the 38400 baud rate and trying to receive 40 characters in a row, it they are being sent without any pause between for the transmitting device, that is not giving your 20M2 PICAXE chip much time to receive a byte value, store it in RAM memory and return for the next byte.
Without having done any speed tests, with your 20M2 operating at 32 MHz it may be taking around 0.03 ms to save a byte to RAM while if there are no pauses/delays between bytes to be received each bit at 38400 baud is 0.026 ms in duration leading to loss of bits received. Thus data transmission speed could be the culprit.

You are using one SERIN command to detect the first character and then a second SERIN command to accept the rest of the data.
Again it can take some time (maybe around 0.05 ms) to complete the first SERIN command and initiate the second command and unless there is a delay, data can be lost between the two commands.

Without knowing the reasoning behind the use of two SERIN commands, first held waiting a character and the second with a time out, can you use one SERIN command with a qualifier in stead of two separate commands ?
 
Usually a speed problem. TX too fast or RX too fast.

Try adding some delays then working the delays down until you find the pinch point.
 
Without knowing the source of the serial data, I will assume that the baud rate is precisely 38400 coming in.

Having tested several 20M2's for accuracy with a good digital scope, the tests show that a 20M2 @32Mhz & serin set for T38400_32 ....that the actual center baud rate for serin is 40590 ( > 5% error) and the lowest baud rate that can be received reliably is 38540.

This is way out of acceptable tolerance limits, and means that there will be problems at an actual received baud rate of 38400. However, using 'calibfreq -15' on the 20M2, allows an actual baud rate of 38400 to be received ok. This will also help to bring the errant 20M2 serout rate of 39500 (actual) down closer to the nominal desired rate of 38400.

However, with your code ... Having two serin commands back to back like that means that unless there is sufficient pacing between characters, the second byte will be coming in before the second serin command is executed, causing corrupted data and loss of sync for the reset of the data packet. Data after the first byte will be corrupted.

This can be overcome by putting a short pause after the first byte sent (on the sending device). So it sends the first byte, waits 1 ms then sends the rest of the bytes consecutively. I tested this to work ok with your code.

If this cannot be done for some reason, then only use one serin command for all bytes.
 
Last edited:
namely, the output is always the same, but always wrong (after the first correct character).

Add some extra code and perhaps SERTXD's that can report exactly what was received and whether the second SERIN is timing out or not.
 
If the first byte is received reliably then there is no problem with the baud rate timing and calibfreq is not required. If one bytes works then they will all work, as the firmware re-syncs on the start bit on each byte.

The main problem with sending 40 bytes of data at this speed is the firmware will need time to 'save' the value in the scratchpad before the next byte comes in. When you run at a higher baud rate you simply reduce the amount of time between bytes, eventually getting to a point where the firmware can't keep up. There are generally two solutions - at the transmitting end add a gap between bytes, or use a lower baud.

Or migrate to a 20X2 and use hserin instead, which can cope with back to back data at this speed.
 
<...>I had this code working with a different prototype but I must have done something that I just don't see after I adapted it to this project.
<...>

@vectorspace ... In 35 years, I have heard the above statement far too many times. Big software projects use COTS software source-safe products to do revision control. On your local PC, you are in control, however. You must discipline yourself to keep all edits separate on the hard drive and when a project is complete, you can elect to do the 'clean-up' at that time... or, as I do, you may elect to ZIP every one of those revisions into a single archive and put it on the external drive that is use for (automated) nightly backups.

May I offer a suggestion, every revision should be saved with a new, unique file name. I use a very simple convention for naming the files, YYYYMMDDnn(Space)<filename>.BAS but it really does not matter, just pick something you like and stay with it religiously.

- Ray
 
There are generally two solutions - at the transmitting end add a gap between bytes, or use a lower baud.

Thanks everyone for the replies. This is really a great group here!

The source is a piece of commercial equipment and I have no control over the baud rate or timing of bytes sent from it.

During testing (using Realterm on a PC as input, not the actual equipment I'll use when done) I tried several different rates down to 4800. I was thinking that if the baud rate or timing was an issue then I would see different errors at different speeds. The errors were always the same (the same incorrect characters in the same order came out each time). And the 20M2 clock speed made no difference, the same incorrect characters were stored at 8MHz, 16MHz and 32MHz.

My plan, once the code is working, is to move the function of receiving the serial input to an 08M2 which would do nothing but get the serial input and, based on the first eight characters, 'tell' another processor what command it received. The other processor would be doing other things while the 08M2 was waiting for a command. Then the other processor could perform an action appropriate to the command received and the 08M2 could go back to waiting for another command.

The strings coming in will be over 100 characters long (different lengths, depending on the command) but I can distinguish between them by looking at only the first eight characters.

I don't have a 20X2 on hand to try. I'll get a few if that's the only fix.

I added code to count the characters received and to sum the byte values of the first eight. The count is always correct. When more than one character is sent, the sum indicates that the second SERIN is NOT timing out but the values stored (and then read back from memory in order to sum them) are incorrect.

For some reason, the incorrect stored characters are always very high numbers as if the most significant bit or two were being received as 1 instead of a zero, but that may just be coincidence.

Would using HSERIN on C.1 of an 08M2 get the bytes into memory any faster?
OR, would SERRXD on C.5 of an 08M2 get the bytes into memory any faster?

I'll do another capture with the logic analyzer and look at the inter-byte timing to see what I can find there.

Thanks again for the replies.
 
Without knowing the reasoning behind the use of two SERIN commands, first held waiting a character and the second with a time out, can you use one SERIN command with a qualifier in stead of two separate commands ?

Thanks! The serial input I'm trying to read is of an undetermined length. It could be 3 bytes, or between 120 to 175 bytes. The first SERIN without a timeout sits and waits for ANY input, and the second SERIN with the timeout gets any additional bytes (up to 40 more) but doesn't wait forever if it only gets one or two more, or no more at all.

I really only need the first eight bytes but I pulled the code from another project and it had 41. Since I get an error after the first character, I figured 8 or 41 wouldn't make much difference.
 
The source is a piece of commercial equipment and I have no control over the baud rate or timing of bytes sent from it.

As Technical suggest an X2 using background receive is probably most appropriate for such a case. With large data packets the 28X2 with its 1024 byte buffering may be better than a 20X2 which has a shorter 128 byte buffer.

The M2's have HSERIN buffering but far less than the X2 so you can hit the same problems as you have with SERIN in not being able to keep up with data arrival, especially at high baud rates as we have here; at 38400 baud a new byte may turn up every 260us.
 
If the first byte is received reliably then there is no problem with the baud rate timing and calibfreq is not required. If one bytes works then they will all work, as the firmware re-syncs on the start bit on each byte.

Having done extensive testing with Picaxe micros at all serin/serout baud rate/frequency combinations, I can confidently say that this is not always true.

A common symptom when the baud rate is on the edge of tolerance is that the first byte or first few bytes may be received ok, then the serin loses sync and then random bytes after that appear to be garbage. As it gets further out of tolerance 'sometimes' only the first byte is received ok.

Below is the OP's original code with modifications to see the results via sertxd. Only one serin command is used for all 40 bytes.
Code:
#picaxe 20M2
#no_data
#terminal 38400
#com 1

'--------------------------------setup---------------------------------------
SETFREQ m32
dirsB = %11111111
dirsC = %11111011
SYMBOL char	= b0			      ;Character holder for IO
calibfreq -15

'--------------------------------I/0-----------------------------------------
SYMBOL LoopOut 	= B.6			;Serial out to Blue cable
SYMBOL C40SerIn	= C.2			;HW Serial TX to C40
SYMBOL C40baud = T38400_32	   ;C40 Serial baud rate xxxx,N,8,1 @ 16 MHz

'-------------------------------init-----------------------------------------
init:
pause 1000 				;wait for something to initialize
high LoopOut
'---------------------------------main------------------------------------------
main:
	gosub getInputString
	gosub textToBlue
	pause 1000
goto main			' main loop

'----------------------------getInputString-------------------------------------
getInputString:
bptr = 28 'Begin storing data at location 28 just above b27
          ' and all that inputs <= FOURTY MORE CHARS
  
'[COLOR="#008000"] serin C40SerIn,C40baud,@bptrinc  'No timeut; so wait for the FIRST CHAR[/COLOR]
serin C40SerIn, C40baud, @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
@bptrinc,@bptrinc,@bptrinc
			            	      
@bptr = 0   ' 0 is the end of transmission marker,	       		      
bptr = 28   'Reset byte pointer to the first location	     		      	
return

'------------------------------textToBlue---------------------------------------
textToBlue:
do until @bptr = 0            	' loop until we reach the EOT character(0)
    char = @bptrinc           	' get each byte
    sertxd (#char," ")
   [COLOR="#008000"] 'serout LoopOut,C40baud,(char);send chr to Blue Cable  'remed by Goey[/COLOR]
    
loop 	' done looping
sertxd (cr,lf,cr,lf)  [COLOR="#008000"]'added by Goey      [/COLOR]                 	
return


The data is sent to the 20M2 with a Picaxe 20x2 usin hardware serial set to 38400. The baud rate of the sent data was measured to be 38440 baud. Below is the 20x2 code for sending 40 consecutive bytes of data to the 20M2.
Code:
#Picaxe 20x2
setfreq m32
hsersetup b38400_32,%000

do 
hserout 0,("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU")
pause 5000
loop

Below is the output of 4 packets with the 20M2 with calibfreq set to zero. Note that that the FIRST BYTE is received ok while the bytes after may or may not be corrupted.

85 85 213 85 85 85 85 85 85 213 85 213 85 85 85 85 85 85 85 213 85 213 85 213 85 213 85 85 85 85 85 85 85 213 85 213 85 213 85 213

85 85 213 85 213 85 213 85 213 85 85 85 85 213 85 85 85 85 85 85 85 85 85 213 85 213 85 85 85 85 213 85 213 85 213 85 213 85 85 85

85 85 85 85 85 85 85 85 85 85 213 85 213 85 213 85 85 85 85 85 85 85 85 85 213 85 213 85 213 85 85 85 85 85 85 85 85 85 85 85

85 213 85 213 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

Below is the output of 4 packets with calibfreq on the receiving 20m2 Picaxe set to -15. Note that all data is now good

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

These two tests clearly show a baud rate problem with serin on the 20M2.

==============================================================================

Now with the serin baud rate somewhat corrected with calibfreq -15 the 20M2 code was returned to having two serin commands back to back. Below is the result.

85 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 253

85 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 253

85 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 253

85 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 253

Note that the first byte is good and the rest "corrupted" but consistent. This is because the second byte was coming in as the second serin command was executed and serin is syncing to a bit in the middle of the second byte. So serin is seeing part of one byte and part of the next as the actual received byte.

====================================================================

Next, a 250us pause was added between the first byte sent and the next 40 bytes sent on the sending code. The sending code now looks like this.

Code:
#Picaxe 20x2
#terminal 38400
#com 6
setfreq m32

hsersetup b38400_32,%000

do 
hserout 0,("U")
pause 2
hserout 0,("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU")
pause 5000
loop

Here is the result in the terminal

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

It now works fine with no corrupted data.

There are two problems. One is the inaccuracy of serin on the 20m2 when set to M32 and 38400 baud. The second is having two back to back serin commands with no space between the first byte and the rest of the bytes.

I would suggest setting calibfreq to -15 to compensate for the serin baud rate error of the 20M2, and then using only one serin command as already suggested. Even better would be to use a 20X2 with background receive.
 
Last edited:
A common symptom when the baud rate is on the edge of tolerance is that the first byte or first few bytes may be received ok, then the serin loses sync and then random bytes after that appear to be garbage. As it gets further out of tolerance 'sometimes' only the first byte is received ok.

That's not necessarily the timing out of tolerance as the receiver resynchronises timing to the leading edge of every start bit. If the PICAXE is late for a start bit it will then synchronise on some other bit and hence corruption.

That can be seen with the example where you use no CALIBFREQ but add a pause between first and second character sent; the 20M2 receives everything without error.

When that pause is taken out corruption occurs on the second or subsequent character and that's because it's back-to-back data the SERIN cannot handle quickly enough, misses a start bit at some point.

Add a CALIBFREQ and it's likely the making the PICAXE run faster which allows it to be ready sooner for the start bit which is solving things, not altering the baud rate.

Added : Note the 213 error. That's likely a missed start bit error ...
Code:
                 ___   _   _   _   _   _____
85,  %01010101      |_| |_| |_| |_| |_|
                     S 1 0 1 0 1 0 1 0 P
                 ___   _   _   _   _   _____
213, %11010101      |_| |_| |_| |_| |_|
                         S 1 0 1 0 1 0 1 1 P

That could be more clearly demonstrated by sending $05 than $55 as slight baud rate error should only change the msb or not be noticed but a missed start bit will lose the original lsb and set both msb's ...

Code:
                 ___   _   _           _____
5,   %00000101      |_| |_| |_________|
                     S 1 0 1 0 0 0 0 0 P
                 ___   _   _           _____
193, %11000001      |_| |_| |_________|
                         S 1 0 0 0 0 0 1 1 P
 
Last edited:
Having done extensive testing with Picaxe micros at all serin/serout baud rate/frequency combinations, I can confidently say that this is not always true.

A common symptom when the baud rate is on the edge of tolerance is that the first byte or first few bytes may be received ok, then the serin loses sync and then random bytes after that appear to be garbage. As it gets further out of tolerance 'sometimes' only the first byte is received ok.
.....
These two tests clearly show a baud rate problem with serin on the 20M2.

You still haven't quite grasped it. There is no 'cumulative error' to get 'further out of tolerance'.
As long as the PICAXE firmware can get back to checking the start bit before it actually comes, then that byte will work. It doesn't matter if it is the first byte or the 100th byte. The most cumulative error there can ever be is 9 bits (start bit + 8 data bits). When the next start edge is detected the cumulative error is reset to 0.

As Hippy states, you are seeing what you do because the firmware simply doesn't get back in time to see the start bit edge. This is due to varying length of time to do the 'saving' of the byte within the firmware. It misses the start edge, then picks up the next edge as the start bit in error.
Increasing calibfreq speeds up the processing time between bytes, so marginal timing works better. But it does not mean the baud rate setting does not work without a calibfreq. You do have to remember you are overclocking the chip 8x from the recommended default clock frequency.

It is the gap beteen bytes, not the sampling of the byte, that matters here. Using hserout on the 20X2 gives no interbyte gap at all. What happens if you repeat your test using serout instead?
 
You still haven't quite grasped it.

No. You still haven't grasped it and, for whatever the reason keep dancing around and obfuscating the severe serin/serout accuracy problems related to 20X2 and 20M2 as has been documented by me and others.

Increasing calibfreq speeds up the processing time between bytes, so marginal timing works better. But it does not mean the baud rate setting does not work without a calibfreq.

I decreased calibfreq rather than increase it which slowed down the processing time between bytes. With this change, unlimited consecutive bytes could be received without error where previously they could not. This suggests you are incorrect in your above assessment of this particular issue.

I suggest that is it time for you (Rev Ed) , to get out of the theoretical armchair, lay aside the company line on this issue, and get a good digital scope or logical analyzer and do some actual testing.
 
Last edited:
This is turning out to be quite instructional.

And missing a start bit would be a good explanation for this:

For some reason, the incorrect stored characters are always very high numbers as if the most significant bit or two were being received as 1 instead of a zero, but that may just be coincidence.


I do have a 28X2 at home. Hopefully tonight I'll have a chance to see the behavior after adding the "calibfreq -15" and then I'll rewire it using a 28X2. I just ordered three more so I should be ready to go. Thank you all, I'll let you know what happens.
 
I suggest that is it time for you (Rev Ed) , to get out of the theoretical armchair, lay aside the company line on this issue, and get a good digital scope or logical analyzer and do some actual testing.

One of the problems is that when we do test we don't see the problems you and others do.

I have just run the exact code in post #11 on my 20M2 for the receiver/reporter, 20X2 for the sender, and everything is fine, no corruption whatsoever, whether no CALIBFREQ or CALIBFREQ -15 in the receiver. Also tested with 28X2 and EM32 as sender and same results. Both have an actual transmitted baud rate of 38430.

That's not company line, that's what I'm seeing,what I've seen in previous testing. I agree you are seeing something different and why that is not clear.

Edit : What's the temperature ? According to Google it's 31C/87F in Austin, here it's 19C/66F.

And what does the following code give as a pulse on HSEOUT pin ?

Code:
#Picaxe 20M2
HSerSetup 999, 0
Do
  HSerOut 0,($FE)
  Pause 100
Loop

It should I believe be a 2ms / 2000000ns pulse in a perfect world, mine gives 2000250ns. Which I make +0.0125% error
 
Last edited:
N
I suggest that is it time for you (Rev Ed) , to get out of the theoretical armchair, lay aside the company line on this issue, and get a good digital scope or logical analyzer and do some actual testing.

There is no company line, our comments are simply made upon hundreds of hours of testing and extensive use of logic analysers and other extremely accurate test equipment.
As hippy states, we have tested 20X2 and 20M2 chips over and over again, and have found no fault, apart from the 20X2 C.0 issue with bytes too fast for an LCD. Once again this is not a fault with the baud timing, it is a fault with the bytes being sent back to back too fast for the LCD to keep up. By introducing a slightly longer delay this allowed the serial LCD modules to keep up.

In fact a while back when people said they needed to use large negative calibfreq values we actually discovered that due to a bug in the M2 compiler a negative calibfreq of any value was not parsed correctly, was hence not processed by the firmware, and was making no difference whatsoever to the internal clock speed of the chip! Although we are not proud of the fact that there was a bug in the M2 compilers (fixed in compiler version 2.2, PE5.5.0) it proved to us 100% that, despite what people 'thought' calibfreq was doing to the 20M2 serin timing at that time (pre 5.5.0), it was not, it simply can't have been as it wasn't even being processed as a negative number!

The manual has also clearly had this serin statement for several years, which directly applies in this case:
Note that the microcontroller may not be able to keep up with processing complicated
datagrams at higher speeds - in this case it is recommended that the transmitting
device leaves a short delay (e.g. 2ms) between each byte.
 
Last edited:
@Hippy

The temperature in my lab stays between 77F and 78F. I don't test outdoors in the heat.

According to my tests 20M2 serin is at the edge at 32Mhz and 38400 Baud. A better test to see how the 20M2 or any device deviates may be to send several 16 byte data packets starting at 10 percent below nominal and increase the baud rate gradually until several packets are received without error. This establishes the lowest marginally reliable baud rate that can be received. Then increase the incoming baud rate gradually again until there are data errors. This establishes the highest marginally reliable data rate that can be received. The center is then established by averaging the two results. This is how the numbers were derived here and in THIS THREAD

My guess is that if you repeated your tests with calibfreq 1 or calibfreq 2 on the 20M2 that you would begin to get data errors. This suggests that the serin nominal is too high and it is marginal at 38400. One would think that if the serin calibration was dead on that calibfreq +5 or calibfreq -5 would have no effect. But such is not the case. And as I am sure you are aware, the Picaxe frequency will increase with heat and in the case of 20M2 serin will exacerbate the problem as the chip warms up.

In fact a while back when people said they needed to use large negative calibfreq values we actually discovered that due to a bug in the M2 compiler a negative calibfreq of any value was not parsed correctly, was hence not processed by the firmware, and was making no difference whatsoever to the internal clock speed of the chip!

I actually discovered that issue and posted it HERE and really appreciated the fast action taken by Rev Ed to correct it.

And what does the following code give as a pulse on HSEOUT pin ?

I get 2001.20us using a TekTHS730A with a 20m2 and 1000.05us with a 20X2.

As hippy states, we have tested 20X2 and 20M2 chips over and over again, and have found no fault, apart from the 20X2 C.0 issue with bytes too fast for an LCD.

And at the same time you seem to keep ignoring the data that I and others have gathered showing baud rate errors of > 5 percent at certain settings. So far and to the best of my knowledge Rev Ed has not even acknowledged these baud rate errors and has neither confirmed or denied them. A promised "explanation" now remains unfulfilled for over three months.

Are you saying that the actual baud rate values and error margins that I posted HERE are bogus and a figment of my imagination? And that these errors cause no problems? Or are simply you not addressing a > 5 percent baud rate error as an actual "fault"? ... In my book, when the serial rate is supposed to be 9600 and the actual rate is 9150, that is a "fault".

I challenge you to do some real testing of the actual baud rates with a test procedure similar to the one I used and then come back an say "we can find no fault".

Goey
 
Last edited:
Some time ago I suggested that it might be a good idea to be able to specify 2 stop bits on the transmit, rather than having to bodge it one character at a time with pauses to give the receiver a bit more head room.

I haven't read any good reason to change my mind. With only one stop bit, it is too easy to get out of shape and have no reasonable room to resync as the receiver starts grasping what it considers to be start bits in the middle of transmitted characters. I happen to think that Goeytex has a good case.

I like it that Google is smart enough to know the temperature in your Austen/TX air conditioned shack Goey . . . I bet your ice cold beer is as cold as mine too. :)
 
The following was done with the same 20M2, 'SETFREQ m32' and 'SYMBOL C40baud = T38400_32" for each test.

I tried adding a delay (even though I won't be able to do that with the actual equipment I'll be trying to read from), and various values for CALIBFREQ. I sent 'aaaaaaaaaaa' repeatedly for each delay and/or frequency change.

I used a 1ms delay between characters being sent. With that delay, and CALIBFREQ = 0, I got 'aaaaaaaaaaa' every single time.

With that same 1ms intercharacter delay and CALIBFREQ = -5, -15, -7, -4, +5 or +9, I got bad results every time, but not consistently. The errors would show up at different points in the 'aaaaaaaaaaa' string but errors always showed up.

So, not knowing, and having the strictest regard for the truth, I'm going to rebuild the circuit with the 28X2 I have on hand, I am happy that I ordered a few more of them today, and I'll probably have to wait until Saturday to see the results of using the 28X2 myself because I have too many other things on my list for this evening and Friday.

I'll report back again with my results and thank you ALL for the very instructional feedback.
 
My beer stays at 36F in a Picaxe Controlled cooler. :)

I prefer my cooler temperature to be between 30F and 34F. Trouble is, even when the beer is kept in a nice beer cozy, it still warms up considerably before I manage to finish it off.

I'd be interested in converting my Peltier device cooler to being Picaxe controlled. Have you posted your cooler controller project info?

Best regards, and Cheers!
 
Goeytex,

There is no intention to hide or mislead. We have actually tested this point over and over again, mainly due to the comments you have made in the past. However we simply just can't duplicate what you are saying. So we need to find the difference, particularly knowing your firmware version and chip date code (first 4 digits on bottom line on top of chip).

We have just taken a brand new 20X2 and 20M2 from the warehouse, and downloaded your code from post #11 exactly.
Tested on an AXE091 at regulated 5V, 20X2 in the breadboarding area, 20M2 in the socket, single wire connecting the two chips.

We get a perfect set of 85s. every single time. Without fail, always 85. 20M2 is a firmware version 8.A (the only 20M2 firmware release there has been), date code 1115. PE is 5.5.1
We then comment out the calibfreq -15 line. Same result, perfect set of 85s. No calibfreq is required.
We then add 'calibfreq 15'. Again, perfect set of 85s.
So calibfreq of +15 to 0 to -15 does not stop the program working or make any difference to the data displayed, we get no corrupt data at any setting.

We then took two older 20M2 chips, lying around on the desk, various ages. Same results.
Hippy also did the same with the 20M2 chip he had lying around (he's working from home today, so completely different hardware). Same results.

So you say you get corrupt date using the programs in post #11. We fully believe you. The problem is we can't reproduce this behaviour. The next step is to know the date code version on your 20M2 chip. We are also willing to send you some new 20M2 chips to compare in your setup.

Grasping at straws, the only thought we do have is that at calibfreq -15, as you correctly say, everything is running a little bit slower. We were wondering if the issue with your setup is actually with the sertxd/cable/computer timing, rather than the communication between the two PICAXE chips. At present the results posted in post #11 are assuming the data is incorrect inside the chip, and that the computer display of the byte is correct. But it is just possible it is actually the other way around? Not very likely we know, but we are at a loss to explain your results.

Now, going back to your previous results tables, there is some inconsistency. This is a bit wordy, but to avoid confusion:

1) Baud rate (timing/accuracy/calibration). This is the ability to detect/generate a byte acurately, via the bit length timing of the start bit and 8 data bits. Data is synched on the rising/falling edge of the start bit, you wait 1.5 bit time, measure the first bit, wait a bit time, measure 2nd bit, and repeat 6 more times. For serout the process is similar, set the bit and wait a bit time. For serin, as data is always synced upon the rising/falling edge of the start bit you do not get cumulative bit timing error over multiple bytes. As long as the firmware is ready to detect the start bit, then the bit length timing process starts again from scratch every single byte. Corrupt bytes occur when the start bit is incorrectly synced (e.g. the firmware thinking the first bit is the start bit, because it missed the real start bit). It is highly unlikely to corrupt the other way (too fast rather than too slow) as the stop bit (of the previous byte) is always the same polarity as 'idle', and hence cannot be accidentally synced upon.

Serial timing is very tolerant in regards to its bit timing, as shown by the attached sheet you need to be out by more than 6% for this to fail. This is one of the strengths of the serial protocol and why it has been very popular over the years.

2) Inter byte timing. This is where many slower microcontroller devices, including LCDs and PICAXE, can struggle. The absolute minimum interbyte delay according to the RS232 spec is the length of a single stop bit. However it can be much longer, any length you want. A longer delay does not decrease the accuracy of the baud rate - that is different, point 1 above. PICAXE serout commands add a longer delay than the minimum required, to allow support of third party devices like LCDs. But this does not means the serout baud rate is incorrect.

3) Serout and serin commands are firmware bit bashed by separate routines. They are completely independent, so an error of say 2% on a serout timing does not mean an error of 2% on a serin routine.

4) PICAXE chips only have 4 serout/serin baud rate settings at each clock freq. So 4800_4, 9600_8, 19200_16, 38400_32 are exactly the same thing. The PICAXE firmware is doing exactly the same thing, the only difference is the internal silicon clock frequency.

5) Due to the way the firmware operates, we agree they may be a % here or there of baud rate inaccuracy, and that some settings may be worse than others, but they are still what we consider to be within acceptable limits for reliable serial communication. We agree that on the 20X2 that 4800_4 (and muliples) is the least accurate of the 4 settings, and will look into that in a future revision.

However on your 20X2 old tests you stated various % serin errors (5.5, 6.1, 5.0, 5.3) in the table for exactly the same PICAXE setting (at various clock speeds). This simply can't be correct, the PICAXE is doing exactly the same thing in each of these 4 tests, so the % error, whatever it is, should always be exactly the same (as it actually is on your 20M2 table). So whilst we agree you are finding a % error, your test and, in particular, the percentages quoted can not be considered completely consistent/reliable.

For the serouts, going back to the 20M2, you stated an actual serout of 4944 (+3%), but we find a very different result. Attached is a screen grab done today of our 20M2, as can be seen the bit timing (serout C.0, N4000_4, "U") is 0.2125 giving about 4705, -2%, and within our acceptable tolerance. Our tekscope and salaee both give similar readings, but logic is easier to screen grab! This is quite different to your table.

Same setting (which now becomes 9600_8) on a 20X2 gives 0.1085, baud 9216.6 or about 4% error. As already stated above, not ideal, but nearer (but not the same) as the 9158 you state in your tests.

So in summary:
1) We need to test your 20M2 firmware/date code. Maybe we can even swap it for a new chip so we can test on your actual chip.
2) Our tests are showing that the 4800_4 (and multiples) setting on the 20M2 are different to what you appear to have found, and the test program in #11 works completely fine for us at any calibfreq value. This is very different to what you have found.... and we cannot currently explain that.
3) On the 20X2 we do agree that the (4800_4, 9600_8 and multiples) is the least accurate of the 4 available settings. We will look into this in a future update.

In the future it would also be very useful when discussing tests to always mention the PICAXE firmware/date codes.
 

Attachments

  • baud4800.JPG
    baud4800.JPG
    79.8 KB · Views: 14
  • logic2.JPG
    logic2.JPG
    78 KB · Views: 8
I'll be glad to send you one of my 20M2 Chips for comparison. If you want to send me some 20M2s for testing that is fine.
Send me a PM with a Shipping address and provide an Email Address where I can send you my shipping address.

The firmware is 8.A, But the chip markings are unreadable without a microscope ( Common with Microchip but maybe I can scan it)

Goey
 
@Technical

I've been working with serial for donkey's years, on just about every speed from 110 baud upwards, and bit-bashed it on a few different micros.

The 6% tolerance is something I always knew existed, but your document showed me clearly where the 6% actually comes from.
It also makes it obvious that the 6% stays the same no matter what the baud rate.

Thanks !.

Now you just need to add a bit about the importance of the inter-character delay.

Cheers,

Buzby
 
The 6% tolerance is something I always knew existed, but your document showed me clearly where the 6% actually comes from.
It also makes it obvious that the 6% stays the same no matter what the baud rate.

Note that the document correctly says:

Baud rate tolerance
When shortest and longest allowed bit times are converted to baud rates we can see
the range of valid baud rates which can be sampled correctly using the nominal baud
rate sampling time
...

In other words - if the receiver sampling clock is correct then you can accept +/- 5% 'slop' in the received data.
Conversely - if the transmitted data is 'nominal' then you can accept +/-5% slop in the receiver sampling clock.

However when both ends of the serial link are software bit-bangers then the 5% has to be shared between the clocks. It is prudent under these conditions (IMHO) to limit each clock to +/-2.5% from nominal.

In practice, some of the 5% tolerance has to be allocated to external factors - noise, ground shift, unequal transition times etc. So I would want better than +/-2% clock tolerance for any real, robust application.
 
... and, a different perspective. The PICAXE using the internal OSC has performed flawlessly in many projects (@9600 BAUD) for me and I use 08M2, 14M2, 18M2, and 20X2.

Another marketer of uC for hobby use also has internal oscillators but one sees them generally utilized with crystals - and there is a darn good reason for this... using them with the internal oscillator is very problematic with serial output even at lower 4800 BAUD rates. But they are half the price of an 08M2 in the U.S. and for blinking lights and non-comm projects, they will do... under a $1 from Newark... they fall into the use & abuse category.

With more and more PICAXE to PICAXE communication projects coming to light, maybe a low-cost PIC with crystal capability would be a PICAXE product RevEd should consider for advanced hobbyists... messing with calibfreq is a real bumpy road to travel.

- Ray
 
My tests do not indicate that the large Picaxe serial baud accuracy issues at certain frequency/baud settings are related to the internal oscillator being off.

Take the 20x2 for example: With the clock at the default 8Mhz and the baud rate set for 9600_8, the actual baud rate is between 9158 and 9200 depending upon temperature, and chip to chip variation. However at the same clock frequency both pulsout and PWM are near spot on. Hserout is also spot on. Now change the clock to 16mhz and baud 9600_16 and serout becomes near spot on, while both pulsout and PWM remain accurate. If it were because the oscillator was off, one would think that the same % serout error would be seen at all settings and that PWM and Pulsout would also reflect the error. They do not.

Now take a 20X2 with the default 8mhz clock and set serin to 9600_8. Then send it 2 bytes from another 20x2 using serout 9600_8. It cannot receive the data. Why? Because the data is being sent at ~9200 baud while serin on the other 20x2 is looking for data at a nominal 10100 baud with the minimum being ~9600. Now set both chips to 16mhz and 9600_16 and the problem goes away.

In theory this should not happen ... where at 8mhz and 9600_8, that the serout baud is low at 9200 and serin baud is high at 10100...But at 16mhz and 9600_16 all is well. This is most likely a firmware problem or something very odd going on with the silicon that can likely be corrected with firmware.
 
Last edited:
@Goeytex:
Affirmative - from what you indicate and from the results of your documented testing, the OSC does not seem to be the issue in this case. I reread the entire thread, again, and this is indeed a puzzling issue. Maybe take Technical's offer and ship 'em the chips so they can dig deeper. Strange things happen sometimes when lab firmware somehow escapes the lab and hits the production line! Also, while I have never heard of counterfeit PICAXE chips, just look at what happened with the fake Prolific USB devices. On the bright side of things, just be glad you were not involved in the faster-than-light neutrion fiasco :)
 
Maybe take Technical's offer and ship 'em the chips so they can dig deeper.

We will be contacting Goeytex via email to arrange doing that after the weekend because we would like to get to the bottom of things as well.

Everything points to it not being an on-chip oscillator tolerance issue, and I think we can discount fake PICAXE chips, but we will keep testing and will hopefully find an explanation.

Now take a 20X2 with the default 8mhz clock and set serin to 9600_8. Then send it 2 bytes from another 20x2 using serout 9600_8. It cannot receive the data. Why? Because the data is being sent at ~9200 baud while serin on the other 20x2 is looking for data at a nominal 10100 baud with the minimum being ~9600.

We are not convinced that is the case from testing here but we will investigate further. As acknowledged the timing is not spot-on in all cases but it does not need to be and should be within acceptable tolerances.
 
The 28X2 using background receive solved the problem for me. THANKS!

I'm still a little confused about the baud rate settings though. I'm using an 8MHz external resonator to get 32MHz on the 28X2. I'm switching to 16MHz internal (m16) in order to write to the AXE134Y OLED display at 2400 and then back to 32MHz (em32) for everything else. The confusing part to me is having to use T19200_32 in order to get 38400 baud when running at 32MHz, but with N2400_16 at 16MHz I get 2400 baud. Seems like having processor clock speed as part of the baud rate setting ought to allow me to use T38400_32 at 32MHz to mean 38400 baud at 32MHz. Anyway, after figuring that all out it's working like I need it to, and tomorrow I'll be connecting it to the 'real' equipment to verify. Right now, using two serial ports on my laptop it's doing great and nothing I tried short of the 28X2 background receive worked.

Thank you all (and Revolution Education's forum) for this great support.

Hope you all get that baud rate accuracy/inaccuracy thing figured out but either way, it's a great learning experience.
 
The confusing part to me is having to use T19200_32 in order to get 38400 baud when running at 32MHz, but with N2400_16 at 16MHz I get 2400 baud. Seems like having processor clock speed as part of the baud rate setting ought to allow me to use T38400_32 at 32MHz to mean 38400 baud at 32MHz.

T19200_32 should be giving 19200 baud, T38400_32 should be giving 38400 baud.

It works for me so perhaps there is something else going on there.
 
Back
Top