A newbie question about serin command

rnetzlof

New Member
In the Command Summary, the write-up of the serin command says:

"All processing stops until the new serial data byte is received."

Suppose that at some time in the past my program issued a servo or a servopos command. As I understand it, something somewhere has been pulsing the servo output pin ever since. Now execution reaches the serin command, and "all processing stops..."

Is the servo output pin still emitting pulses while we're waiting for a byte to come in? I would hope so, but it does say "all processing stops..." and pulsing the servo is processing, isn't it?

I would like to think that I'm reading too much into the statement, but I've been burned before by wishful thinking. Would someone clarify this please?
 

hippy

Ex-Staff (retired)
All processing does stop, so no servo pulses go out while you're waiting for SERIN data to arrive.

The only exception is for the PWMOUT command which doesn't require processing once activated. That will continue unaffected by SERIN.

That's probably thrown a huge spanner in the works of what you planned but it's not over yet, no need to throw your PICAXE collection in the bin and have to look elsewhere for an alternative.

By using a separate PICAXE ( a cheap 08 or 08M ) you can have that do the SERIN and when it has read the data it needs to it can indicate to the servo controlling PICAXE that it has data available.

The servo controlling PICAXE rather than executing SERIN runs in a continuous loop checking to see if there is any data. If not it doesn't stop so servos keep running as expected. If there is data it stops, asks for the data from the 08/08M which arrives in quick measure so that doesn't affect servo operation. Then the 08/08M goes back to waiting for the next serial data, the servo controller goes back to its normal uninterrupted looping.

There have been quite a few discussions on this so a Forum Search should turn up more details for this type of technique ( and it's also useful to handle wireless communications using a 'front-end device' in the same way ) and plenty of people here who can give more details and help you move forward.
 
Last edited:

rnetzlof

New Member
> All processing does stop, so no servo pulses go out while you're waiting for SERIN data to arrive.

Oh, expletive!

> That's probably thrown a huge spanner in the works of what you planned...

Indeed.

> By using a separate PICAXE ( a cheap 08 or 08M ) you can have that do the SERIN and when it has read the data it needs to it can indicate to the servo controlling PICAXE that it has data available.

> The servo controlling PICAXE rather than executing SERIN runs in a continuous loop checking to see if there is any data. If not it doesn't stop so servos keep running as expected. If there is data it stops, asks for the data from the 08/08M which arrives in quick measure so that doesn't affect servo operation. Then the 08/08M goes back to waiting for the next serial data, the servo controller goes back to its normal uninterrupted looping.

OK, I'll have to ponder that. I had hoped to use 08M's as sort of output expanders for a master 14M. Use a single pin on each 08M to receive a byte which tells it what to do to the 4 outputs it controls. Thus, control 4 outputs at the cost of only one output pin on the 14M. Lovely idea, too bad it won't work.

But thanks for the quick reply even though I shall have to retire to a darkened room to regain my composure.
 

Mycroft2152

Senior Member
Actually, you are halfway there. Just use an 08M as the front end input as well as the using the 08M's as the back end outputs.

Myc
 

hippy

Ex-Staff (retired)
I'm with Myc, you seem to have everything you need. The 14M can do the SERIN then pass data as necessary on to the 08M's which are presumably driving servos or controlling other I/O. It needs a little extra in the way of handshaking but nothing onerous, probably just one extra I/O line on each PICAXE, and maybe none extra needed on the 08M's with some clever design. You won't be able to drive servos from the 14M itself, but that can be delegated to other PICAXE's.

Untested, but this should allow Master to Slave comms with no additional handshaking lines ...

Code:
              -.-
  Master      .|.      Slave
.--------.    |_|    .-------.
|        |     |     |       |
|     TX |-----^-----| RX    |
|        |           |       |
`--------'           `-------'

Master:
  Low TX
  Do
    Input TX
    Do : While TX <> 0
    Low TX
    SerOut TX, Nxxxx, ( b0 )
    Pause 1000
  Loop

Slave:
  Input RX
  Do
    If RX <> 0 Then
      Low RX : Low RX
      SerIn RX, Nxxxx, b0
    End If
    Gosub DoWhatever
  Loop
 

rnetzlof

New Member
Hippy said:

Slave:
Input RX
Do
If RX <> 0 Then
Low RX : Low RX
SerIn RX, Nxxxx, b0
End If
Gosub DoWhatever
Loop

** end quote **

Ah! A light dawns.

When a 1 comes in on RX, the 08M turns off that 1, then waits for a byte to come in on that pin. (I do wonder why 2 Low commands?) While it's doing that, the servos may start to wander, but they won't get far because the byte will be received promptly.

In the particular thing I'm pondering, even if the servos wander a bit at that time, it shouldn't matter because receipt of a serial byte is a signal to set the servos. Thus, if they wander a bit it will get lost in the changes that are about to occur anyway (or am I about to suffer another defeat?).

Although I think I'd be better off with:

Slave:
Input RX
Do
If RX <> 0 Then
Low RX : Low RX
SerIn RX, Nxxxx, b0
<do what I need to do with the servos and relays>
End If
Loop

Thanks Hippy, thanks Mycroft.
 

hippy

Ex-Staff (retired)
Doing that way for servos certainly makes sense and the delays in responding could be minimised even further if nothing needs to happen except when something is recieved. Only a slight change ...

Code:
Slave:
  Input RX
  Do
    Do : While RX = 0
    Low RX : Low RX
    SerIn RX, Nxxxx, b0
    Gosub DoWhatever
  Loop
The two LOW's are there to get the timing right. This, and the master code, may both need tweaking to make it work.

PS : You can keep code formatting and indentation by putting it between [code]...[/code] tags.
 
Top