CNC Spindle Speed

^ Good point - all of this could be done in the microcontroller without external sensors, as long as the canbus update rate is high enough for decision making. It probably is.

Realtime during operation, very difficult, you’d have to hack in amps and volts readings, or spindle torque. But for calibration, it’s doable to make a dynamometer - hook a known mass up and accelerate it, measuring speed and calculating the torque applied. However, without calibrating your homemade dynamometer it likely wouldn’t result in numbers that are more accurate than the 50W given for spindle power.

1 Like

Hey everyone - thanks for the feedback and watching my video :slight_smile:

@brent113 @ITmaze my current ESP 32 code is pretty rough around the edges but I’m happy to share ( see end of this msg )

The hardware you can buy here ( those are affiliate links that buys me a coffee for every 10 pcs bought haha - go directly to Aliexpress if you prefer non affiliate - no worries :smiley: )

AliExpress.com Product - M5Stack 2020 New Arrival Official ATOM Lite ESP32

…and you also need one of these ( buy a few in case you break one - they’re cheap )

AliExpress.com Product - A tracking module tracking sensor infrared reflective photoelectric switch TCRT5000

Current version is listening through the dev UI via USB.

Current code as follows…


#include <Arduino.h>

// External library: JC_Button
#include <JC_Button.h>

// External library: FastLED
#include <FastLED.h> 



// Atom button + led

// HW: Pin assignments
const byte PIN_BUTTON = 39; // M5Stack Atom Lite: internal button
const byte PIN_LEDATOM = 27; // M5Stack Atom Lite: internal Neopixel LED
const byte PIN_GROVE_YELLOW = 32; // M5Stack Atom Lite: grove port, yellow cable

// Internal button
Button Btn(PIN_BUTTON);

// Internal LED controller
CRGB ledAtom[1];

// Brightness factor for LED
uint8_t brightness = 255;

// tacos
// -------------------------------

hw_timer_t * timer0 = NULL;
hw_timer_t * timer1 = NULL;
portMUX_TYPE timerMux0 = portMUX_INITIALIZER_UNLOCKED;
portMUX_TYPE timerMux1 = portMUX_INITIALIZER_UNLOCKED;

volatile uint32_t deBounce = 10; 
volatile uint32_t deCnt = deBounce; 
volatile uint32_t cnt = 0; 
volatile uint32_t resCnt = 0; 
volatile boolean isCnt = false; 

void IRAM_ATTR onTimer0(){
  // Critical Code here
  portENTER_CRITICAL_ISR(&timerMux0);
  //oddcode here

  resCnt++;
  deCnt--;
  if ( deCnt < 2 ) { deCnt=1; if (!isCnt) if (digitalRead(23)) { cnt++; isCnt = true; deCnt = deBounce; } } 
  if ( deCnt < 2 ) { deCnt=1; if (!digitalRead(23)) { isCnt = false ; deCnt = deBounce; } }
  
  portEXIT_CRITICAL_ISR(&timerMux0);
}

void IRAM_ATTR onTimer1(){
  // Critical Code here
  portENTER_CRITICAL_ISR(&timerMux1);

  //oddcode here
  Serial.print(" resolution/s "+String(resCnt)+"  max_count/s "+String(resCnt/(deBounce*2))+" - ");
  Serial.print("RPM ");
  Serial.println(cnt*60.00);

  cnt=0;
  resCnt=0;

  portEXIT_CRITICAL_ISR(&timerMux1);
}



void setup() {

  Serial.begin(1500000);
  while (!Serial);
  Serial.println("Reboot");

  // GPIO pins
  pinMode(33,INPUT); //A0
  pinMode(23,INPUT); //D0
  Serial.println("Pins set");

  delay (1000);

  Serial.println("start timer 0");
  timer0 = timerBegin(0, 20, true);  // timer 0, MWDT clock period = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp
  timerAttachInterrupt(timer0, &onTimer0, true); // edge (not level) triggered 
  timerAlarmWrite(timer0, 10, true); // 1000000 * 1 us = 1 s, autoreload true

  Serial.println("start timer 1");
  timer1 = timerBegin(1, 80, true);  // timer 1, MWDT clock period = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp
  timerAttachInterrupt(timer1, &onTimer1, true); // edge (not level) triggered 
  timerAlarmWrite(timer1, 1000000, true); // 1000000 * 1 us = 1 s, autoreload true

  // enable the timer alarms
  timerAlarmEnable(timer0); // enable
  timerAlarmEnable(timer1); // enable

}


void loop() {

vTaskDelay(portMAX_DELAY); // wait as much as possible ...


/*
  // Read the button state
  Btn.read();

  if (Btn.wasReleased()) {
      ledAtom[0].setRGB(255, 255, 255);
      FastLED.show();
      delay(60);
      ledAtom[0].setRGB(0, 10, 0);
      FastLED.show();
        Serial.println(" YAY ! ");
  }
  if (Btn.pressedFor(1000)) {
      ledAtom[0].setRGB(20, 0, 0);
      FastLED.show();
      delay(40);
      ledAtom[0].setRGB(0, 10, 0);
      FastLED.show();
      delay(40);
        Serial.println(" HIT ! ");
  }
*/

}

…and here’s the platformio.ini file


[platformio]

default_envs =

pico32

description =

[env:pico32]

platform = espressif32

board = pico32

framework = arduino

upload_speed = 1500000

lib_deps =

JC_Button

FastLED

khoih-prog/ESP32TimerInterrupt @ ^1.0.3

monitor_speed = 1500000

1 Like

For the ESP32 toolchain and editor… I can thoroughly recommend https://platformio.org/ !!

It has a slight learning curve but its super powerful…way way more cool than any micropython / arduino stuff…

…for the next version of the RPM meter I’ve got a few of these on order - to have a display directly on the Snapmaker showing the RPM

AliExpress.com Product - New Arrival! Official M5Stack M5StickC PLUS ESP32-PICO Mini IoT Development Kit Bluetooth and WiFi Bigger Screen IoT Controller

Pls let me know what you guys would like to see feature wise ?? no promises but if I find the time…

oh and if you buy the ESP32 with display make sure it’s the PLUS version as that has a larger screen…and I’d recommend to get it from the official supplier as they usually have the best price too. ( some other sellers try to advertise M5Stack models early at double price with slow delivery - got burned once myself )

Cheers

…and here’s the pinout !

Any questions…fire away

//O.

2 Likes

Cool idea - hmm guess its time to look at modifying luban… …would be cool if it can be made to read the ESP32 via USB…

…something I’ve been pondering is a laser distance sensor that measure distance to surface for filament printing on irregular shapes.

Is the spinal speed controlled via pwm from the main board? If so youncould implement a pid system to keep the rpm at the set speed. And alot of that has already been done. Check out this: https://forum.v1engineering.com/t/pid-hardware-needed-for-a-software-fix/6522
Of course you wouldn’t need the ac dimmer since the spinal doesn’t use ac power.

Spindlespeed (50-100%) is sent over CANbus (IDdec 21) to the toolhead is the RPMs dont need to be “that” exact and dont need percission in rotation.

No they don’t need to be exact but consistent is good. Like Brent was saying it will save bits if the the spinal doesn’t slow down under load.


The Motor and the Controller board in the CNC module

after checking with my DSO
DIR is constantly at GND
PWM is at a constant 2kHz and has a variable OFF time
FG is either another drive pin or a feedback as it has a changing PWM on it when the motor is driven and loaded a bit with my finger. Its quite jittery though.
NC is constantly at 3V3 (maybe a error pin if the motorboards has a problem?
PWM off times (Signal in Low state) | PWM on FG Pin
50% = 260us | 294Hz
60% = 313us | 350Hz
70% = 363us | 413Hz
80% = 413us | 442Hz
90% = 460us | 500Hz
100% is low constantly | 555Hz

1 Like

FG is the Frequency Generator pin for feedback. That’s great, thanks. Apologies to @sdj544 - he was right about the frequency feedback.

How long until someone makes a new toolhead with this and an external power supply:

Just saying…lmao.

My dad wanted a stronger engraver on it.
should be possible to do.
Not going to order somethgin like that yet though as i didnt get how to report a module as a valid one.
You’d have to get an arduino or so to do the CAN stuff and talking to the motor. But when you start modding stuff that way, why not buy a propper engraver which is built to do that or a router?

Haha @brent113 reading my mind again…

…and @Streupfeffer agree likely better to buy a more rigid machine…

…but somehow it’s fun to go a bit retard and just mod something far beyond what it’s made for - been very tempted to buy this the past few days…

220V 1.5KW ER11 CNC Air Cooled

…although if I go there I’ll do the 800W version…a lot more sensible…saying that…800w is probably 3x more than remotely reasonable on a snapmaker :smiley:

…but…tempted…

2 Likes

Even a 250 W motor on the Snapmaker is likely too much motor for the rigidity of the stock machine to handle.

  • Just to start, mounting anything on the X-axis module is a cantilever load that exert a torques on the small bearing carriage that’s inside the linear module. The rail and rollers system is perpendicular to the cantilever arm, which is the worst case situation for a two-roller system; there will be a rotation. At minimum, there would likely need to be a tramming adjustment with a heavier motor. And that’s just the static load.
  • Cutting along the Y-axis presents a dynamic load along the same torque axis. So the tram you adjusted statically won’t be stable under load. This means the tool bit won’t stay vertical. This may or may not affect the work you’re doing. It will, however, tend to break bits sooner than they might otherwise.
  • The Z-axis modules have rather flimsy support in the Y-Z plane (the little brackets) and about the same in the X-Z plane (from the way the X-axis module is mounts). What this means is that vibration is correspondingly larger for a bigger motor. This leads to broken bits and rougher surface finish.

The fact is that the Snapmaker positioning system is relatively flimsy. It’s OK for light loads such as for the FDM head and the laser head. It’s OK for a very small milling head, which is what they ship. It’s not OK for a milling head much larger than they ship with it. There are other kinds of light-load heads that would be fine for this machine. The one at the top of my list is a drag knife or even better a rotary knife (fourth axis inside the head for the blade angle).

I’ve come to the opinion that the Snapmaker is a bad value in rigidity for the materials that comprise it. I’ll not go into the details here, but roughly speaking, 50% more materials (say, by mass) could have made a machine with 10x the rigidity.

Yea, that was a joke. Gantry machines will never be as stable as real milling machines.

Yeah, but plenty of people unfamiliar with machining won’t know that.

They can be, but you need mechanical designs that are up to the task. Haas sells gantry mills, and no one would ever argue that they’re not real milling machines. Snapmaker’s design isn’t up to the task.

2 Likes

Had to look that up. That thing is 80% gantry, good lord. With a good shake it might flip upside down, it looks topheavy.

Just weld a few plates on the linear modules for stiffening, add a brace or 2, literally the same thing :rofl:.

1 Like

As much of a joke as it seems, it’s basically the right idea. Add extra bracing material so that your torque- and shear-resisting elements are stiffer; that’s the essence of it. Snapmaker combines the linear bearings and the lead screw into a single, closely spaced element. This is not a good idea. Separating the linear modules into drive modules and support modules would have allowed a much stiffer machine for not much more mass given a certain build volume.

Yea, I was thinking it works for truck frames… Stiffness and thickness cubed, doesn’t take much to make something a lot stiffer. You’re absolutely right about that would ruin the machine though - the bearings and roller assemblies are too light duty and would fail in short order. Even the 50W spindle is enough to ruin the machine as sdj can testify - took too heavy of a cut in hardwood and shook the x axis bearings loose.

1 Like

Ok we went there… here is another gantry milling machine. Has been proven to mill up to aluminum (slowly)

The MPCNC

They even offer a version similar to the machine you posted capable of full 4’ x 8’ sheets and can use a 1.25 HP plunge router.

2 Likes

Like the bat signal, I was waiting for that. I think one of those is in my future as well. With the 3D printed parts you’ll have to let me know how it does with aluminum. Use the 3d printed parts to mill aluminum brackets, and reprap your way to a pretty capable mill?

2 Likes