Missing pulses!

Hi there folks!

We’re trying to calculate a distance with an instrument that sends out a Serial data string of ‘A’, ‘B’ or ‘+’ that it has read from a pulse counter connected to a spring loaded drum with a chord monitored by a pulse counter.

RS485 in 19200 that we convert into RS232.

Cord is being pulled out, ‘A’ comes we add 2cm on the result variable, back in ‘B’ and we subtract, nothing happens a ‘+’ comes by with some frequency.

Our code works at low speed is:

// result, k and penetration are variables…

  while (Serial3.available() > 0)          
  { 
      result = Serial3.read();                   
                                      
      if (result == 'A'){                 
          penetration +=k;
      }

       else if(result=='B'){              
          penetration -=k;
      }

    Serial.println(penetration, 4);  
  }

Instead of while we’ve also used ‘if’ from time to time, it sits in a big loop anyways…

Our guess is that it somehow writes over the old data before it has recorded it…

According to manufacturer equipment has been tested with their software at the speed of gravity pulling the chord out with a weight, so the hardware must be sorted…

(Text to picture; Its shiny, its heavy, its stainless steel, its offshore gear, 1000m depth rated)

Is it possible that the cord is being pulled at more than 3.84 ms-1?

What is the value of k? What type is penetration? If you are adding 2, why is penetration anything but an int (or long)?

What baud rate are you sending data out at?

TolpuddleSartre:
Is it possible that the cord is being pulled at more than 3.84 ms-1?

No not that high. We pull the chord just by hand in somewhat of a speed, less than what gravity would do, but it still doesn’t work…

PaulS:
What is the value of k? What type is penetration? If you are adding 2, why is penetration anything but an int (or long)?

What baud rate are you sending data out at?

penetration and k are floats.

I guess we could work in tens of millimitres and get by with ints.

k is like 0.0025 [metres], the resulotion is very high… First I thought it was like two centimetres.

Baud is 19200

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your [u]complete[/u] code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

Hi, Can you post a link to spec/data of your drawstring unit?

Thanks... Tom.. :)

TomGeorge: Hi, Can you post a link to spec/data of your drawstring unit?

Thanks... Tom.. :)

I fixed the code-wrapping there.. thanks!

We haven't really documented anything yet since its not fully operational.

And we don't have to much info on this shiny instrument. We know that its RS485 and it runs at baude 19200.

The circuit is just a RS485 to RS232 converter like this in between the instrument and our Megas serial port.

https://img.staticbg.com/thumb/view/upload/2012/lidanpo/SKU108443%20(5).JPG

And data comes in... We're now experimenting with different loops and try to record the data into an array, it has given some improvements...

Things could become clearer to all of us if you posted your code.

There might be some minor issues with this code since its stripped from Swedish comments and the reading of other ports etc. But again, it works when going slow.

Some further background is that this instrument is going to be attached to the head of a barrel that’s going to be shoved down 3-6 meters into the seafloor to gather a core samle.

#define MAX485_DE       2

char result;
float penetration=0;
float k=0.0025;

void setup() {
  Serial.begin(9600);              
  Serial3.begin(19200);
  pinMode(MAX485_DE, OUTPUT);       
  digitalWrite(MAX485_DE, 0);                   
}

void loop() {
  
 
    if (Serial3.available() > 0)          
    { 
      result = Serial3.read();                                
      if (result == 'A'){                  
        penetration +=k;
      }
      else if(result=='B'){                
        penetration -=k;
      }
      if(penetration< 0){                 
        penetration=0;
      }
      
    }
    Serial.println(penetration, 4);
    
}

What happens when you increase the speed of Serial?

Hi,
Ops 485 to 232 board,
SKU108443 (5).JPG
How are you powering the drawstring?
Doesn’t the device have any info on it, or is it custom made and the drawstring unit is inside the housing?

Thanks… Tom… :slight_smile:

Hi, What does;

digitalWrite(MAX485_DE, 0);

do?

Tom... :)

TolpuddleSartre:
What happens when you increase the speed of Serial?

But we can’t since we have to adapt to the instruments baud rate that we can’t alter? And if the manufacturer could get it to work in 19200 it should be possible…

We continue experimenting with additional flags and buffert-variables, and have seen some improvements.

TomGeorge:
Hi,
Ops 485 to 232 board,
SKU108443 (5).JPG
How are you powering the drawstring?
Doesn’t the device have any info on it, or is it custom made and the drawstring unit is inside the housing?

Thanks… Tom… :slight_smile:

We power the instrument (real name Penetration logger) with external 12 volts. Yea its custom made…

Half of it is drawstring housing and half is a water proof housing with some intelligence.

The data string out of the instrument pulses slowly + + + + + + + + + + + +

But when you pull the string A:s appear in o much higher frequency… As we’ve seen just monitoring it.

TomGeorge:
Hi,
What does;

digitalWrite(MAX485_DE, 0);

do?

Tom… :slight_smile:

It tells the RS485 to RS232 converter which mode, in our case to read. Its hooked up to the pins DE and RE on the converter.

Robin

Now this piece of code has made a major improvement!

Maybe we’re happy with it now. Or if you could see anything that could cause a failure?

#define MAX485_DE       2

char PenBuff[5];
int PenBuffLen=5;
int IncPenLen=0;
float penetration=0;
float k=0.0025; 

void setup() {
  Serial.begin(9600); 
  Serial3.begin(19200); 
  pinMode(MAX485_DE, OUTPUT);       
  digitalWrite(MAX485_DE, 0);       
}

void loop() {

  while (Serial3.available() > 0) {

    IncPenLen=Serial3.readBytes(PenBuff, PenBuffLen);
    
    for (int i=0; i<IncPenLen;i++){
        if(PenBuff[i]=='A'){
          penetration +=k;
        }
        else if (PenBuff[i]=='B'){
          penetration -=k;
        }
        else if (PenBuff[i]=='+'){
          penetration=penetration;
        }
        if (penetration <=0 ){
          penetration=0;
        }
    }
    Serial.println(penetration,4);
  }
}

Robin & Fredrik

But we can't since we have to adapt to the instruments baud rate that we can't alter? And if the manufacturer could get it to work in 19200 it should be possible...

I wrote that you should increase the speed of Serial. I wrote nothing about Serial3.

Cord is being pulled out, 'A' comes we add 2cm on the result variable

Does not match what your code suggests.float k=0.0025;

TolpuddleSartre: I wrote that you should increase the speed of Serial. I wrote nothing about Serial3.

Oki. A baud rate of 300 can transmit 30 signs a second wikipedia says, so 9600 should be enough.

We don't have to transmit the final data in any high frequency later, its just that the calculation of the drawstring length must be correct!

TolpuddleSartre: Does not match what your code suggests.float k=0.0025;

It does not no, 2.5 mm is correct.

So my 3.84 ms-1 is way out.

A baud rate of 300 can transmit 30 signs a second wikipedia says, so 9600 should be enough.

So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.

You do the arithmetic.

TolpuddleSartre:
So my 3.84 ms-1 is way out.
So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.

You do the arithmetic.

Another way to look at it is this. For every character that comes in, you send out at least 8 (0.0025) at half the speed. Is it any wonder why you loose incoming data?

Get out of the stone ages. 9600 baud went out with 8 track players.

TolpuddleSartre:
So my 3.84 ms-1 is way out.
So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.

You do the arithmetic.

I think 1 m/s is good enough! Receiving rate is 19200, should be good enough.

PaulS:
Another way to look at it is this. For every character that comes in, you send out at least 8 (0.0025) at half the speed. Is it any wonder why you loose incoming data?

Get out of the stone ages. 9600 baud went out with 8 track players.

It doesn’t matter, that baud rate that we’re sending with is good enough, it’s just for display.

But with the initial code the whole calculation was wrong. As long its the right value on the draw string variable we’re happy. So it was probably an issue with over writing or similar.

As said, it seem to be working now with this buffer we included, we’we also tweaked down the array size quite a bit and its still happy. To long array and it stayed in the for-loop so long it was noticeable.