Interrupt Driven Rotary Table controller

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Rod,
My name is Scott and I have been following this post for quite a while. Thank you for all of the time and effort you have put into this project. I have finally collected all of the parts I need to make this work for my application. I plan on using a Hass 5c collet stepper indexing head for use on my cnc mill. I have got the Hass head to index like it should and it works great. I now just need to figure out how to interface it to my cnc mill. It is a VMC with a fanuc control. I plan on doing the same thing as Scott did by using a remote switch to index the head. I have some available M codes I can use on my machine to call for the arduino to make the step move. The problem I have is that when I request an m40 code in the g code The cnc will activate a relay which will simulate a right button push. That m40 relay then stays active until the cnc gets a signal to de activate m40. The machine will not progress with nc code until this condition is met. I have looked though your code and I have not found what looks like a finish movement signal. If I can capture that signal and activate a relay to end m40 that will let the nc code continue. I would appreciate if you could point me in the right direction and maybe give me a little help with the code part of it. I am not super savvy on the arduino side of things. It could be as simple as a potentiometer going to an analog input that changes the length of time before the arduino activates a pulse to de activate the M40 code. I think that you would want to use interrupts to time this so that the processor is not counting and waiting for that time period. I would appreciate any help you can give me
Thanks
Scott

Now I'm by no means any kind of an Arduino expert, but would it not be possible to just make a digital pin go high when the code is not active, AKA signal is not being sent to the stepper motor?
 
Last edited:
Yes that is what I am looking for but, as I am picking through the code I am having a hard time thinking how I an going to do it. Something along the lines of if stepper not true then bring pin whatever high for a pulse to deactivate the M40 code. I am going to dive back in and see if I can figure something out.
Thanks
 
Hi Scott
Scott here, can't you address it in the code ? I am not that savvy with custom macros but can't you call the m40 conditionally ? Like for 5-6 seconds ( long enough to make your rotary move ) and then have it return from M40. Or is there another M code that will cancel it. Like we cancel a canned cycle or cutter comp ?

Scott
 
I had not thought about a macro. My machine has macro a and I have not tried to write a macro before but that is a thought. There is not another m code to cancel m40, it waits for a 24 volt signal to trigger a change in the ladder to cancel it. There may be a way to do it with a macro but I need to do a little research and see. From my limited understanding of macros you can use variables programed into the diagnostic parameters which could be used for a time limit. I will look at my fanuc manual and see what I can find out about that.

Have you had good lock with the setup you did with the proximity switch?
Thanks
Scott
 
Hi Scott
Actually we had to bail on the prox switch. It developed a serious debounce issue that I could not resolve. I went to a mechanical N.O. switch and piggybacked it to the shield switch.
It has been rock solid since. It really brought some new possibilities to a "vintage" machine.

Scott
 
Did you try to tie it into the A0 pin directly with the same value resistor? I am only asking because I am in the process of mounting five buttons on the face of the machines control enclosure and I tried simulating the five switches on the shield with a resistor array matched to the resistors on the shield. I had problems because I was getting feedback from the resistors on the shield and the voltage values were not correct when both were wired into the A0 pin. My next step is going to break the connection to the A0 pin from the shield. I plan on mounting the arduino and display inside the Machines control with just the lcd showing though so there wont be a need for the shield buttons anyways.

as for the macro idea I did some reading in the fanuc manual and you can change some internal registers on the cnc control with a macro but I think that the one for the m40 code may not be one of them. I posted a question about this type of thing elsewhere maybe the fanuc gurus can shed some light on the problem.
 
Did you try a small value capacitor from the signal pin to ground? I had a random trigger issue with an Arduino based device. It would trigger every time a fluorescent lamp turned on of off nearby. A small capacitor solved the issue. It was a genuine Arduino Nano.
 
I think I have a solution for this application. I used a digital write command within the go divide section to send pin 10 high momentarily to cancel the m40 command from the cnc. I tried to use the millis compare system but kept getting errors from the compiler in a strange section of the code and I could not figure out why. So I went against what I believe to be the correct method and used a delay command in between pin 10 high and pin 10 low with a 100 ms pulse. I know this stops the processor from working during the delay but bench testing showed no sign of problems. Everything seemed to work properly. The next step is to hook everything to the cnc machine and se how it works.

I would ultimately like to write a macro for the machine so that I can input the number of divisions into a macro variable and the nc code will index until it reaches the desired number of divisions. Need to do some macro studying.
Scott
 
Curtis, sorry I totally missed all of the activity on this thread about your idea to use a Fanuc Macro. I'm not 100% sure from your description about what you need to do to tell Fanuc to reset the output relay. On thing you could consider doing is use a a hardware interrupt that sensed the relay turning on (RISING).
https://circuitdigest.com/microcontroller-projects/arduino-interrupt-tutorial-with-examples
Let that interrupt set a global variable (FanucM40) that godivide() could monitor. Let godivide save that variable in a static variable (last_FanucM40) so it knows if its changed since the last time through the while loop

Very roughly a bit like this maybe...
Code:
   static int volatile FanucM40;
// in godivide()
  int FanucM40_changed;
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
     if(FanucM40 && !last_FanucM40){ // M40 set
          event = LCD_BUTTON_RIGHT;
          FanucM40_changed = 1;
     }
      switch(event){
        case LCD_BUTTON_LEFT:
          thisDiv--;
          if(thisDiv < 1)
            thisDiv = divisions;     
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          setSteps(stepsPerDiv * 2, 1);
          printDivideVals(thisDiv,gAngle);
          break;
        case LCD_BUTTON_RIGHT:
          thisDiv++;
          if(thisDiv > divisions)
            thisDiv = 1;     
          digitalWrite( globals.DirPin, CLOCKWISE );
          setSteps(stepsPerDiv * 2,1);
          printDivideVals(thisDiv, gAngle);
          break;

      }
   last_FanucM40 = FanucM40;
   if FanucM40_changed{  /we've processed this button press so safe to reset M40
       //Reset M40 signal
       FanucM40_changed = 0;
   }
}
 
And you could extend this by adding a toggle switch that put 5 volts from the Arduino to a digital input so you could decide if you wanted to move left or right in godivide on a M40. Mounted horizontally, this switch would be quite intuitive.
 
Well, finally here is an upgrade. In the Zip file, there are 3 files:
  1. RotaryTable11.ino - The latest version with the bug fix for correct stepping interpolation discussed earlier
  2. LCD.h - Replaces the file in the LCD library folder.
  3. LCD.cpp - Replaces the file in the LCD library folder
The changes 2 & 3 are to support a greater range of LCD/keyboard shields
In LCD.h uncomment the#definef you have a DFROBOT compatible shield
Code:
// if a DFROBOT display (with 2.2k ohm resistor on input buttons) uncomment the line below
//#define DFROBOT

This will use the correct key map and also the correct pin for the backlight via some conditional code in LCD.cpp


See this URL for details on the DFRobot: https://wiki.dfrobot.com/Arduino_LCD_KeyPad_Shield__SKU__DFR0009_
Chances are that if you have a keyboard that does not work with the rotary table controller, this will fix it.

For the curious, I ran a simple sketch that printed the keyboard values to the serial monitor, downloaded the genlookup.c from the original repository https://github.com/rweather/arduino-projects
edited it and compiled it using gcc on a linux box
Code:
gcc -o genlookup genlookup.c
and changed the permissions of the binary file genlookup to: read/write/execute
Then I piped the ouptut to a text file to insert into LCD.cpp and it worked!
Code:
genlookup > genlookup.txt

Let us know if this works for you. Sorry but the forum does not allow me to update the first post.

A friend looks like he's talking me into adding a rotary encoder support for easier data entry so you never know, this might improve with age. If I've got a spare interrupt left after adding the encoder, I may add support for an external relay that can be triggered on a CNC machine with a M40 command from gcode.
 

Attachments

  • RotaryTable11.zip
    14.3 KB
Last edited:
Glad to see this beautifull project is still evolving and improving .

Pat
 
Pat, thanks for the encouragement. I hope the new LCD shield support makes it more valuable for people on the other side of the world. Any feedback will be appreciated.
 
Hmm, that was easy. It looks like external relays are now supported. I won't share it yet as I have not tested it with real hardware unless somebody really wants to try it but a hardware interrupt on pin 2 fires if it receives a 5 volt signal and after indexing is completed, pin 13 is briefly enabled (currently for 0.3 seconds) signifying the indexing move has been completed. To implement this you'd need two relays (optoisolated preferred). One relay would be triggered on the external device and it would switch 5 volts from the Arduino power supply to pin 2.

Another relay would be attached to the Arduino PIN13 and Arduino GND. It would switch field power on the external device to an input signifying the machine could continue. Apparently some machjines (eg with Fanuc controls) are provided with macro relays that can be triggered with something like an M40 in gcode.

You could also do this from LinuxCNC/Tormach PathPilot out of the box with a M64/M65 followed by a M66 wait on input something like
Code:
M62 P0  (turn on digital output 0)
G4 P0.1  (pause to catchup to avoid breaking blending)
M66 P1 L1 Q10  (wait for 10 seconds for digital output 1 to go true at end of indexing)
M63 P0 (turn off digital output 0)

Of course you'd need to add a bit of error handling. The Linuxcnc docs say "If the timeout is exceeded, the wait is interrupted, and the variable #5399 will be holding the value -1."

I wonder where Scott is....
 
Rod , has this software ever been tested on a nano ?
I've been experimenting with a nano , and a custom made display/button shield with a larger display and better quality switches .

It all works at first sight , but when entering setup to assign the step and dir pins etc when I save the entire
systems locks up . Even the reset does nothing . All I can do is pull the power to reset the device .
And offcourse the parameters arent saved .

I tried to modify the parameters in the skecth before compiling , and upload that .
Didn't work on the nano I was using , kept going back to the stored parameters .

I then tried a brand new nano , and uploaded the modified sketch , and this time the parameters
are correct . But I have thesame behaviour as before , can't modify them .

Seems to be some kind of eeprom issue ? Looks like it can't or won't erase


On my uno , the one with the modified df robot shield , it all works fine .
The save of the setup returns to the startup screen and the processor continues working .

Strange because the nano uses thesame 328p processor .


Edit , uploaded a couple of pictures to show what I'm trying to do .

The original shield is there to compare size. Arrowed switches are also illuminated , but the camera doesn't seem to like blue leds .

IMG-20190708-00377.jpg


Little pcb bolted to the display holds the various parts for contrast and display backlight .
I added an 7805 so the nano doesn't have to supply the current for all the leds and the backlight .

IMG-20190708-00378.jpg
 
Last edited:
I have never tried the nano.
I think there are probably 2 issues here. Re not saving the data, there is a signature written to the first 3 bytes of the EEPROM to tell it it has valid data. So this signature need to be erased by another script or changed.
Incrementing the signature in the #defines will force an overwrite. I only changed this number if the globals structure was altered
Code:
#define CONFIG_VERSION       "RT4"        // The Signature to tell us we've saved stuff in the EEPROM
#define NO_DEVICE_SIG        "XXX"        // The Signature to tell us we've got nothing in the EEPROM

This script pushes the global memory to its limit and I had to shorten text displayed to make it fit.
If the nano has less global memory or less efficient initialisation code that reduces the amount of available code space, you will get memory overruns and unpredictable behaviour. This is the most likely explanation for hanging.
Ideally all the menu strings should be PROGMEM variables to reduce the consumption of global memory but this requires modification to the third party menu library I used. I did not have much luck changing it.
 
At first sight i'de say its a bootloader issue .
My uno and my nano's both hve thesame meg328P chip .
So that can't be the problem .
So I tried uploading the software , but this time I used Nano(old bootloader) in the arduino gui .
When saving the setup parameters , the arduino stilll locks up but the parameters seem to be saved as they should .
I'll do some further testing and keep you posted .
 
I have been using the program from rodw for a couple of years now. I'm working on a back gauge for my leaf brake and now I need the Linear portion of this program. From the very beginning I have not been able to change any of the parameters in the program from using the LCD keypad (SainSmart) on the Arduino UNO. All changes I have made were to the Arduino program sketch. So, today I upgraded my Sketch to the new Version 11 from rodw including the library changes and now my SainSmart display will not allow the buttons to work correctly. The 'right' button is the only one that will work. If I plug in a Osepp LCD keypad, that one works. Can you help with these 2 problems please?
 
Last edited:
Back
Top