Setting S in Tool Setup

Moderators: TomKerekes, dynomotion

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Setting S in Tool Setup

Post by Bill D » Sat May 25, 2019 8:39 pm

Friends,

Setup: Kflop controller, CNC4PC C68 Kflop interface board, CNC4PC C62 Breakout Board, steppers with step encoders feeding back to the stepper driver (purchased as a unit), 4'x4'x12" cnc router, Hyaunyang (?) VFD/2.2Kw water cooled spindle.

I have been able to initialize and run my 4 axis (X, Y, Z and A) successfully on my new Kflop board, but am unable to get spindle speed modulation using the C routine pwm example setting duty cycle to 128, CNC4PC's spindle c progs, or to set anything up directly to modulate the requisite PWM channel through the Tool Panel S command setup.

The C62 breakout board inputs an isolated (separate ground) 12V power source and outputs a 0-10V analog signal to the HY, modulated by PWM0, if I recall, on pin 26 for spindle speed. The C62 contains 3 relays, one of which turns on the spindle, another that controls direction. I have the requisite pins for the relays set up in the Tool Panel M3-M5 to turn things on in either direction, and to stop. These work fine, as the spindle turns on and off when these pins are activated, but it pegs out at 10V/24,000 rpm when on. A trim pot on the breakout board allows me to fine tune maximum voltage to 10.0, and spindle RPM is reduced if this is adjusted below 10V, so I believe the VFD end of things is working.

I have basically been thrashing about trying all sorts of rational and irrational +/- settings/scaling values in the Tool Panel and PWM initialization lines (which I do not fully understand, particularly the modifiers with embedded arithmetic operators +,*) in C to get any modulation of the spindle rpm with no change in the off/24,000 rpm when on, cw or ccw mode. I could be initialiazing the PWM channel incorrectly, setting wrong scaling parameters (one poke at the innards appeared to indicate a PWM value on the order of a billion...). I have added lines to print out these parameters. The monitoring panel parrots the command/value I am sending (rpm or 0-256 pwm counts) but then prints out a value of 0 for these variables immediately.

I am basically an aerospace FORTRAN/Basic dinosaur and script kiddie when it come to programming the board in C, but can generally muddle enough to get things to work. I was able to implement spindle control before via a USB to RS485 converter and the French gentleman's wonderful HY driver under M3. M3 dropped out on me unacceptably often with my previous UC100 controller no matter the settings for the ports, etc. I am trying to set up as short of a command chain as possible (KmotionCNC to the Kflop) bypassing anything in between like Mach 3, or the USB to RS485 converter + M3 driver as a result. The UART to RS485 examples posted look great and make some sense, but I'm afraid I am confused enough now as it is, particularly when it comes to making changes considering the HY not-so-Modbus protocol and my spindle's rpm range (different from the examples if I recall). I did purchase a 3.3v UART to RS485 but doubt I know enough to make everything work together.

Let me know what files/settings you need from me to understand this better...

Thanks in advance, Bill D

User avatar
TomKerekes
Posts: 2540
Joined: Mon Dec 04, 2017 1:49 am

Re: Setting S in Tool Setup

Post by TomKerekes » Sun May 26, 2019 4:33 pm

Hi Bill,

My understanding is that KFLOP's PWM #1 signal goes through the C68 board and comes out Parallel Port #1 connector Pin 14 then enters the C62 board and is converted to a 0-10V analog signal.

So a first step might be to run the test C Program below to create a 500Hz 50% duty cycle PWM signal and check if the analog signal is 5V.

Can you perform that test?

Code: Select all

#include "KMotionDef.h"

#define PWMCHAN 1

main()
{
	int PWM = 128;  // test value 50%
	SetBitDirection(26+PWMCHAN,1);  // define bit as an output
	FPGA(IO_PWMS_PRESCALE) = 130;  	// divide clock by 130 (500 Hz)
	FPGA(IO_PWMS+2*PWMCHAN) = PWM;  // Duty Cycle
	FPGA(IO_PWMS+2*PWMCHAN+1) = 1;  // Enable PWM1
}
Regards,

Tom Kerekes
Dynomotion, Inc.

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Mon May 27, 2019 2:40 pm

Thank you kindly, Tom. Yes, I do believe it it PWM1, not 0. I will let you know how it goes.

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Mon May 27, 2019 5:14 pm

Hi Tom,

1. Opened PC, turned on system (controller, etc.) power, waited for the system check green led. All step and direction LEDs are off at this stage, which I take to mean the system has not run the default init file on startup (this might matter a bit later). Clipped voltmeter across output connector block labeled 0-10v and gnd next to vfd plug / trim pot on c62; measured 0v.

2. Opened KmotionCNC, took snapshots of curent tool setup screens TS1 through TS3.jpg in case they might be helpful, then opened Kmotion to the c file screen.

3. Openet my initialization file I5082520KlimBD.c in "thread1" (default location) and commented out the lines similar to the code you just posted which I had been fiddling with to try and get the 50% duty cycle/ 5V out to the VFD. Noted your code has a line or two more than my attempts than my best efforts from reading you previous posts. Hit the "full monty" button on the right of the editing screen which saves, compiles, downloads and runs the code (?).

4. All 5 "dir" leds on the c62 lit up at this point, which normally happens when I initialize to the board. I assume this is an indicator that the board has been initialized, and that my dir commands default to high, thus the lights.

5. Pasted your code into string 6 and saved as 50pctPWM1.c (TS4.jpg). Full monty'd that to the board.

6. Voltmeter still indicates 0v. Could not confirm this on the cable to the vfd at this point, as it is hard to get a probe on it. VFD has been left unpowered...

7. Opened up the "Digital IO" sheet in Kmcnc, verified IO channel 27 was initialized (box to left checked), and box to the right of it had a blinking check mark, which does not show up in screen capture TS4.jpg. Pin 29 is initialized for the charge pump function, and likewise has a check mark in box to its left, and a blinking check mark in box to its right which I take to mean it is working in PWM mode as well? Bob Safety Charge Pump function appears to be happy... *** It occurs to me that I may be "double-initializing" IO27, once for S in tool screen, and again with your code snippet and getting unexpected results... Your thoughts? ***

8. Just for grins, I set IO38 high in the Digital IO screen, which activates relay 1 in the Bob and gives me 10v at the voltmeter (output previously trimmed for 10V with trimpot).

9. Again, for grins, I set IO38 low, verify 0V, set IO39 high, re-set IO38 high, and again read 10v at the analog output.

Do you have any preference as to whether I "place inline" my attachments?

Thanks,

Bill D
Attachments
TS5.JPG
TS4.JPG
ts3.JPG
ts2.JPG
TS1.JPG
I5082520kLIM2BD.c
(7.54 KiB) Downloaded 107 times
50pctPWM1.c
(320 Bytes) Downloaded 119 times

User avatar
TomKerekes
Posts: 2540
Joined: Mon Dec 04, 2017 1:49 am

Re: Setting S in Tool Setup

Post by TomKerekes » Mon May 27, 2019 5:37 pm

Hi Bill,
8. Just for grins, I set IO38 high in the Digital IO screen, which activates relay 1 in the Bob and gives me 10v at the voltmeter (output previously trimmed for 10V with trimpot).

9. Again, for grins, I set IO38 low, verify 0V, set IO39 high, re-set IO38 high, and again read 10v at the analog output.
It seems IO38 is influencing the analog voltage. That would be PWM #2. Try setting PWM #2 at 50% to see if you get 5V

On a minor side note there is only one global prescale for all 8 PWMs. So setting to 13KHz serves no purpose as it is then changed to 500Hz. But 500Hz is probably ok for the charge pump.
Regards,

Tom Kerekes
Dynomotion, Inc.

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Mon May 27, 2019 6:59 pm

Tom,

I will do that, but hesitate a bit because of the following:

I have IO0 set to high so I could repurpose some pins as drivers for my 5th stepper motor/A-axis. I thought this also shifts IO38 to IO27, connected to pin 1-14 for PWM1, which turns on relay 1 or 2 depending on IO39s state.

I have the following table from my c68 docs (labeled "c32 pins", which I assume are the same as my board) that confuses me, but perhaps you can make sense of it for me:
table1.JPG
table1.JPG (18.8 KiB) Viewed 4102 times


Do I take this to indicate Bob pin 1-14 (either IO27 or IO38) in pwm mode will switch relay 1 or relay 2 on/off PLUS set the PWM duty cycle depending on the state of pin 1-16? If pin 1-14 is at a very low duty cycle, could it trip either relay?

If this is not an issue, how do I change your code correctly to set IO38 to pwm? Do I use SetBitDirection(37+PWMCHAN,1) when defining the bit as output? This is where I could use a little more understanding of the FPGA() command modifiers...

I understand the prescale line, but do not quite follow the arithmetic operators and integers in the modifiers in the last two lines, such as (IO_PWMS+2*PWMCHAN+1) in:
FPGA(IO_PWMS+2*PWMCHAN) = PWM; // Duty Cycle
FPGA(IO_PWMS+2*PWMCHAN+1) = 1; // Enable PWM1

I would be happy to send you links to CNC4PC's initialization and spindle control files for this Bob if it would help. I could not get them to work for me, perhaps due to RPM scaling or some such issue...

Thanks again,

Bill D

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Mon May 27, 2019 8:00 pm

fyi, tried setting the S config in the Tool Setup to "none", no joy...

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Mon May 27, 2019 9:18 pm

fwiw, commented out init file lines defining IO38 and IO39 as outputs.

re-booted kflop, ran board init, verified IO38 and IO39 check boxes cleared in Digital IO screen

Modified 50% pwm code changing 26 to 37, to set PWM 1 on IO38 from IO27.

Saved, compiled, downloaded, ran (scdr) above; IO38 shows up as output, right hand box unchecked, not blinking. Voltage remains 0.

clicked status box for IO38, got a check mark, relay 1 clicked on and voltage climbed to 10.

clicked status box off, V=0, relay off. Clicked both boxes for I039, status box for IO38, relay 2 came on, V=10V. Unchecked both IOs, relay 2 went off and V=0.

*****************

I realized IO38 and IO39 were called in the tool setup screen for M3 and M4 (and turned both off for M5). Changed all these to "none".

Exited KMcnc, rebooted kflop, reopened KMcnc, re-initialized kflop, verified M3-M5 settings were clear in the tool setup screen, and IO38 was un-checked in the digital IO screen.

Ran 50% pwm code again, voltage remained 0, IO38 showed up initialized in digital IO screen but status check mark was not blinking.

Clicked IO38 status box, relay 1 activated (heard click and led came on), voltage went to 10V. Unchecked status box, voltage returned to 0v, relay 1 went off. Checked both boxes for IO39, clicked IO38 status box to checked, relay #2 came on, voltage climbed to 10v. Unchecked both and Voltage returned to zero.

Shut down KM and KMcnc, powered down controller and hardware, re-started everything but the PC, repeated actions following asterix string above with identical results, just in case I had not initialized something correctly.

I'm fresh out of directions to flail in...

Thanks,

Bill D

User avatar
TomKerekes
Posts: 2540
Joined: Mon Dec 04, 2017 1:49 am

Re: Setting S in Tool Setup

Post by TomKerekes » Tue May 28, 2019 2:20 am

Hi Bill,

Ignore the PWM #2 idea. Sorry about that I confused IO38 and IO28.

I think the problem is with the C68 board jumpers. See the manual here:

PWM Jumpers.png
I think this shows that a PWM signal (IO27) can be routed to Port 1 pin 14 or IO38 can be routed to Port 1 pin 14. I think you have the jumpers set like in the bottom section causing IO38 to effect the analog output. Change as the top section.

Until you get the analog signal hardware sorted out please do not run KMotionCNC. That avoids any confusion with KMotionCNC, Tool Setup, MCodes, etc
I understand the prescale line, but do not quite follow the arithmetic operators and integers in the modifiers in the last two lines, such as (IO_PWMS+2*PWMCHAN+1) in:
FPGA(IO_PWMS+2*PWMCHAN) = PWM; // Duty Cycle
FPGA(IO_PWMS+2*PWMCHAN+1) = 1; // Enable PWM1
The FPGA has memory mapped 8-bit registers to do many different things. There are 8 PWMs in the FPGA. Each of the PWMs uses 2 consecutive registers to control it. The first register controls the duty cycle. The 2nd register enables the PWM and allows it to control the output pin. In total there are 16 consecutive registers to control all of the PWMs. So:

IO_PWMS = the address of the first of the 16 PWM registers
IO_PWMS+2*PWMCHAN = the address of the duty cycle register of a selected PWM where PWMCHAN is the desired PWM as a number from 0-7
IO_PWMS+2*PWMCHAN+1 = the address of the enable register

Regarding the CNC4PC Table: I think that is just explaining how the Direction bit controls which relay will come on when there is some PWM activity. And that if there is no PWM activity then both relays will automatically be off regardless of the direction.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Bill D
Posts: 9
Joined: Sat May 25, 2019 7:12 pm

Re: Setting S in Tool Setup

Post by Bill D » Wed May 29, 2019 3:55 pm

Tom,

Do I need to change anything in the init file when I switch these jumpers? In Kmotion (alone), do I need to init the kflop by running my init code first, or do I just run the PWM c code alone and check for voltage change?

<< I think the problem is with the C68 board jumpers. See the manual here:

PWM Jumpers.png

I think this shows that a PWM signal (IO27) can be routed to Port 1 pin 14 or IO38 can be routed to Port 1 pin 14. I think you have the jumpers set like in the bottom section causing IO38 to effect the analog output. Change as the top section. >>

Yes, all my jumpers are set 1-2 for "-If using 6 axes: 1-2" This does appear to limit Pin 1-14 to "dir" output only...


Would re-setting these jumpers to 2-3 put me in a mode where I can only output to 4 of my 5 step/dir axes? Or as long as I have free IO channels can I initialize these for step/dir output? I have 2 controller/steppers on my x axis, one each for y and z, and a rotational A-axis for 5 axes total. Or is the 4 axis limit only when using encoders for feedback to the Kflop?

I'm not sure I understand all the manual says about this:

"Use Jumper depending the the axis that fence to using" ;) C68-R3_USER_MANUAL.PDF Page 2

In case this means more to you than it does to me, I tried sequentially enabling and activating IO ports in Kmotion (with KMotionCNC OFF - duh, thanks!) one by one:

I0# Effect
26 led for pp 2-14 lights up
27 nothing
28 leds for pp 2-16 and relay 3 light up. Relay three can be jumpered to pp 2-17 instead
29 led labeled pp 2-17 lights up
30-35 nothing
36 Axis5 step led on pp 1-1
37 Axis5 dir led on pp 1-17
38 Axis6 step led / relay #1 led on pp1-14
39 Axis6 dir led on, switching IO38 on now activates relay #2, pp1-17

Post Reply