To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1088
1087  |  1089
Subject: 
Re: Electrical Data Link between 2 RCXs
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Tue, 17 Apr 2001 15:47:39 GMT
Viewed: 
2762 times
  
It's me again with some improvements for an "Electrical Data Link between 2
RCX".

In the current version I changed the default condition of the link to "high"
(in the transmitter: OFF(OUT_B)) so that the receiver has a 1 at its sensor
input. So, you can better see, if the link is active. I also added an UNTIL
(SENSOR_1 == 1) statement in the receiver program (thanks to Dean for that
hint).

In order to get a stable transmission - after a lot of experimenting - I
increased the time for a 1-bit to 40 ms, for a 0-bit to 20 ms. E.g. the
transmission of a "9" (binary 1001) would result in:

_____                ________        ____                _________
          ________                ____        ________

           Startbit        bit3       bit2   bit1     bit0

The link works fine, although it is slow. If you need to transmit a value
between 2 RCX very seldom only, you may even transmit 8 bit sensor values.

The original need for the electrical link - transmitting a status from one RCX
to another RCX that should react to it - is of course the better application
for such a slow scheme. In this case, you may perhaps reduce the value range to
2 bits (e.g. 0: stop motor, 1: motor on left, 2: motor on right). This will
allow faster transmissions.

For those, interested in this subject, I will attach the 2 programs for cut &
paste.

Always good connections ...
Bernd Frassek

TRANSMITTER:

int buf = 0;                          // buffer for value to be transmitted
int mode = 0;                         // mode for testing transmission
                                      // (0 = contiuos, 1 = single shot by
pressing touch sensor)
task main ()
{
  Off (OUT_B);                        // default condition for electrical link
(high at receiver)
  SetSensor (SENSOR_3, SENSOR_TOUCH); // touch sensor for single shots
  ClearSensor (SENSOR_3);
  SetUserDisplay (buf, 0);            // show value being transmitted

  while (true)                        // transmit numbers 0 ... 15 repeatedly
  {
    buf = 0;
    repeat (16)
    {
      if (mode == 1)
      {
        until (SENSOR_3 == 1);        // single shot mode
        until (SENSOR_3 == 0);        //
      }
      send ();
      buf ++;
    }
  }
}

sub send ()
{
#define _one   4
#define _zero  2

int _bit3 = _zero;
int _bit2 = _zero;
int _bit1 = _zero;
int _bit0 = _zero;

// apply bit mask and set bits for transmission
//
  if ((buf & 0x08) == 0x08) _bit3 = _one;
  if ((buf & 0x04) == 0x04) _bit2 = _one;
  if ((buf & 0x02) == 0x02) _bit1 = _one;
  if ((buf & 0x01) == 0x01) _bit0 = _one;

// transmit bits
//
  Float (OUT_B); Wait  (_one);   // Startbit (high)
  Off   (OUT_B); Wait  (_bit3);  // Bit 3    (low)
  Float (OUT_B); Wait  (_bit2);  // Bit 2    (high)
  Off   (OUT_B); Wait  (_bit1);  // Bit 1    (low)
  Float (OUT_B); Wait  (_bit0);  // Bit 0    (high)
  Off   (OUT_B);                 // default  (low)
  Wait (5);                      // allow enough time for receiver before next
transmission
}


RECEIVER:

int display = 8888;        // display variable, default after start = 8888
int xyz;                   // variable for working with received value
int buf;                   // buffer for received value
int buf_flag = 0;          // flag; = 1, if buffer contains a new received
value

task main ()
{
  SetUserDisplay (display, 0);
  start receive;
  while (true)
  {
    until (buf_flag == 1); // wait for a new received value
    xyz = buf;             // store received value
    buf_flag = 0;           // reset rx_flag

    // work with received value
    // ...
    display = xyz;        // here simply display it ...
    //
  }
}


task receive ()
{
#define _threshold 4  // threshold for pulse length in order to distinguish
betwenn 0 and 1

int _bit3;
int _bit2;
int _bit1;
int _bit0;
int _start;

  SetSensor (SENSOR_1, SENSOR_TOUCH);
  until (SENSOR_1 == 1);              // wait for default condition of link
(high)

// listen to link (receive bits)
//
  while (true)
  {
      buf  = 0;
    _bit3  = 0;
    _bit2  = 0;
    _bit1  = 0;
    _bit0  = 0;
    _start = 0;

    until (SENSOR_1 == 0);            // wait for Startbit
    until (SENSOR_1 == 1) _start ++;  // pulse length of Startbit
    until (SENSOR_1 == 0) _bit3 ++;   // pulse length of bit 3
    until (SENSOR_1 == 1) _bit2 ++;   // pulse length of bit 2
    until (SENSOR_1 == 0) _bit1 ++;   // pulse length of bit 1
    until (SENSOR_1 == 1) _bit0 ++;   // pulse length of bit 0

// only for analyzing the timer values ...
/*
  PlayTone(4000, 5);
  display = _start;
  Wait (100);
  PlayTone(4000, 5);
  display = _bit3;
  Wait (100);
  PlayTone(4000, 5);
  display = _bit2;
  Wait (100);
  PlayTone(4000, 5);
  display = _bit1;
  Wait (100);
  PlayTone(4000, 5);
  display = _bit0;
  Wait (100);
  PlayTone(4000, 5);
  Wait (50);
*/
// "construct" value according to received bits
//
    if (_bit3 >= _threshold) buf = buf + 8;
    if (_bit2 >= _threshold) buf = buf + 4;
    if (_bit1 >= _threshold) buf = buf + 2;
    if (_bit0 >= _threshold) buf = buf + 1;
    buf_flag = 1; // new value in buffer
  }
}



Message is in Reply To:
  Re: Electrical Data Link between 2 RCXs
 
(...) My guess is that SENSOR_1 in your receiving RCX is getting a 1 when your program starts. I imagine that OFF is the default state for OUT_B in your transmitter RCX, and that the receiver is seeing this before OUT_B is switched to FLOAT. This is (...) (24 years ago, 3-Apr-01, to lugnet.robotics.rcx.nqc)

11 Messages in This Thread:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR