Serin Timeout problem......

marky26uk

New Member
Hi guys & gals,

l0:
SERIN [1000,l1],7,2400,("HUMI"),b0,b1
sound 7,(100,10):goto l0

l1:
sound 7,(50,50)
debug b0
goto l0

Experimenting with the timeout function for the first time my code is above.
The problem i have is it seems to eratically timeout or not at all, very random.
I have a receiver to receive the data with a qualifier as these AM receivers receive alot of noise so, does the timeout reset every time it receives junk from my rx or will it timeout on not receiving the qualifier ?
By the way the 28x1 firmware is v0, i bought these when they first came out, i hope it's not a firmware issue as i seem to remember something being posted about it, i can't find it though.
Any help greatly appreciated.

Mark
 

moxhamj

New Member
Aargh. Timeout problems. This might be one for Technical.

Timeouts and Serin and radio have been a source of frustration for me for over a year.

In a nutshell, radio = noise. It is not like a wired RS232 connection where signals are "0" or "1".

The qualifier certainly helps, but you probably need a checksum as well. Add a couple more bytes at the end, add up all the bytes you are sending and check the addition is correct as well.

The challenge for any Serin instruction is can it handle white noise. And how does it handle that noise - does it timeout after a certain time. And how does it handle qualifiers - bearing in mind that sending a qualifier such as "ABC" will still go through with random noise every 2^24 bytes.

I'm working on this problem right now, but it involves machine code. It is not a trivial problem. It does not work with standard UARTs like the 16550. The solution may well lie with true wireless modems - ie ones that send "0" if you put "0" in one end - and very few work like that. A solution to this problem also solves the problem of wireless downloads to picaxes, and that has been discussed at length on this forum with no conclusive outcome.

First question though - which wireless modules are you using, what sort of antenna, what frequency, and what does a photo of the setup look like. It is certainly possible to improve wireless reliability, and that should be the practical solution to your problem.
 
Last edited:

marky26uk

New Member
Hi drcula,
My rx antenna & tx antenna are fine, all cut to correct lengths ect, i used to be a communications engineer so i'm quite up on that side.
My code snippet is just for testing purposes, my main program does use variables from the serin that are added up & then checked with the post value to make sure all has been received ok.
I'm using the AM 433mhz modules, these are prone to interference & such, think i'll purchase some FM modules which should fair alot better interference wise.
I see what you mean with the serin noise, differentiating noise to a valid serial command would be difficult but, i wondered if the serin timeout command would timeout if it didn't receive the qualifier "HUMID" say.
Upon experimenting i found that the timeout command is resetting on any noise from my rx module it receives.
I thought the timeout would work timing out if it didn't get the whole qualifier within the set time period, that's a darn shame.

Cheers,
Mark
 

moxhamj

New Member
I still haven't solved this one. If you go back to the older picaxes, like an 08 or 08M, then they have no timeout. So they sit there hanging till they get their qualifier, then read in the next bytes whether they are valid or not. I had an idea that you could then presume that was a valid signal and send it through to another picaxe - but even that is not 100% perfect. But it will be a lot better than what you have.

But my experience is that the AM modules are very reliable if they are used not too close (<2 metres) and not too far away, and not near other sources of interference.

Not sure about FM vs AM. Maybe not as important as one would think.

Two things that do make a difference - the db rating of the receiver, and the milliwatts of the transmitter.

I wonder about an 08 with no timeout acting as a filter, and just pass thru the bytes with no change, then use your 28X1 as it is with the timeout.
 

hippy

Ex-Staff (retired)
Technical can only provide the definitive answer. Timeout could be implemented in any number of ways - when waiting for any data to be received, when waiting for a qualifier or first data byte, only when first entering SERIN. I don't know, but you could build a test jig and write some code to determine which it is sending data from PC Terminal Emulator over a hard-wired link.

It all comes down to where in the command the internal timeout counter is reset/started and where timeout is checked for. The simplest and most obvious place for a programmer to put a timeout check is while waiting for a start bit to arrive. In this case it's a "no data being received" not a "no qualifier received" timeout and any noise from the RF module will keep the SERIN from timing out even though a valid qualifier may never be detected. That seems to fit with what you're experiencing.

The best solution in this case is to use a separate PICAXE as a front-end slave which reads RF data packets and passes valid data to the master. The slave doesn't have to care about timeouts as it either gets valid data or not and it doesn't matter where it is hanging around waiting within command execution or what affect noise has.
 

marky26uk

New Member
Hi Dracula,
FM (frequency modulation) would definitely be better then AM (amplitude modulation), AM works on varying rf power whereas fm on frequency, so am is prone to allsorts of interference around.
I think that if the serin command jumps to the next instruction only upon receiveing the valid qualifier, wouldn't it not be so hard to have a timeout if it knows it's not getting that qualifier ?
Could this be a future firmware fix or new command Technical ?

Thanks for your replies Dracula, have a good Weekend to you & all,

Mark
 

marky26uk

New Member
Hi Hippy, yes you're right & using a slave picaxe would cure that problem, this i'll have to do but was rather hoping not having to do this.
Another command maybe would be a good idea so you can have a timeout for use with qualifiers.

Cheers,
Mark
 

moxhamj

New Member
FM vs AM - I'm rather fortunate where I live as I have virtually no interference from either. But in suburban locations there is all sorts of interference on both types of modulation - from garage door openers and the like, and as our esteemed colleague Stelios found, from enthusiastic ham operators next door who can pump hundreds of watts of power into your poor little receiver.

As for the timeout - I'm starting right from scratch with some raw machine code, but I'm still not sure of the perfect system. For picaxe, it probably is two chips. Going back to first principles, it may well be a numerical array which is a database of values captured over the previous few hundred milliseconds, which is compared using a correllation coefficient to a matching string. DSP processors are good at this sort of thing - they can take a sample of analog signal and filter out echos for instance. But a picaxe is not a DSP.

Manuka also found that putting a series of "U" characters at the beginning helped. This is binary 01010101 and if you have at least 6, it synchronises the picaxe so at least it is likely to start reading the qualifier byte at the beginning of the byte and not half way through. Do you have some "U"s in the tx eg something like "UUUUUUABC" then the data bytes?
 
Last edited:

Technical

Technical Support
Staff member
Timeout occurs whilst waiting for the start bit of a byte. Once a voltage change, either legal or noise, is detected the byte will be received regardless - so a incorrect noise spike could cause a byte received as 0 or 255, depending on polarity.

If this does not match the qualifier, as it won't with noise, the qualifier will not be met and the serin line resets back to the start of the qualifier.

As already suggested, most of these tx/rx work ok as long as you send a random byte or two to wake them up - this is normally the tx/rx waking up, not the PICAXE.

So try making your tx serout "UUHUMI" whilst leaving the receiver qualifier as "HUMI".
 

marky26uk

New Member
Serin timeout problem

Hi Technical thanks for your reply, i do understand about leading qualifiers for the tx to have chance to get going properly.

My question really is :-
When serin is sat there waiting for my qualifier ie, "HUMI", when it doesn't receive the qualifier within the specified timeout period of let's say 1 second, is it not possible to have the timeout work on wether or not it gets the valid qualifier or not, rather than looking for anything that's coming in on the serin ?

I understand everytime the serin command with the timeout is receiving random 0's & 1's of garble from the receiver, it is resetting so not getting to the end of it's specified timeout period.
If a command could be made so as to timeout when a qualifier is used solely for looking for the qualifier & timeout if it doesn't get it, then that would be great.

Cheers chaps,
Mark
 

moxhamj

New Member
Long ramble - then I'll try to answer this!

Yes, I think a number of us might have a "wish list" for timeout. I've been working on a board for the last 6 months and the latest incarnation is that this is one problem that might have to be done with a Z80 in machine code rather than with picaxe. But the problem is a bit complex so that is nothing against picaxe!

For radio - using a dedicated 08 is a good solution. This then can pass the data along to the main picaxe. But this handshaking cannot use Serout/Serin otherwise the hang problem is still there. So you have to hand code your own protocol using high/low commands (I've replicated the RS232 protocol but at 1 baud). Or clock in the signal using a clock line. Any protocol really, as long as it uses instructions that do not time out in any way.

Or, the main picaxe can be one of the newer picaxes that has a timeout.

The problem I'm up against is how to build a system that listens to 5 different lines at the same time - 4 RS232 lines and a radio link. You can have 5 08s all acting as filters and buffers and talk to the main picaxe with slow serial as above. You could make the main picaxe an X2 and poll the lines - but this might risk missing a packet. Or you can go to a machine code solution and poll all the lines so quickly that nothing is missed, and read in all the lines in parallel. Machine code is at least 1000x faster than picaxe code.

I'm still pondering the merits of all the above solutions. And then I have another design parameter - down the track it would be great to send large amounts of data - eg pictures, and most picaxes can only handle 14 bytes in one packet.

Using seperate 08s is a bit of a pain as there are now 6 picaxes on the board, but it does have the advantage of allowing asynchronous comms - data can be arriving all at the same time and it can be buffered until the main picaxe is ready for it.

But there are also advantages in machine code, and it may help solve the problem of dropped packets. Even with lots of header "U"s, some packets don't go through. I think this may be to do with framing errors. A radio Rx is receiving random noise before the signal starts, and the serin will be sitting in an endless loop waiting for a low to high transition. If it picks one up, it reads in a byte, and checks for a low stop bit at the end. If that isn't there, it assumes that byte was not valid and tries to read the next byte. I'm not exactly sure how that happens, but I think the probability of framing errors is halved with each "U" that goes through, so after there are 4 "U"s, the probability of a framing error is 1/2^4 = 1/16. The mathematical problem is how the system moves towards a correct beginning of a byte if it happens to start in the middle of a byte. One would need to see the source code for Serin to answer this properly. Suffice to say that 8 "U"s and "ABC" makes for a very reliable header, but you still need a checksum word, and now all these extra bytes are more than the number of data packet bytes.

With machine code, one can read in the actual waveform with many captured bytes into an array, and then compare this with an array containing, say, "UUUUABC", and check for the % match or even a fancy check with a corellation coefficient.

Or there are other algorithms - eg a wakeup can be a series of 255/0/255/0s. In that sequence there will be long periods of high or low, so these can be used to check for a signal vs noise. Then once a signal is flagged as present, send a series of 0s. In that sequence, the only high transition will be 1 bit wide and will be the start bit. So this can be used to synchronise the signal and avoid framing errors. It could also even be used to determine the baud rate automatically as that bit will be of a known width.

With radio, the aim is to minimise the chatter and to keep the packets short. This conserves power, keeps the neighbours happy, and enables lots of picaxes to talk on the same frequency with a low chance of collisions.

Keeping the packets short means even the wakeup bytes and the qualifier bytes should be kept to a minimum.

Going back to the question in post #10, I'm sure RevEd will think about it and may put it in their next revision. But as you can see from the above, serin coding is not simple so they may look at it and decide it is too hard. So if you want something working and working soon, I think the 2 picaxe solution would be the most practical.

I have the "2 picaxe" solution working with radio repeaters and it does work well. The "main" picaxe often isn't working all that hard and some of the repeaters are simply 2 08s.

Addit: To Marky26 - one quick test to check reliability of radio modules is to setup a picaxe producing a 1khz square wave, put that on a protoboard with a tx module, set up a Rx module to a scope, and then go and put your Tx out in the garden. Go back to the scope and see what the waveform does. It is quite informative to see how the waveform distorts depending on distance to the ground, trees, sheds etc. If you are lucky you may be able to persuade a 'significant other' to walk round with the Tx module. My experience is that the distance the manufacturers claim is usually a little optimistic. 50 metre units go 10 metres. 4000m units go 500 metres. I think the figures they quote are the furthest distance one can hear a signal on a scanner using the marvelous noise reducing properties of the human ear, not the furthest distance one can send data.
 
Last edited:

hippy

Ex-Staff (retired)
If you're considering going to Z80, how about going to a processor which allows multiple asynchronous serial to be handled easily ? Choose the right processor ( you can probbaly guess what I'm thinking of ) and you'll effectively have 8 PICAXE's running at 80MHz / 20MIPS each on a single chip with shared RAM. As with individual PICAXE's the programs on each will be simplistic and dedicated to just one task, reading serial bytes and packets. Having shared RAM allows FIFO buffers to be easily created so there should be nothing missed, providing bufers can be emptied quicker than a sender fills them up. At the sort of baud rates we're talking about it should be possible to have a single core dealing with multiple serial inputs.

I know what I'd use.
 
Top