Spindle Interface II
Moderators: TomKerekes, dynomotion
Spindle Interface II
Hi Tom,
You helped me get my spindle up and running a few months ago. Everything worked fairly well except that as the spindle would run the speed would slowly decrease. It looked like something was slowly heating up in my C6 interface board that was causing the problem. I contacted the CNC4PC customer support about the issue and they suggested I upgrade to a C41S board which has a much improved circuit. Only problem is I can't get it to work. Here are the spec's of the new board:
INPUT SPECIFICATIONS
On-state voltage range 2 to 5V DC
Minimum on-state input current 10 mA
Recommended PWM signal frequency (200Hz)
Signal Type Active High
I am running the spindle off of Channel 6, pin 5 on RJ5. How do I know what frequency that channel is outputing? How do I adjust it? I have attached my init file for reference.
Thanks,
Jack
You helped me get my spindle up and running a few months ago. Everything worked fairly well except that as the spindle would run the speed would slowly decrease. It looked like something was slowly heating up in my C6 interface board that was causing the problem. I contacted the CNC4PC customer support about the issue and they suggested I upgrade to a C41S board which has a much improved circuit. Only problem is I can't get it to work. Here are the spec's of the new board:
INPUT SPECIFICATIONS
On-state voltage range 2 to 5V DC
Minimum on-state input current 10 mA
Recommended PWM signal frequency (200Hz)
Signal Type Active High
I am running the spindle off of Channel 6, pin 5 on RJ5. How do I know what frequency that channel is outputing? How do I adjust it? I have attached my init file for reference.
Thanks,
Jack
- Attachments
-
- Init File 0327.c
- (10.35 KiB) Downloaded 415 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle Interface II
Hi Jack,
The C41S expects a PWM (Pulse Width Modification) where the faction of on time (duty cycle) determines the output more or less regardless of the constant frequency. Where the C6 expects a pulse frequency to determine the output regardless of the duty cycle.
The C6 is somewhat simpler to use because a Step/Dir output can be used to control its output in the same manners as stepping motor.
PWM outputs require a couple lines of C to control the PWM. So a loop would be required to send the Axis Output to the PWM. And An axis would need to be configured so the output would be proportional to the commanded speed (Velocity Feed Forward only).
If you want to use the C41S, as a first step connect it to a PWM output (Bit26) and run the program below in some unused Thread. This should cause the C41S to output 5V. Then change the 128 to 0 - 255 to see if the output responds appropriately.
HTH
The C41S expects a PWM (Pulse Width Modification) where the faction of on time (duty cycle) determines the output more or less regardless of the constant frequency. Where the C6 expects a pulse frequency to determine the output regardless of the duty cycle.
The C6 is somewhat simpler to use because a Step/Dir output can be used to control its output in the same manners as stepping motor.
PWM outputs require a couple lines of C to control the PWM. So a loop would be required to send the Axis Output to the PWM. And An axis would need to be configured so the output would be proportional to the commanded speed (Velocity Feed Forward only).
If you want to use the C41S, as a first step connect it to a PWM output (Bit26) and run the program below in some unused Thread. This should cause the C41S to output 5V. Then change the 128 to 0 - 255 to see if the output responds appropriately.
HTH
Code: Select all
#include "KMotionDef.h"
main()
{
SetBitDirection(26,1); // define PWM #2 bit as an output JP6 Pin5
FPGA(IO_PWMS_PRESCALE) = 255; // divide clock by 255 (254 Hz)
FPGA(IO_PWMS) = 128; // duty cycle 128 = 50%
FPGA(IO_PWMS+1) = 1; // Enable
}
Last edited by TomKerekes on Fri Sep 08, 2023 5:58 pm, edited 1 time in total.
Reason: Forgot to post C Program
Reason: Forgot to post C Program
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle Interface II
Hi Tom,
So far so good. I need to play with the adjustment pot a little but basically at 128 I got 5 volts and at 255 I got a little over 10 volts. All this time I thought the C6 was using PWM.
I tried to take the next step and modify the canned spindle programs to drive the spindle but didn't get very far. I set bit 27 (direction) and 26 (speed) in the init file and then used the attached file to drive the spindle CCW. This new C41 board does not require a CCW and CW bit. It's either CCW or it's not so I'm only using bit 27 for direction. Using the console it appears that I'm passing the STATEVAR just fine but for some reason I only get zero's for the SPEEDVAR even when I try to force a test speed 15000 it still prints as zero's on the console. What am I doing wrong?
Also, can you help me understand the difference between KMVAR and SPEEDVAR?
Jack
So far so good. I need to play with the adjustment pot a little but basically at 128 I got 5 volts and at 255 I got a little over 10 volts. All this time I thought the C6 was using PWM.
I tried to take the next step and modify the canned spindle programs to drive the spindle but didn't get very far. I set bit 27 (direction) and 26 (speed) in the init file and then used the attached file to drive the spindle CCW. This new C41 board does not require a CCW and CW bit. It's either CCW or it's not so I'm only using bit 27 for direction. Using the console it appears that I'm passing the STATEVAR just fine but for some reason I only get zero's for the SPEEDVAR even when I try to force a test speed 15000 it still prints as zero's on the console. What am I doing wrong?
Also, can you help me understand the difference between KMVAR and SPEEDVAR?
Jack
- Attachments
-
- SpindleOnCCWJogDir2.c
- (1.33 KiB) Downloaded 414 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle Interface II
Hi Jack,
Several bugs: Printing the integer SPEEDVAR as a float %f instead of %d. Validate will point out these types of errors:
Checking C:\Users\tk\Downloads\SpindleOnCCWJogDir2.c ...
C:\Users\tk\Downloads\SpindleOnCCWJogDir2.c, line 19 : warning invalidPrintfArgType_float
%f in format string (no. 1) requires 'double' but the argument type is 'signed int'.
printf("Jogging Spindle %f SPEEDVAR/sec\n", SPEEDVAR);
^
Brackets in wrong place. Should be: UserData[SPEEDVAR]
CheckDone takes an axis number not a bit number.
But the main thing you should decide first is how you want to control things. Basically whether to use a KFLOP Axis or not. This would allow you to use Axis Jog commands like you had before. It will also allow using the Axis Acceleration Parameter to gradually ramp up and down the voltage/speed. I would recommend this as it also provides a level of abstraction where the axis is commanded to do things (ie Jog) regardless of the actual type of hardware involved.
Otherwise just writing to the PWM will change the voltage instantly and how it changes speed will be determined entirely by the Spindle Controller.
If using an axis there will need to be a forever loop to output the Axis Output to the PWM. See the Setup Gcode 4 axis PWM signMag.c example
SPEEDVAR defines which persist variable where the last specified speed is saved.
Normally they would be the same. But its possible that the KMVAR is used by other actions and lost so better to explicitly save it somewhere.
HTH
goodSo far so good. I need to play with the adjustment pot a little but basically at 128 I got 5 volts and at 255 I got a little over 10 volts.
Several bugs: Printing the integer SPEEDVAR as a float %f instead of %d. Validate will point out these types of errors:
Checking C:\Users\tk\Downloads\SpindleOnCCWJogDir2.c ...
C:\Users\tk\Downloads\SpindleOnCCWJogDir2.c, line 19 : warning invalidPrintfArgType_float
%f in format string (no. 1) requires 'double' but the argument type is 'signed int'.
printf("Jogging Spindle %f SPEEDVAR/sec\n", SPEEDVAR);
^
Brackets in wrong place. Should be: UserData[SPEEDVAR]
CheckDone takes an axis number not a bit number.
But the main thing you should decide first is how you want to control things. Basically whether to use a KFLOP Axis or not. This would allow you to use Axis Jog commands like you had before. It will also allow using the Axis Acceleration Parameter to gradually ramp up and down the voltage/speed. I would recommend this as it also provides a level of abstraction where the axis is commanded to do things (ie Jog) regardless of the actual type of hardware involved.
Otherwise just writing to the PWM will change the voltage instantly and how it changes speed will be determined entirely by the Spindle Controller.
If using an axis there will need to be a forever loop to output the Axis Output to the PWM. See the Setup Gcode 4 axis PWM signMag.c example
KMVAR defines which persist variable that KMotionCNC should use to pass the speed to KFLOP. Its value must match the Variable KMotionCNC's S Action is configured to use.Also, can you help me understand the difference between KMVAR and SPEEDVAR?
SPEEDVAR defines which persist variable where the last specified speed is saved.
Normally they would be the same. But its possible that the KMVAR is used by other actions and lost so better to explicitly save it somewhere.
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle Interface II
Hi Tom,
I took your advice and am working on using Channel 6 for controlling the spindle. I've started modifying the init file as step 1 but have a question and issue.
First, I'm not sure I have the OutputChan0 and 1 set correctly (lines 361 and 362.
Second, the program validates correctly but won't compile. It keeps asking for a ; on line 416.
I set up a forever loop and then added an If statement to handle an ESTOP but there is a problem with the If.
Attached is my init file.
Thanks for all of your help,
Jack
I took your advice and am working on using Channel 6 for controlling the spindle. I've started modifying the init file as step 1 but have a question and issue.
First, I'm not sure I have the OutputChan0 and 1 set correctly (lines 361 and 362.
Second, the program validates correctly but won't compile. It keeps asking for a ; on line 416.
I set up a forever loop and then added an If statement to handle an ESTOP but there is a problem with the If.
Attached is my init file.
Thanks for all of your help,
Jack
- Attachments
-
- Init File 0925.c
- (11.2 KiB) Downloaded 420 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle Interface II
Ji Jack,
There are also 2 extraneous close brackets at the very end.
The call to:
Should have the first parameter as the Axis Channel used. So in your case it should be 6.
2nd parameter is the PWM to be used. I think you are using PWM0 ?
3rd parameter is your direction bit. If you don't have a direction bit then some unused bit should be used. Or a Virtual Bit. or an LED (46).
HTH
With 'NO_OUTPUT_MODE' nothing is output by the Axis so those aren't used. Your C Code will do the outputting.First, I'm not sure I have the OutputChan0 and 1 set correctly (lines 361 and 362.
C Programs are case sensitive. You have 'If' instead of ''if'. So the Compiler interprets If as a function call which should have a semicolon afterward.Second, the program validates correctly but won't compile. It keeps asking for a ; on line 416.
I set up a forever loop and then added an If statement to handle an ESTOP but there is a problem with the If.
There are also 2 extraneous close brackets at the very end.
The call to:
Code: Select all
void OutputSignMag(int ch, int pwm, int dir_bit);
2nd parameter is the PWM to be used. I think you are using PWM0 ?
3rd parameter is your direction bit. If you don't have a direction bit then some unused bit should be used. Or a Virtual Bit. or an LED (46).
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle Interface II
Hi Tom,
My CNC programming has been on the back burner for awhile. I've been manually turning my spindle on and off and setting the speed but I want to get things talking together. Right now I have 2 problems. Using the programs in the C Programs directory and your previous help I can turn the spindle on, i.e., I can get a PWM wave form on pin 5 of JP6 but I can't turn it off or change the frequency. I have to cycle power to turn it off. Using the small file you sent to me on Sept 8, 2023 I can turn the spindle on and chenge the frequency. It's further down in this discussion.
The second problem is that when I hit the ON CW or ON CCW under the red "S" on the KmotionCNC screen the DRO near the Green "F" (actual forward speed) begins counting up. When I hit the OFF button the same DRO begins counting down back to zero.
I've attached my Init file and the Spindle ON/OFF/SPEED files. Need your help.
Jack
My CNC programming has been on the back burner for awhile. I've been manually turning my spindle on and off and setting the speed but I want to get things talking together. Right now I have 2 problems. Using the programs in the C Programs directory and your previous help I can turn the spindle on, i.e., I can get a PWM wave form on pin 5 of JP6 but I can't turn it off or change the frequency. I have to cycle power to turn it off. Using the small file you sent to me on Sept 8, 2023 I can turn the spindle on and chenge the frequency. It's further down in this discussion.
The second problem is that when I hit the ON CW or ON CCW under the red "S" on the KmotionCNC screen the DRO near the Green "F" (actual forward speed) begins counting up. When I hit the OFF button the same DRO begins counting down back to zero.
I've attached my Init file and the Spindle ON/OFF/SPEED files. Need your help.
Jack
- Attachments
-
- SpindleOnCWJogV2.c
- (1.1 KiB) Downloaded 375 times
-
- SpindleOnCCWJogV2.c
- (1.14 KiB) Downloaded 377 times
-
- SpindleOffJogV2.c
- (685 Bytes) Downloaded 375 times
-
- SpindleMillJogV2.c
- (996 Bytes) Downloaded 379 times
-
- Init File 070724.c
- (11.36 KiB) Downloaded 380 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle Interface II
I think you need Velocity Feed Forward to get the Output to be proportional to commanded speed. Similar to when using a DAC output as described here. Also PID=0 and max Output 255.
You'll need to determine what Spindle Speed corresponds to full PWM of 255.
Also the Spindle Axis should not be included in the DefineCoordSystem6.
You'll need to determine what Spindle Speed corresponds to full PWM of 255.
Also the Spindle Axis should not be included in the DefineCoordSystem6.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle Interface II
Hi Tom,
Thanks for the reply. There appears to be a problem with the link you provided. When clicking on it I just get "The requested page could not be found."
Jack
Thanks for the reply. There appears to be a problem with the link you provided. When clicking on it I just get "The requested page could not be found."
Jack
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle Interface II
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.