Arduino powered DRO for my Mini Mill

Hello enthusiasts,

Some Dutch friends probable know me already from the dutch forum.

For my mini mill I'm making a Digital Readout (DRO) I have a set of digirulers which I want to use with an Arduino Mega

I have 3 sony magnerulers PL82b from the manual I get that these have an A and B pulse output as any encoder (3-2 pagina 15) The software for the Arduino is ready and tested with a simple rotary encoder http://www.youtube.com/watch?v=bxJv_wGsuDI

I connected the pulses A and B to the arduino and nothing happened. Finally I measured the A and B pulses with a scope and what strikes me is that it does not really looks like the block signal you expect and they are not shifted 90* but they are in my opinion, in phase.

I have 3 sets and all three of them do the same even when I mix the cables and sensors.

I think the problem is me :blush: I missing some knowledge or information. I put a picture in of the scoop, maybe I'm seeing it wrong

I also measured it once with an old-fashioned analog scope, but the picture is exactly the same Sjuul

How exactly have you connected it up? The manual implies it outputs differential pairs, so you'll need a set of differential line receivers perhaps?

Arduino Interrupt 0 on pin 1 of the ruler Arduino Interrupt 1 on pin 3 of the ruler

5V on 9 of the ruler GND on 12 of the ruler

All the ground and Vcc pins of the rulers are internally connected

I'm pretty sure those pins marked PCA and *PCA etc are differential pairs - try connecting a scope to both and look at the difference?

thats correct, I have to use a SN 75176 to get it to work.

Sjuuls: thats correct, I have to use a SN 75176 to get it to work.

You need two SN75176 chips, one to receive A and A*, the other to receive B and B* (or you could use half a AM26C32, since you only need to receive). Is that what you have? How exactly do you have the digiruler, SN75176s, and Arduino wired together?

Sorry, I was a bit in a hurry

SN75176 number 1 for the A-puls:

pin 1: go's to Arduino; as 'A' data. pin 2: go's to GND pin 3: go's to GND pin 4: go's to GND pin 5: go's to GND pin 6: go's to PL82 PCA pin 7: go's to PL82 PCA* pin 8: go's tor +5V A capacitor go's between pin 5 en 8 (10-220nF)

SN75176 number 1 for the B-puls:

pin 1: go's to Arduino; as 'B' data. pin 2: go's to GND pin 3: go's to GND pin 4: go's to GND pin 5: go's to GND pin 6: go's to PL82 PCB pin 7: go's to PL82 PCB* pin 8: go's tor +5V A capacitor go's between pin 5 en 8 (10-220nF)

Your wiring sounds OK to me, although it would be a good idea to use more of the Vcc and ground pins on the device connector, since it takes 300mA.

What exactly are the pink and green scope traces you plotted in your original post? The legend suggests they are A+B and A-B, in which case you definitely have quadrature outputs but also some transients. Can you provide a trace of the A and B outputs (from the 75176 output) instead?

Also please post your code.

dc42: Your wiring sounds OK to me, although it would be a good idea to use more of the Vcc and ground pins on the device connector, since it takes 300mA.

Your right, I will

dc42: What exactly are the pink and green scope traces you plotted in your original post? The legend suggests they are A+B and A-B, in which case you definitely have quadrature outputs but also some transients. Can you provide a trace of the A and B outputs (from the 75176 output) instead?

Is the signal I have'd measured at the output of the PL82 at the PCA and PCB pins, i didn't know then that is was a RS422 protocol, I expected to measure an A and B puls like I know them from simple decoders.

dc42: Also please post your code.

The code is because of all the comments to long to post, use the link Al comment are in Dutch, i got the puls counting code from Kevin Darrah I tweaked it for my one purpose. The code only has the X an Y axis it i'm still working on it

Sjuul's DRO - Sketch

Sjuuls:

dc42: What exactly are the pink and green scope traces you plotted in your original post? The legend suggests they are A+B and A-B, in which case you definitely have quadrature outputs but also some transients. Can you provide a trace of the A and B outputs (from the 75176 output) instead?

Is the signal I have'd measured at the output of the PL82 at the PCA and PCB pins, i didn't know then that is was a RS422 protocol, I expected to measure an A and B puls like I know them from simple decoders.

Can you post an oscillogram showing the outputs from the two 75176 chips (the recovered A and B signals)? They should be in quadrature.

I have a few comments on your code:

  1. Never try to do a Serial.print in an interrupt service routine. This can cause your sketch to hang. Interrupt service routines should do no more than capture data, store it and set flags that can be read by the main code. Those Serial.print statements may be the main reason your sketch isn't working. Just because you got away with them when using a relatively slow mechanical rotary encoder doesn't mean they are OK.

  2. Don't detach and then re-attach an interrupt in an ISR. It isn't necessary. Unless you re-enable interrupts within the ISR (which is generally best avoided), you won't get a nested interrupt anyway.

  3. Pin number variables such as ZeroXbutton and other variables that are constant should be declared e.g. "const int" instead of plain "int".

  4. Variables such as Xpulses that are modified in an interrupt service routine and read by the main loop code must be declared 'volatile'.

dc42: Can you post an oscillogram showing the outputs from the two 75176 chips (the recovered A and B signals)? They should be in quadrature.

Those chips have been ordered and aren't in yet. OP is waiting for them, hoping to have them in by next weekend.

dc42: I have a few comments on your code:...

Thanks for helping me, I don't speak "Arduinos" that well but I'm working on it. I have to study your comments to really get what you mean, and get it to work. I'm tweaking the code and translating the comments. I'll post it when ready.

The Serial.prints were inherited from the person who wrote the original code, it was an easy fix to deleted those

While waiting for the 75176 chips, I have some time to do the homework that dc42 gave me XD

dc42: 1. Never try to do a Serial.print in an interrupt service routine. This can cause your sketch to hang. Interrupt service routines should do no more than capture data, store it and set flags that can be read by the main code. Those Serial.print statements may be the main reason your sketch isn't working. Just because you got away with them when using a relatively slow mechanical rotary encoder doesn't mean they are OK.

fixed that

dc42: 2. Don't detach and then re-attach an interrupt in an ISR. It isn't necessary. Unless you re-enable interrupts within the ISR (which is generally best avoided), you won't get a nested interrupt anyway.

Cant get this part, don't know what an ISR is. I got the encoder code from Kevin Darrah, an in his vid on youtube he explains why and i to me is sound good. http://youtu.be/HQuLZHsGZdI?t=15m52s

dc42: 3. Pin number variables such as ZeroXbutton and other variables that are constant should be declared e.g. "const int" instead of plain "int".

fixed that

dc42: 4. Variables such as Xpulses that are modified in an interrupt service routine and read by the main loop code must be declared 'volatile'.

fixed that

I'm ready with translating the code and it's comments, I know it's "over-commented" but it is my first real program and in the beginning it helped me a lot. Because i'm now using the I2C bus for the display, I disabled Interrupt 2 and 3. I ordered an new display and when it's in I wire it to the i/o pins so I can use all the Interrupt pins.

The story so far: Arduino Powered DRO 27-09-2013

Sjuuls:

dc42: 2. Don't detach and then re-attach an interrupt in an ISR. It isn't necessary. Unless you re-enable interrupts within the ISR (which is generally best avoided), you won't get a nested interrupt anyway.

Cant get this part, don't know what an ISR is. I got the encoder code from Kevin Darrah, an in his vid on youtube he explains why and i to me is sound good. http://youtu.be/HQuLZHsGZdI?t=15m52s

ISR = interrupt service routine. Not all advice you find on the internet is good advice. Remove the pairs of detachInterrupt and attachInterrupt calls, leaving just the attachInterrupt calls in setup().

Thanks for explaning,

I took your advise and changed this :

void XA_RISE(){ 
  detachInterrupt(0);                                             
  X_A_SIG=1;
  if(X_B_SIG==0)
  Xpulses++;
  if(X_B_SIG==1)
  Xpulses--;
  attachInterrupt(0, XA_FALL, FALLING);
}

into this:

void XA_RISE(){
  X_A_SIG=1;
  if(X_B_SIG==0)
  Xpulses++;
  if(X_B_SIG==1)
  Xpulses--;
}

I did this in all the ISR's ;) of the X-asis. After loading it into the Arduino it has trouble starting up, it looks like it runs three times the void setup before starting the main program. (it printed the welcome massage 3 times) when started up, it doesn't react good to the encoder anymore, it pick up some pulses but not more 2 or 3 turning the encoder a full revolution.

If it’s running setup more than once, something else is wrong in the code. Please post the complete sketch as it is now.

After downloading it to the mega, it shows me the welcoming text, next the template for a split second and then back the welcoming text, after 3 times the template stays on. The Z only count backwards an the X only count 1 or 2 pulses every revolution.

Arduino Powered DRO 28-09-2013 (Without detach- & attachInterrupt)

I found the setup-bug.
somewhere i placed a { wrong.

  for(int i = 0; i< 3; i++){  
  {
    lcd.backlight();
    delay(100);
    lcd.noBacklight();
    delay(100);
  }
  lcd.backlight(); 
  ...
  ..
  .

shout have been

{
  for(int i = 0; i< 3; i++)   
  {
    lcd.backlight();
    delay(100);
    lcd.noBacklight();
    delay(100);
  }
  lcd.backlight(); 
 ...
 .. 
 .

Sjuuls: The Z only count backwards ...

I just found out that this isn't a new problem, all my previous codes do the same. I can't find out why the Z-subroutines are copied from the X-subroutines. First I checked the wiring, thats ok I switched the Interrupt pins in the code to rule out any hardware problems but it didn't help. Tried the X-encoder that works fine, but on the Z still no success. Last I put the Z subroutines first in the code but also no success.

Sjuuls: ...the X only count 1 or 2 pulses every revolution

This is new after deleting the detach- & attachInterrupts