I have a somewhat hacked K2CNC (3-axis, 2x3ft, 2.2kWspindle) system, could not figure out how to get the 0-10V analog spindle control signal out of their breakout board, so I worked around it with a standalone PWM-to-Analog board, attempting to use pin33(PWM7) to generate a 1-3kHz 3.3V PWM signal, converting it to 0-10V analog for the spindle VFD. That works great, spindlepwm.c does what it needs to do and I can control spindle RPM from Gcode.
So... This all worked fine with no axis plugged in. With the axes plugged in, my X-axis "rings" as soon as I send an SXXXXX command, its a nice sharp and loud tone. The axis will move, but makes a pretty ugly noise in the process.
With the standalone PWM->analog board completely removed from the system, I get the same result, its not a wiring issue, or is my logic here incorrect?
If I comment out the scaler change line from spindlepwm.c, I dont get the ringing, but my PWM frequency is too high (I think?) and the board cannot detect the signal. So, in changing the prescale to get pin 33 to where I want it, something else is happening... not really sure where to go next.
Questions:
1. What could be causing X-axis to freak out? or what do I do next to troubleshoot?
2. Any tips on learning more about FPGA() commands in use? Im a C novice and have not had luck in finding anything online that explains what this is doing to me, I dont know enough to really understand what the comments are trying to communicate, most of the FPGA() lines beyond "prescale" look like black boxes to me.
3. Any workarounds? stepaspwm.c doesnt seem like it would work for me, and I would want to use it through one of the open IO pins not through an axis channel if possible...
Thanks in advance!
Here is my spindlepwm.c:
#include "KMotionDef.h"
#define MAX_RPM 18000.0f
#define PWM_NUMBER 7 //0-7 pins 27-33
#define pdSpindleRPM 35
#define INVERT
main()
{
int pwm;
float speed = *(float *)&persist.UserData[pdSpindleRPM]; // value stored is actually a float
pwm = speed/MAX_RPM * 255.0f;
if (pwm > 255) pwm=255; // limit to max pwm value
if (pwm < 85) pwm=0; // limit to min pwm value
#ifndef INVERT
pwm = 255 - pwm; // set the PWM
#endif
//pwm = 128;//165-175
printf("Spindle Set to %f pwm %d\n",speed, pwm); // print the desired speed
SetBitDirection(26+PWM_NUMBER,1); // Set bit PWM pin as an output
FPGA(IO_PWMS_PRESCALE) = 33; // PWM approx 1 KHz
FPGA(IO_PWMS+2*PWM_NUMBER+1) = 1; // enable the PWM
FPGA(IO_PWMS+2*PWM_NUMBER) = pwm; // set the PWM
}