VFD for 180v DC motor

312 views
Skip to first unread message

Aurelien

unread,
Jul 13, 2019, 7:46:14 AM7/13/19
to Machinekit
Hi

I use machinekit for a CNC lathe with Beaglebone Black and Furaday cape, debian 9 up to date, Axis GUI, icewm as DM.

I need to replace my spindle controller board, this is a 180V DC shunt motor 1Hp run ~200 to ~3500rpm.


For now i have only the attached document.


I think this controller is ok for my motor, but for manage the RS232 protocol whith machinekit i'm unsure.

I suspect this need to use one of this VFD driver and adapt the protocol for the ebay controller ?

It is ok for use this with USB/RS232 or is better to use some onboard UART from Beaglebone ?


Best regards, Aurélien
ACRF16 USART simple protocoll codes.pdf
ACRF16 v1.0 basic.pdf
ACRF16 USART advanced protocoll codes.pdf

ce...@tuta.io

unread,
Jul 14, 2019, 9:09:59 AM7/14/19
to Aurelien, Machinekit
Jul 13, 2019, 1:46 PM by golf...@gmail.com:

> Hi
>
> I use machinekit for a CNC lathe with Beaglebone Black and Furaday cape, debian 9 up to date, Axis GUI, icewm as DM.
>
> I need to replace my spindle controller board, this is a 180V DC shunt motor 1Hp run ~200 to ~3500rpm.
>
> I have found this one over ebay : > https://www.ebay.fr/itm/180V-200V-DC-230V-AC-16A-HP-motor-speed-controller-reversible-RS232-CNC-control/183788127346?hash=item2acaa04472:g:hq0AAOSwAE1cz7vg <https://www.ebay.fr/itm/180V-200V-DC-230V-AC-16A-HP-motor-speed-controller-reversible-RS232-CNC-control/183788127346?hash=item2acaa04472:g:hq0AAOSwAE1cz7vg>
>
> For now i have only the attached document.
>
>
> I think this controller is ok for my motor, but for manage the RS232 protocol whith machinekit i'm unsure.
>
> https://github.com/machinekit/machinekit/blob/master/src/hal/user_comps <https://github.com/machinekit/machinekit/blob/master/src/hal/user_comps>
> I suspect this need to use one of this VFD driver and adapt the protocol for the ebay controller ?
>
Hi,
yes, you will need to write simple HAL module. Good thing is it needs not to be real-time, all you need is to send some command every 3 seconds, so simple python script with use of few ready-made libraries will be enough.

Did you bought already or it is just theoretical question?

>
> It is ok for use this with USB/RS232 or is better to use some onboard UART from Beaglebone ?
>
Could be, looks like the pins for UART5 are not used by the cape, but somebody more knowledgeable will have to tell.

Cern.

>
>
> Best regards, Aurélien
>
>
>
> --
> website: > http://www.machinekit.io <http://www.machinekit.io>> blog: > http://blog.machinekit.io <http://blog.machinekit.io>> github: > https://github.com/machinekit <https://github.com/machinekit>
> ---
> You received this message because you are subscribed to the Google Groups "Machinekit" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to > machinekit+...@googlegroups.com <mailto:machinekit+...@googlegroups.com>> .
> Visit this group at > https://groups.google.com/group/machinekit <https://groups.google.com/group/machinekit>> .
> To view this discussion on the web visit > https://groups.google.com/d/msgid/machinekit/53c22a1f-0a11-48e2-9a0f-d461525381d5%40googlegroups.com <https://groups.google.com/d/msgid/machinekit/53c22a1f-0a11-48e2-9a0f-d461525381d5%40googlegroups.com?utm_medium=email&utm_source=footer>> .
> For more options, visit > https://groups.google.com/d/optout <https://groups.google.com/d/optout>> .
>

ce...@tuta.io

unread,
Jul 14, 2019, 10:35:12 AM7/14/19
to Cern, Aurelien, Machinekit
Jul 14, 2019, 3:09 PM by ce...@tuta.io:

> Jul 13, 2019, 1:46 PM by golf...@gmail.com:
>
>> Hi
>>
>> I use machinekit for a CNC lathe with Beaglebone Black and Furaday cape, debian 9 up to date, Axis GUI, icewm as DM.
>>
>> I need to replace my spindle controller board, this is a 180V DC shunt motor 1Hp run ~200 to ~3500rpm.
>>
>> I have found this one over ebay : > https://www.ebay.fr/itm/180V-200V-DC-230V-AC-16A-HP-motor-speed-controller-reversible-RS232-CNC-control/183788127346?hash=item2acaa04472:g:hq0AAOSwAE1cz7vg <https://www.ebay.fr/itm/180V-200V-DC-230V-AC-16A-HP-motor-speed-controller-reversible-RS232-CNC-control/183788127346?hash=item2acaa04472:g:hq0AAOSwAE1cz7vg>
>>
>> For now i have only the attached document.
>>
>>
>> I think this controller is ok for my motor, but for manage the RS232 protocol whith machinekit i'm unsure.
>>
>> https://github.com/machinekit/machinekit/blob/master/src/hal/user_comps <https://github.com/machinekit/machinekit/blob/master/src/hal/user_comps>
>> I suspect this need to use one of this VFD driver and adapt the protocol for the ebay controller ?
>>
> Hi,
> yes, you will need to write simple HAL module. Good thing is it needs not to be real-time, all you need is to send some command every 3 seconds, so simple python script with use of few ready-made libraries will be enough.
>
BTW, it looks like the exact same problem like: https://forum.linuxcnc.org/24-hal-components/36469-rs232-spindle-control?start=0 <https://forum.linuxcnc.org/24-hal-components/36469-rs232-spindle-control?start=0>

>
> Did you bought already or it is just theoretical question?
>
>>
>> It is ok for use this with USB/RS232 or is better to use some onboard UART from Beaglebone ?
>>
> Could be, looks like the pins for UART5 are not used by the cape, but somebody more knowledgeable will have to tell.
>
> Cern.
>
>>
>>
>> Best regards, Aurélien
>>
>>
>>
>> --
>> website: > http://www.machinekit.io <http://www.machinekit.io>> blog: > http://blog.machinekit.io <http://blog.machinekit.io>> github: > https://github.com/machinekit <https://github.com/machinekit>
>> ---
>> You received this message because you are subscribed to the Google Groups "Machinekit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to > machinekit+...@googlegroups.com <mailto:machinekit+...@googlegroups.com>> .
>> Visit this group at > https://groups.google.com/group/machinekit <https://groups.google.com/group/machinekit>> .
>> To view this discussion on the web visit > https://groups.google.com/d/msgid/machinekit/53c22a1f-0a11-48e2-9a0f-d461525381d5%40googlegroups.com <https://groups.google.com/d/msgid/machinekit/53c22a1f-0a11-48e2-9a0f-d461525381d5%40googlegroups.com?utm_medium=email&utm_source=footer>> .
>> For more options, visit > https://groups.google.com/d/optout <https://groups.google.com/d/optout>> .
>>
>
> --
> website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
> ---
> You received this message because you are subscribed to the Google Groups "Machinekit" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/machinekit.
> To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/Ljka_fF--3-1%40tuta.io.
> For more options, visit https://groups.google.com/d/optout.
>

Golfo

unread,
Jul 14, 2019, 1:56:30 PM7/14/19
to ce...@tuta.io, Machinekit
Hi


Thank a lot for reply

Great for UART5 I plan to play with this one soon.

No I didn’t already bought this contrôler I have wait for some reply before. At first I check for PWM controler (this one offers reversing direction this is but the seller suggest me to use rs232.

It is really ok to not be real-time regarding to constant surface cut speed and threading ?

I have write a instanciable component for ATC maybee i can use the same way for drive this controler or adapt some vfd existing driver, because I have a very short experience with python.

Br thanks for interest

ce...@tuta.io

unread,
Jul 15, 2019, 12:01:46 PM7/15/19
to Golfo, Machinekit
Jul 14, 2019, 7:53 PM by golf...@gmail.com:

> Hi
>
>
> Thank a lot for reply
>
> Great for UART5 I plan to play with this one soon.
>
> No I didn’t already bought this contrôler I have wait for some reply before. At first I check for PWM controler (this one offers reversing direction this is but the seller suggest me to use rs232.
>
> It is really ok to not be real-time regarding to constant surface cut speed and threading ?
>
I haven't got the time to study the pertinent part of the code-base yet, so take my suggestions with grain of salt, but I assumed that the motion is synchronized on the speed of the spindle, so you need to have RT capable encoder read-out.

>
> I have write a instanciable component for ATC maybee i can use the same way for drive this controler or adapt some vfd existing driver, because I have a very short experience with python.
>
I have heard people say that python is "easy", but I personally don't like it myself. (Fact still is that there are tonnes of libraries for your pick.) If you are going to write some other component, you can use C/C++ for everything.

But be aware that the VFD components could not be all RT capable, so if you are after RT, always check. Also, mentioned driver wants in basic mode UART on 9600 baudrate with 10 bits per one transferred byte. If you have 1kHz task, you could end missing your constraints only on writes alone. So you will need to look at advanced mode and setting own speed.

Cern.

>
> Br thanks for interest
>
>
>
>> Le 14 juil. 2019 à 15:09, <ce...@tuta.io> <ce...@tuta.io> a écrit :
>>
> --
> website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
> ---
> You received this message because you are subscribed to the Google Groups "Machinekit" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/machinekit.
> To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/A108EC8D-45FE-4D5D-B3DE-D50D0BED8006%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

justin White

unread,
Jul 15, 2019, 1:05:51 PM7/15/19
to Machinekit
Do you really want to go through the trouble of trying to make something work over rs232 just for a brushed DC motor? KB drives have been around for a long time and are probably the best thing to use for small brushes FC motors. This is a pretty good price for a new regen reversing drive, used ones can be had cheaper:

https://www.ebay.com/itm/KB-Electronics-KBMG-212D-DC-motor-control-8831-upc-024822088312/221581346770?epid=1628350059&hash=item33974707d2:g:XUIAAOSwE2lThe8P:sc:USPSPriority!20902!US!-1

You can control it with 0-10v, not sure what kind of hardware you’re running MK with but if you don’t have an analog out you can get pwm-analog boards cheap.

For threading (on a mill) you need a spindle encoder and and an index. I forget what the minimum is, think it’s 400 counts in quadrature. Spindle encoders can be a pain to get mounted, but you can use a proximity switch that counts gear teeth as well.

You get encoder feedback and analog control over the motor you can setup a PID for closed loop spindle control. Rs232 is too iffy for closed loop unless the drive and the component are well sorted.

Aurelien

unread,
Jul 15, 2019, 5:14:25 PM7/15/19
to Machinekit
Hi

I'm not really want "to go through the trouble of trying to make something work over rs232" lol

I have already a KBMG-212D + 24 V PWM à 0-10 V (K24P-10V), my motor shunt have burned so i like to replace the controler before installing the repaired motor.

The starting point for wanting to replace this controler is for have a reversible rotation because primarly i don't have any free wire for add a high power relay directly to the spindle wire for control the motor FW/REV
I don't found any way for generate a negative PWM signal like the datasheet wiring make me think : something is possible with -/+PWM
But now the things are a little different because i have remanaged the wire and now i can try to control one relay for reversing direction.

So if you think is better to keep my actual driver this is off course better for me ^^

MK Beaglebone furaday-cape spindle-encoder for cnc-lathe

Many many thanks for "Rs232 is too iffy for closed loop"


If you have better idea than put a reversible relay to the spindle brush wire you are welcome 

Br





Mon cablage spindle.png

justin White

unread,
Jul 15, 2019, 7:17:35 PM7/15/19
to Machinekit
It's not that rs232 is bad for controlling a motor, I'm sure it's fine. It's just that since nothing readily exists as a hal component and the documentation on that driver is likely poor you'd best use a simpler means.

That's a coincidence your machine already has the same KB drive I suggested. Unfortunately I forgot about the archaic requirement of Bipolar analog +/-0-10v for controlling speed in both directions (I really hate brushed DC motors for things like this). I can't seem to find any PWM to bipolar analog controllers but that's all you would really need to make the drive work reversing, just using schematic F on page 22 of the manual. There's plenty of DIY schematics all over the internet for this but I can't find anything you can just buy.

You can try using the relay to reverse the motor, not sure you the KB drive will like that. On a Shunt wound motor you reverse the field wires to reverse direction. Maybe it's best you look for a drive that accepts PWM or 0-10v analog and will switch direction with a logic input. Honestly I'd ditch the DC setup and grab an AC motor and VFD but I'd assume that's not an option.

justin White

unread,
Jul 15, 2019, 7:24:32 PM7/15/19
to Machinekit
Actually, that Ebay drive accepts PWM:
  • 2 programable controlling modes with the red switch: Potentiometer , PWM input + Serial communication with TTL or the optional RS232/485 boards      
If you look at the green terminal block there is a PWM terminal and a F/R terminal. I'd ask the seller for documentation because you might be able to run it straight from the BB pwm with a separate reverse output

Aurelien

unread,
Jul 15, 2019, 9:31:48 PM7/15/19
to Machinekit
Yes i have found this controler firstly by schearching something with PWM input and possible reverse.

My problem with the ebay controler is to convert my furaday 0/24v PWM to 0/5v PWM isolated, unfortunatly i'm not able to design something like this myself. 
The seller send to me only the 3 first attached documents after waiting and ask again and again from 4 month.
(edit : i have think about keep the k24p-10v with the ebay controler and use the reverse function the easy way)

The KBMG is retrofited when start the project, in reality i like to keep this controler if i can found for reversing (maybee find someone and pay some money for a ready to use solution for this one or for the PWM ebay)

For the suggestion about retrofit AC motor it's i think for a lathe with motor integrated to the spindle this not the best way.

Many thanks for your interest


Ps : Finally you think it is better for spindle accuracy to have a simple PWM (or PWM/analog) with pru or a complex C code comp file with serial communication or this is only more easy to use PWM ? (I'm lost : finalize the order or not lol)

justin White

unread,
Jul 15, 2019, 11:00:04 PM7/15/19
to Machinekit
The Furaday cape says it has 5v PWM outputs on P1....

Maybe you're using a field output as PWM? If you can't get around that these are cheap and worth a try.....

You can feed the 24v PWM into the input and it will output an inverted 5v PWM. I don't have a BBB but looking at hal_pru the pwmgen component has a scale pin and it looks like a value of -1 will invert the PWM and cancel the boards inversion out if it matters which it probably doesn't. You can just use an optocoupler output on that cape to pull the F/R pin to speed_gnd on the driver board to change directions.

The cape handles 0-5v analog outputs as well so you could use that too.

The KB drive is just a PIA at that point. You can use the serial thing but I'm not sure what difference you think it makes. The only thing that serial can do is command a speed output to the driver board. You still have to close the loop with feedback coming from something else, like an encoder which doesn't change regardless of whether you use PWM/serial/or analog. If you command a speed of 300rpms No matter which you choose all it can do is command an output that you tune to be as close to relate to 300RPM as you can. So if you go to take a cut and the spindle bogs down there is no way to detect that unless you have an encoder and run a PID loop. The PID will compensate for the slowdown by increasing or decreasing the output command to hold steady, it could be a serial command to speed up, a PWM duty cycle increase, or an analog voltage increase, it doesn't matter if the PID is setup right.

Analog is a bit more susceptible to noise than PWM. Serial is fine if you really want to deal with it but I'm not sure I see why you would. It looks like if you configure the outputs on your BBB/cape right all really don't need anything extra.

Aurelien

unread,
Jul 16, 2019, 6:35:46 AM7/16/19
to Machinekit
i have the digital version of this cape but i need to keep free the opto and pwm output for future project.
So Marius (the furaday author) help me for manage PWM from Digital output 0 so this is 24v pwm with my setup. (for reverse F/R and enable i use also digital output)

I not fully understand it is ok for use the amazon board you found for convert my PWM to 0/5v PWM (with try to invert pin) and use 2 other channel for enable and direction for the ebay controler?

Than you suggest i now think is better to not use the rs232 except for make all more complicated.

Thanks a lot

justin White

unread,
Jul 16, 2019, 10:09:44 PM7/16/19
to Machinekit
I not fully understand it is ok for use the amazon board you found for convert my PWM to 0/5v PWM (with try to invert pin) and use 2 other channel for enable and direction for the ebay controler?

It should work fine, it's only $5.  It will flip the PWM signal upside down, that might not be an issue at all. If it is change the hal scale pin to -1. The Amazon board I linked to has the wrong truth table shown. This is the right one, you can buy it from here if you want:

wire it up like #4 for your cape

Marius Alksnys

unread,
Jul 17, 2019, 7:06:38 AM7/17/19
to machi...@googlegroups.com
Hi, Aurelien, Hi all!

This is the schematics of Furaday Cape v1.2:
https://drive.google.com/open?id=0B82aedCuGLVAUnJ2cEJGM1lIZ0k

U4 serves for analog outputs 0..10V and was optional (it was possible to
order either analog output version or 5V digital version of the board).

Aurelien

unread,
Jul 17, 2019, 8:19:02 AM7/17/19
to Machinekit
Many many thanks !

I have done the order both your linked isolator and the ebay controler your help was precious !

Come back later with the hardwar test lol


I hope to all a nice day.


ps : at the same time the ebay seller send me this schematics, i think this is close to your link:

Aurelien

unread,
Jul 18, 2019, 4:22:22 AM7/18/19
to Machinekit
Marius i don't see your message before sending my last message.

Thanks a lot for schematics.

Aurelien

unread,
Aug 26, 2019, 10:23:42 PM8/26/19
to Machinekit
Hi

I have now the board in my hand, unfortunatly i wait for the repaired motor but i can start playing with the optocoupler board.

- For enable and fw/rev i have succefully do the change for inverting the pin. but i think this is not safe : at startup the pin was not inverted. (5v on the opto output)

- I can't found the way for reverse the PWM signal but i'm afraid about startup states like enable/reverse

hal :
loadrt hal_bb_gpio output_pins=808,809,810,814,815,817,818 input_pins=811,812,816,831,833,835,911,912,913,915,917,918,924,925,926,927,928,941,942
# NOTE: disable 807 as an output if it is used as a PWM PRU!!!

setp hpg.pwmgen.00.out.00.pin 807
setp hpg.pwmgen.00.out.00.enable 1
setp hpg.pwmgen.00.out.00.scale [SPINDLE]OUTPUT_SCALE
setp hpg.pwmgen.00.pwm_period [SPINDLE]OUTPUT_PERIOD

ini :
# Spindle
[SPINDLE]
ENCODER_SCALE = 400
ENCODER_ABS_SCALE = 400
# Settings below are in Hz
OUTPUT_SCALE = 56.7
OUTPUT_MIN_LIMIT = 0
OUTPUT_MAX_LIMIT = 55
#             #55*60seconde = 3300rpm
OUTPUT_PERIOD = 8000000
MAX_ACC = 30
MIN_SPEED = 0.05


Best regards

Aurelien

unread,
Aug 27, 2019, 8:21:29 AM8/27/19
to Machinekit
Hi

Can you confirm do this change to optoisolator can work fine ?


pwm signal isolator non inverted.png
Message has been deleted

Aurelien

unread,
Aug 27, 2019, 8:36:49 AM8/27/19
to Machinekit
pwm signal isolator non inverted.png

Aurelien

unread,
Aug 27, 2019, 9:58:52 AM8/27/19
to Machinekit
Succefully moded the board for PNP ouptup, i'm happy

reverse all led, swap pin 3/4 and swap Gnd/Vcc

Br

Aurelien

unread,
Sep 7, 2019, 8:33:50 PM9/7/19
to Machinekit
Finally we have misundertanding something because all this controler need to be NPN controled

pwm input set to 5v = 0 rpm
pwm input set to 0v = full rpm

Enable and forward need to be drived to GND so no need to change nothing on this optocoupler logic.

Br

Aurelien

unread,
Dec 12, 2019, 5:02:53 PM12/12/19
to Machinekit
Hi all

I have lost many time with the ebay controler and i'm not really happy with this product, many difficulty for make something work, not really stable and i have at multiple time burned something...


I'm close to work again with some KBMG-212D controler but i like to found a "easy way" for PWM 0/24v to digital +/-10v 
Unfortunatly i'm really unsure about some diy schematics and resistor calculating possible to found on the web.

After spend many time schearching ready to order over the web i have finally found this now and i hope this one is ok ! 
I really like if someone can check a little and can confirm one of these ar ok.

Did you know if i can use directly my pwm output to the converter input choosing the 0/24v input version ?
Or i need to use the my pwm connected to DAC 0/10v and connect DAC outpup choosing the 0/10v input version ?

Any suggestion are really welcome, i'm really affrais to burn something another time.

Many thanks for reading, Br

Aurelien

unread,
Dec 12, 2019, 5:04:07 PM12/12/19
to Machinekit

Aurelien

unread,
Dec 30, 2019, 6:06:10 PM12/30/19
to Machinekit
Hi all

Unfortunatly i have another question related to spindle :

The linked DAC seems to work correctly with my PWM output, but need to tweak pwm for output something like :

0% PWM = -3300rpm
50% PWM = 0rpm
100% PWM = 3300rpm
(i think i have understand that is better to not use 0% to 100% but something like 5% to 95%)

I have try to play with BIAS = 50 with this settings but seems to not work fine for reversing direction.
Also try to change output_scale = 120

hal:


#####################################################################
# Spindel VFD closed loop with PID LOWPASS NEAR SCALE
#####################################################################


newinst pid pid
-s                   # used for closed loop spindle
newinst lowpass lp
-s-fb
newinst near near
-s-fb              # used for spindle at speed
newinst scale scale
-spindle-rpm     # used for display RPM to user


# maxerror is related to the Igain (max value possible to add by pid = Igain x maxerrorI)
setp pid
-s.maxerrorI 0
setp pid
-s.Pgain 0
setp pid
-s.Igain 1
setp pid
-s.Dgain 0
setp pid
-s.bias 50
setp pid
-s.FF0 1
setp pid
-s.FF1 0
setp pid
-s.FF2 0
setp pid
-s.deadband .05
setp pid
-s.maxoutput [SPINDLE]OUTPUT_SCALE


setp near
-s-fb.scale 1.01        # 1.01 Allow 1% / 1.1 Allow 10% for speed cmd vs real
setp lp
-s-fb.gain 0.005




# --- Spindle encoder
setp hpg
.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE  # counts per revolution
setp hpg
.encoder.00.chan.00.filter 1                      # Currently unsupported, included for compatability with hm2. ????  
setp hpg
.encoder.00.chan.00.index-mask 1                  # Currently unsupported, included for compatability with hm2. ????  
                                                         
# disable encoder index as it is not working in pru encoder (finally seems to be ok)
#setp hpg.encoder.00.chan.00.counter-mode 0               # Quadrature mode AB default


net spindle
-index-enable motion.spindle-index-enable <=> hpg.encoder.00.chan.00.index-enable pid-s.index-enable # need testing


# ---Spindle VFD closed loop with PID and compensation
net spindle
-pos hpg.encoder.00.chan.00.position => motion.spindle-revs                           # report our revolution count to the motion controller
net spindle
-vel-fb hpg.encoder.00.chan.00.velocity => lp-s-fb.in #pid-s.feedback                 # report encoder speed to pid and speed filter input

net spindle
-vel-fb-lp lp-s-fb.out => near-s-fb.in2 motion.spindle-speed-in scale-spindle-rpm.in pid-s.feedback # report speed filtered to motion controller + scale input
                                                                                                 
# +report speed filtered to near component  = Yes/No allowed with 1% difference


net spindle
-at-speed near-s-fb.out => motion.spindle-at-speed                                    # connect the near output to motion spindle-at-speed = Yes/No
setp scale
-spindle-rpm.gain 60                                                                   # scale filtered speed RPSx60 = asked RPM
net spindle
-vel-rpm scale-spindle-rpm.out                                                        # create hal for user display asked RPM connected with scale
# ---setup spindle control signals and soft start---
newinst limit2 lim
-s-speed

setp lim
-s-speed.min -[SPINDLE]OUTPUT_MAX_LIMIT
setp lim
-s-speed.max [SPINDLE]OUTPUT_MAX_LIMIT
setp lim
-s-speed.maxv [SPINDLE]MAX_ACC
setp hpg
.pwmgen.00.out.00.scale [SPINDLE]OUTPUT_SCALE
setp hpg
.pwmgen.00.pwm_period [SPINDLE]OUTPUT_PERIOD         # spec du controler ACRF16

net spindle
.is-on motion.spindle-on hpg.pwmgen.00.out.00.enable                           # active pwmgen only when spindle is on from motion

net spindle
-vel-cmd-rps motion.spindle-speed-out-rps lim-s-speed.in near-s-fb.in1
net spindle
-vel-cmd-rps-lim lim-s-speed.out => pid-s.command                        # WITH PID FOR WORKING
#net spindle-vel-cmd-rps-lim lim-s-speed.out => hpg.pwmgen.00.out.00.value            # WITOUT PID FOR TEST
net spindle
-output pid-s.output => hpg.pwmgen.00.out.00.value                    

net spindle
-vel-cmd <= motion.spindle-speed-out
net spindle
-vel-cmd-rpm-abs <= motion.spindle-speed-out-abs

net spindle
.is-on => pid-s.enable fur.do-6                     # output pin



Ini :
# Spindle
[SPINDLE]
ENCODER_SCALE = 400
# Settings below are in Hz
OUTPUT_PERIOD =  10000000
# Settings below are in unit/second
OUTPUT_SCALE = 60
OUTPUT_MAX_LIMIT = 55
#             #55*60seconde = 3300rpm
MAX_ACC = 17


I'm really lost with these spindle settings from long time, any help are really welcome.


Ps : i hope a very good end of the years at all !

justin White

unread,
Dec 30, 2019, 6:50:10 PM12/30/19
to Machinekit
It's not clear whether you are using the Ebay controller of the KBMG drive. Personally I don't like the 0% DC= max revers, 50% DC = 0, 100% DC = Max forward type of control, but that's upto you. If you are still using the ebay controller why don't you just use the F/R pin on the drive to reverse the drive? The hal component motion will do like so with a gpio pin:

net spindle_dir motion.spindle-reverse => bb_gpio.pN.out-NN

I assume you have your polarities all figured out by now. If you want to max duty cycle out @ 95% then it looks like:

setp hpg.pwmgen.N.scale 0.95

Then make your adjustments to your drive that you are getting full speed while it's outputting 95% from BBB PWM

That'll take care of the upper limit, but I wouldn't bother if I were you. Not sure what's wrong with using 0-100% if you're not using the R-0-F setup.

Aurelien

unread,
Dec 30, 2019, 9:48:03 PM12/30/19
to Machinekit
many thanks for reply, i appologize for missing information.

The ebay controler seems to be not very good, i have many problem and have burned these controler after too much attempt for make it work...


For now the new kbmg is not delivered but i have received a new DAC from China and i try to make it work with multimeters.


I have do some investigation and i think the most problem is from pid closed loop
The pwm signal monitored with watch -n0.4 halcmd show pin hpg.pwmgen.00.* show me some result :

(pid Igain = 0, Bias = 60, Pgain = 1, scale = 120, min =-115, max = 115)

ask M4 S3300 = 5% pwm so value are 4.95
ask M4 S1 = ~50% pwm so value are 60
ask M3 S1 = ~50% pwm so value are 60
ask M3 S3300 = 95% so value are 114.95

I agree with you these is not perfect because stop spinlde = 0%.... with R-0-F the drive have a "enable signal input" i hope these is safe...


the problem come when i change Pgain = 0 and Igain = 0.1 or 1 etc

ask M4 S3300 = 0% pwm so value decrease quickly to -120
ask M4 S1 = ~50% pwm so value are 60 but decrease slowly to -120
ask M3 S1 = ~50% pwm so value are 60 increase slowly to 120
ask M3 S3300 = 100% so value are 120



Maybee i have these problem only because encoder show 0rpm for the moment (motor can't run without controler), but i think hpg.pwmgen.value need to stay in, range 0/120 or better 5/115.

setting setp lim-s-speed.min 5 seems to not work fine.

I don't understand how to do the job.

Many thanks, Br

Aurelien

unread,
Dec 30, 2019, 9:52:14 PM12/30/19
to Machinekit
off course i have tested the DAC output regardless to the MK settings but from the cape pwm output
0v on the DAC input = -10v ouptut
24v on the DAC input = +10v outpur
~12v on the DAC input = 0v output

Regards

Hi Ti

unread,
Dec 31, 2019, 11:13:20 AM12/31/19
to Machinekit
You are missing an importance component in your setup. The component from Aliexpress  that you called "DAC" is a signal isolator (converter), and is not a DAC. You need a PWM DAC, which converts PWM signal to DC voltage and is placing between the PWM signal and the isolator's input.


 As Justin has pointed out that when PWM=0V -> full motor reverse is undesirable. This is also somewhat dangerous as when prior components to the KBMG/Isolator (i.e. the BB or the cape) loss power, the motor would kick into a full speed mode.  A simple solution is a FWR/REV signal from BB as Justin has suggested, but need a different circuit and maybe a different isolator than the one you got. 

I would rethink the whole motor driving scheme starting with why motor reversing is needed, motor acceleration/deceleration requirements should be investigated, and what Gcodes are required to do the operation, and go from there with components selection and wiring.

Aurelien

unread,
Dec 31, 2019, 11:55:40 AM12/31/19
to Machinekit
Hi, thanks for reply.

Ok i understand for using that need a DAC before this unit, but i have some working output with direct connection to the cape 0/24v output.

I have ordered a second unit because i'm unsure at start, so first unit is 0/24v to +-10v and the second unit is 0/10v to +-10v i have also a oldest DAC 0/24v to 0/10v so i can test that you suggest, but i think this does not change the PID negative range problem.

Br

Hi Ti

unread,
Dec 31, 2019, 1:08:13 PM12/31/19
to Machinekit
Depending on the frequency response of the isolator amplifiers (which is expecting DC voltage) 24V PWM signal connected directly to the isolator sometimes will work since low frequency response is synonym to a low pass filter, but if the isolator has high enough frequency response, the KBMG might went berserk because it got some ripple at its input.

With PID you need a correct feed back signal from the motor/spindle to determine the speed for the HAL controller algorithm to work. I would definitely disable it if I were you.It is more than a can of worm in your hand.





justin White

unread,
Dec 31, 2019, 1:35:48 PM12/31/19
to Aurelien, Machinekit
You really shouldn't bother with the pid stuff right now. If you don't have a motor that is driving the encoder you dont have proper feedback to operate the pid. I understand what your trying to see, I'm no pid tuning wizard but I don't think you ever want to add I to a Pid and have P at 0. You tune a pid starting with increasing  P, and I and D set to 0. Then move to I.

You could do something like use the offset component on the output of the Pid to shift it left. Using offset to shift the Pid Output half the overall range will put the output negative at minimum and half output will be 0.


This is all undesirable though. If you are using the KBMG it has a +/-15v supply. You can cleverly use a double pole relay to swap  +/-15v supply terminals as they relate to common on the KBMG before going into the signal input. I'd have to look better at the thing you bought to see exactly what it does later.

--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/31333bb3-da24-42af-a3ae-d91802daf7ba%40googlegroups.com.

justin White

unread,
Jan 1, 2020, 1:37:36 AM1/1/20
to Machinekit


Looking at it again you're on the right track if you really want to use the R-0-F thing. It's pretty hard to help you with this because of the way your files are written. Your expectations of what pid is supposed to do is probably off. What you saw happen with the pid output is exactly what should have happened given the circumstances.

(pid Igain = 0, Bias = 60, Pgain = 1, scale = 120, min =-115, max = 115)

ask M4 S3300 = 5% pwm so value are 4.95
ask M4 S1 = ~50% pwm so value are 60
ask M3 S1 = ~50% pwm so value are 60
ask M3 S3300 = 95% so value are 114.95

Pgain is the Propotional change to the output vs the input. Igain is the Integral response of time vs the Error. Here  you ask for a speed of 3300rpms and since there is no encoder it always sees 0rpm. The output of the PID (supposed to be controlling a motor) has to increase to try to get the input (supposed to be an encoder attached to the motor) to increase. This is the whole point of "closed loop'" control. Since you have a proportional gain that is much higher than the integral gain, it just shoots to the max and stays there since the pid output cannot satisfy the input (no motor, no encoder). What you have here is large changes made with no time consideration.

the problem come when i change Pgain = 0 and Igain = 0.1 or 1 etc

ask M4 S3300 = 0% pwm so value decrease quickly to -120
ask M4 S1 = ~50% pwm so value are 60 but decrease slowly to -120
ask M3 S1 = ~50% pwm so value are 60 increase slowly to 120
ask M3 S3300 = 100% so value are 120

This is not a problem, this is what you are asking for. You have no, or very little proportional gain set so the output will not act aggressively to the input, it will make very small changes incrementally. Couple that with the fact that you have now included Integral (time) gain to the pid. What you wound up with here is that it is making very small changes slowly. This is backwards from how you tune a PID but it doesn't matter because you have nothing to feedback and close the loop. The only thing you can get from this is what the minimum and maximum outputs were, but that's not really relevant because you're limiting the pid.

Because of the way you have the hal/ini files written it took me a while to realize what you were trying to do. I decided to write it myself because I enjoy a challenge, which this certainly is because of the hardware you chose to use. It's funny because by the time I was done I realized you were really on the right track. Do yourself a favor and don't worry about the low pass filter and the 5%-95% thing until after you have a working spindle. Your hal file is super hard to read and confusing....and I look at hal files all day. Your main problem I think is using bias of pid for the offset. This is written like a legacy (linuxCNC) hal file but it works fine with MK. You can change the loadrt's and addf's to newinst if you want. Double check for errors because I can't load these files since I don't use the same hardware.

##### HAL FIle

###########################
# Spindle
###########################

loadrt pid names=pid.spindle
loadrt offset names=offset.pwmgen
loadrt near names=near.at-speed
loadrt scale names=scale.spindle-vel-rpm 

addf pid.spindle.do-pid-calcs             servo-thread
addf offset.pwmgen.update-output.funct    servo-thread
addf near.at-speed                        servo-thread
addf scale.spindle-speed-rpm              servo-thread

# scale RPS to RPM
setp scale.spindle-vel-rpm.gain [SPINDLE]VELOCITY_RPM_GAIN

# setup Spindle PID
setp pid.spindle.Pgain     [SPINDLE]P
setp pid.spindle.Igain     [SPINDLE]I
setp pid.spindle.Dgain     [SPINDLE]D
setp pid.spindle.FF0       [SPINDLE]FF0
setp pid.spindle.FF1       [SPINDLE]FF1
setp pid.spindle.FF2       [SPINDLE]FF2
setp pid.spindle.bias      [SPINDLE]BIAS
setp pid.spindle.deadband  [SPINDLE]DEADBAND
setp pid.spindle.maxerror  [SPINDLE]MAX_ERROR
setp pid.spindle.maxoutput [SPINDLE]MAX_OUTPUT

setp hpg.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE
setp hpg.encoder.00.chan.00.counter-mode 0

setp hpg.pwmgen.00.out.00.pwm_period [SPINDLE]PWM_PERIOD

setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE

# offset the pid output the value of max output to shift the output above 0
setp offset.pwmgen.offset [SPINDLE]MAX_OUTPUT
net DAC-ctrl-in <= pid.spindle.out
net DAC-ctrl-in => offset.pwmgen.in

# scale max expected input * 2 to equal a PWM duty cycle of 1.0 
setp hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE

# set the pwmgen output pin
setp hpg.pwmgen.00.out.00.pin 921

# encoder connections
net spindle-pos <= hpg.encoder.00.chan.00.position 
net spindle-pos => motion.spindle-revs

net spindle-vel-fb-rps <= hpg.encoder.00.chan.00.velocity
net spindle-vel-fb-rps => motion.spindle-speed-in
net spindle-vel-fb-rps => scale.spindle-speed-rpm.in
net spindle-vel-scaled-rpm <= scale.spindle-speed-rpm

# Speed command in RPS
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => pid.spindle.command

# offset output to feed to pwmgen output
net DAC-ctrl-out <= offset.pwmgen.out
net DAC-ctrl-out => hpg.pwmgen.00.out.00.value


# Spindle control signals
net spindle-enable <= motion.spindle-on
net spindle-enable => pid.spindle.enable
net spindle-enable => fur.do-6
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => near.at-speed.in1 
net spindle-vel-fb-rps  => near.at-speed.in2
net spindle-at-speed <= near.at-speed.out
net spindle-at-speed => motion.spindle-at-speed 


##### INI File

#############
# SPINDLE
#############

[SPINDLE]
# PID, input is RPS
OUTPUT_PERIOD =  10000000
P = 0.1
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_ERROR = 0.0
#Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. 
MAX_OUTPUT = 55.00
# quadrature mode (mode-0) is encoder PPR * 4
ENCODER_SCALE = 1600
# scale pid output to pwm control value. Max duty cycle of 1.0 / (Max speed * 2) ---range of both directions
PWM_OUTPUT_SCALE = 110
# PWMgen output frequency in Hz
PWM_PERIOD = 10000000
AT_SPEED_SCALE = 1.01
VELOCITY_RPM_GAIN = 60







Aurelien

unread,
Jan 1, 2020, 10:35:40 AM1/1/20
to Machinekit
Hi

Happy new year to all !!


A ton of thanks, i's more than expected ! For sure your file is really better writed for reading/understanding.

setp hpg.pwmgen.00.out.00.pin 807 # Digital out from cape Do-0
maybee this is the type of this cape output that make it work directly to the isolator/convertor ? As you can see i have short knowledge for all this pwm dac spindle stuff.

As i have check 




I paste the updated file like you write :

Saisissez le code ici...





[SPINDLE]
# PID, input is RPS

P
= 1

I
= 0.0
D
= 0.0
FF0
= 0.0
FF1
= 0.0
FF2
= 0.0
BIAS
= 0.0
DEADBAND
= 0.0
MAX_ERROR
= 0.0
#Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS.
MAX_OUTPUT
= 55.00
# quadrature mode (mode-0) is encoder PPR * 4

ENCODER_SCALE
= 400

Aurelien

unread,
Jan 1, 2020, 10:48:24 AM1/1/20
to Machinekit
Sorry bad clicl publish too early


Hi

Happy new year to all !!


A ton of thanks, i's more than expected ! For sure your file is really better writed for reading/understanding.

setp hpg.pwmgen.00.out.00.pin 807 # Digital out from cape Do-0
maybee this is the type of this cape output that make it work directly to the isolator/convertor ? As you can see i have short knowledge for all this pwm dac spindle stuff.

As i have check all work as wanted from -10.2v to +9.6v accroding to asked speed and direction.

Only one problem with the half (55) value that provide ~+2v to the isolator output in place of wanted 0v (maybee only need to replace change the offset value not tested for now)



I paste the updated file like you write :

#####################################################################
# Spindel VFD closed loop with PID NEAR SCALE and OFFSET for Rev/fw -10v 0v +10v
# from 0/24v PWM out to 0/10v Analog to -10v 0v +10v isolator/convertissor
#####################################################################



loadrt pid names
=pid.spindle
loadrt offset names
=offset.pwmgen
loadrt near names
=near.at-speed
loadrt scale names
=scale.spindle-vel-rpm


addf pid
.spindle.do-pid-calcs             servo-
thread
addf offset
.pwmgen.update-output          servo-thread
addf near
.at-speed                        servo-thread
addf scale
.spindle-vel-rpm                servo-thread


# scale RPS to RPM
setp scale
.spindle-vel-rpm.gain [SPINDLE]VELOCITY_RPM_GAIN


# setup Spindle PID
setp pid
.spindle.Pgain     [SPINDLE]P
setp pid
.spindle.Igain     [SPINDLE]I
setp pid
.spindle.Dgain     [SPINDLE]D
setp pid
.spindle.FF0       [SPINDLE]FF0
setp pid
.spindle.FF1       [SPINDLE]FF1
setp pid
.spindle.FF2       [SPINDLE]FF2
setp pid
.spindle.bias      [SPINDLE]BIAS
setp pid
.spindle.deadband  [SPINDLE]DEADBAND
setp pid
.spindle.maxerror  [SPINDLE]MAX_ERROR
setp pid
.spindle.maxoutput [SPINDLE]MAX_OUTPUT


setp hpg
.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE
setp hpg
.encoder.00.chan.00.counter-mode 0



setp hpg
.pwmgen.00.pwm_period [SPINDLE]PWM_PERIOD
setp hpg
.pwmgen.00.out.00.enable 1  # allow to be at half value when spindle is off due to offset use but maybee bad idea ??



setp near
.at-speed.scale [SPINDLE]AT_SPEED_SCALE


# offset the pid output the value of max output to shift the output above 0
setp offset
.pwmgen.offset [SPINDLE]
MAX_OUTPUT
net DAC
-ctrl-in <= pid.spindle.output
net DAC
-ctrl-in => offset.pwmgen.in



# scale max expected input * 2 to equal a PWM duty cycle of 1.0
setp hpg
.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE


# encoder connections
net spindle
-pos <= hpg.encoder.00.chan.00.position
net spindle
-pos => motion.spindle-revs


net spindle
-vel-fb-rps <= hpg.encoder.00.chan.00.velocity
net spindle
-vel-fb-rps => motion.spindle-speed-in

net spindle
-vel-fb-rps => scale.spindle-vel-rpm.in
net spindle
-vel-rpm <= scale.spindle-vel-rpm.out  # name changed according to my other config for display axctual rpm (actually unfiltered)
net spindle
-vel-cmd <= motion.spindle-speed-out   # added according to my other config for display asked rpm



# Speed command in RPS
net spindle
-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle
-vel-cmd-rps => pid.spindle.command


# offset output to feed to pwmgen output
net DAC
-ctrl-out <= offset.pwmgen.out
net DAC
-ctrl-out => hpg.pwmgen.00.out.00.value




# Spindle control signals
net spindle
-enable <= motion.spindle-on
net spindle
-enable => pid.spindle.enable
net spindle
-enable => fur.do-6
net spindle
-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle
-vel-cmd-rps => near.at-speed.in1
net spindle
-vel-fb-rps  => near.at-speed.in2
net spindle
-at-speed <= near.at-speed.out
net spindle
-at-speed => motion.spindle-at-speed

Aurelien

unread,
Jan 1, 2020, 12:32:43 PM1/1/20
to Machinekit
Sorry i allways miss some information :

until now i have only
 Do=0 cape 0/24v PWM out to -10v 0v +10v isolator/convertissor to multimeter


I have do some test with I = 0.1 and work fine the value increase/decrease slowly in the good range (without input rpm) as excepted regarding to asked rpm.

What you think about about adding to ini a "OFFSET_OUTPUT = xx" for finding 0v center point ? or there is better way to do this ?

the isolator/convertissor have some potentiometer for set zero and span but impossible to decrese deeper he is already set to min zero i can only increase  to more than +2v.

Br







justin White

unread,
Jan 1, 2020, 1:50:42 PM1/1/20
to Machinekit
Do you have your motor hooked up, attached to the spindle and your encoder installed and wired in? If not why are you worried about adjusting the PID? you are chasing your tail here. First I have to ask, do you understand that the PID is trying to close the control loop but without having a motor for it to control and an encoder or something feeding back to it it can't do anything right. It's like driving a car with your eyes closed, you probably won't make it to where you are trying to go.........

So why are you adjusting the PID? It's there in the config because you WILL be using it later, but whatever you do right now with it is going to be erroneous.

If you just want to play with the stuff you have then disconnect the pid from the config. 

if at full speed reverse (request -3300rpm) "motion.spindle-speed-out-rps" pin is at ~-55, then don't mess with the offset, you'll be defeating the purpose of it. If you want to play with it without the real encoder functioning then comment out these lines:
net DAC-ctrl-in <= pid.spindle.output
net DAC
-ctrl-in => offset.pwmgen.in

And add these lines right beneath it so you know what you changed for testing:
#FOR TESTING
net spindle
-vel-cmd-rps => offset.pwmgen.in

That will disconnect the PID and pipe the motion speed command straight into the offset component so you can test whatever else. Verify these things

If at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 0, and your PWM is at ~0, 
If at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 55, and your PWM is at ~50% or~12v
If at full forward(55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 110, and your PWM is at ~100% or~24v

If all of that is about the case then you are done. You "DAC" is not doing what you want it to and you need to either adjust it or get rid of it. There's already alot of funny business going on with this config and you don't want to keep trying to adjust offsets and add this and add that, your setup will not be safe.

setp hpg.pwmgen.00.out.00.enable 1  # allow to be at half value when spindle is off due to offset use but maybee bad idea ??

Yes, you need to keep the pwmgen enabled because of this setup, I probably missed it when I wrote it, like I said, I don't have this hardware to test. This is why you need to use this 

net spindle-enable => fur.do-6

You need to hook this output up to a relay that will operate the enable of the KBMG. when the spindle is requested off it will disable the KBMG, that way you don't rely solely on the PWM to output @50% and the "dac" thing to remain at 0v to keep the spindle stopped. This is pretty much how it will have to be to be safe. You may even want to integrate the motion.spindle-inhibit pin once it gets running to further increase safety.

justin White

unread,
Jan 1, 2020, 2:42:51 PM1/1/20
to Machinekit
In addition to the above, if the outputs of the offset component are correct, the only thing you should really adjust is the  "hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE"

It should be scaled correctly as is however there may be some delays or inconsistencies of the PWM between the BBB and the cape. Again, first verify that the component values I listed above look as they should, then I would focus on making sure at 0 RPM that the cape is outputting 50%. Also keep in mind that most multimeters cannot measure PWM correctly, what kind of meter are you using? 

Your dac may not like the PWM frequency it is receiving either changing hpg.pwmgen.00.out.00.pwm_period [SPINDLE]PWM_PERIOD might help that. 

I would certainly be using a scope to verify the PWM in this case, there's just too much going on here.

Aurelien

unread,
Jan 1, 2020, 5:36:49 PM1/1/20
to Machinekit
No for the moment motor is not attached, but encoder is attached.

Sorry i think i have understand but have try PID only for testing where goes the min and max limit.

Yes without tunned PID or with testing "net spindle-vel-cmd-rps => offset.pwmgen.in"
at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 0, and your PWM is at ~0%,  or~1.1v    output -10.2v
at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 55, and your PWM is at ~50% or~14.9v   output +1.8v
at full forward(55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 110, and your PWM is at ~100% or~23.9v   output 9.7v

measured with 2 different multimeters, one old style metrix with needle and one cheapest modern style numerical

for motion.spindle-inhibit and
for relay this is already doing with the "net spindle-enable => fur.do-6"


For now i think all is in the good way and ready for PID except the 0rpm PWM output value that is not 100% linear and is more than 12v

For the second post for now i don't have any DAC connected this test are doing only from cape Do-0 to chinese isolator 0/24v to +-10v.


You can be sure i hear you for any better material setting for this motor 180vdc + shunt 1Hp (like to have both direction + some braking) managed by Digital out from furaday cape, i have already lost a lot of time and money for this spindle but i really like to finish this retrofit correctly.

For now i have :
2x burned KBMG-212D
2x burned ebay controler
2x opto isolator board 24v to 5v link
1x chinese isolator 24v to +-10v link
1x chinese isolator 10v to +-10v link
2x chinese DAC 24v to 0/10v link
some LM358 for diy use
i wait delivery for 


Another time many thanks

Aurelien

unread,
Jan 1, 2020, 5:39:05 PM1/1/20
to Machinekit
for motion.spindle-inhibit i need to investigate

Aurelien

unread,
Jan 1, 2020, 5:57:32 PM1/1/20
to Machinekit
with 
PWM_PERIOD = 20000000
isolator Zero to minimum

at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 0, and your PWM is at ~0%,  or~1.1v    output -10.2v
at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 55, and your PWM is at ~50% or~13.8v   output +0.65v

Aurelien

unread,
Jan 1, 2020, 7:09:25 PM1/1/20
to Machinekit
One other thing is not safe, if i close the GUI without stopping spindle or clicked power off button
-enable signal stay activated (so enable relay stay closed)
-pwm value stay to last value
Restarting the GUI and waiting HAL started to default value stop the spindle.

I have this problem from long time before changing the config.

Br

justin White

unread,
Jan 1, 2020, 8:06:47 PM1/1/20
to Machinekit
Try increasing  the PWM_OUTPUT_SCALE. I don't think the HPG PWM thing is particularly well sorted. 

I don't know what to tell you about the outputs staying on after a crash. It might be something to do with the way MK controls PRU pins or something. If there is another output pin that does not do this, use that pin to control the relay.

Aurelien

unread,
Jan 1, 2020, 8:37:01 PM1/1/20
to Machinekit
Increase scale allow me to found some point with 0v output for 0RPM resulting other value also affected (i think this is possible to tune the controller for make correct speed in both direction)

with 
PWM_PERIOD = 20000000
PWM_OUTPUT_SCALE = 121
isolator Zero to minimum

at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 0, and your PWM is at ~0%,  or~1.1v    output -10.2v
at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 55, and your PWM is at ~50% or~12.9v   output 0/-0.01v
at full forward(55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 110, and your PWM is at ~100% or~22.8   output 8.6v



Thanks for the suggestion about testing other output pin !!

justin White

unread,
Jan 1, 2020, 9:01:49 PM1/1/20
to Machinekit
Why is the PWM pin outputting anything if the input value is 0? You should try commenting out tthe line with hpg.pwmgen.00.out.00.value pin and setp that pin to 0.0. Zero is zero no matter how you scale it. I don't know if maybe your meter is seeing some type of noise on the board or something else is wrong.

You don't have to worry about getting it perfect, When the PID is connected it will constantly adjust the output to try to satisfy the input as long as it is setup correctly. That is you you cannot do these tests with it connected in the hal file.

Aurelien

unread,
Jan 1, 2020, 9:36:18 PM1/1/20
to Machinekit
with 
PWM_PERIOD = 20000000
PWM_OUTPUT_SCALE = 150
OFFSET_OUTPUT = 66
isolator Zero set as arbitrary position
isolator Span set close to max

at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 1, and your PWM is at ~0%,  or~3.77v    output -7.58v
at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 66, and your PWM is at ~50% or~12.81v   output 0/-0.04v
at full forward(55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 121, and your PWM is at ~100% or~21.3   output 7.33v

What do you think of this ?

asked test :
#net DAC-ctrl-out => hpg.pwmgen.00.out.00.value
setp hpg.pwmgen.00.out.00.value 0

Do-0 = 1.27v




Aurelien

unread,
Jan 1, 2020, 9:42:25 PM1/1/20
to Machinekit
during this test i have also try to increase max_output to 60 for have some more resolution than needed.

justin White

unread,
Jan 1, 2020, 11:13:58 PM1/1/20
to Machinekit
What do you think of this ?

 
I think that you should stop changing everything to try to make up for hardware issues.

the output of offset needs to stay linked to MAX_OUTPUT as I had it. It needs to match the max output or it's defeating the purpose.

you were better off where you started here:


PWM_PERIOD = 20000000
isolator Zero to minimum

at full reverse (-55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 0, and your PWM is at ~0%,  or~1.1v    output -10.2v
at 0 speed (0 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 55, and your PWM is at ~50% or~13.8v   output +0.65v
at full forward(55 on "motion.spindle-speed-out-rps") the "offset.pwmgen.out" pin is at 110, and your PWM is at ~100% or~23.9v   output 9.7v

Because the KB drive works with 0-10v or 0-15v, it does not scale beyond this. @ 8v you can't get your motor at full speed. You can adjust the deadband pot of the KB drive so it does not care about the 0.65v plus you need to have that relay working to disable it when the spindle is supposed to be stopped. Again don't try to make up for hardware issues by messing up the config.

I suggest you put everything back to that and stop messing with it until you get your motor and encoder hooked up. If your not happy with it you should probably abandon the brushed DC motor thing, there's a reason nobody uses brushed DC motors in new designs anymore, they are antiquated and a pain in the ass.

Aurelien

unread,
Jan 2, 2020, 6:37:20 AM1/2/20
to Machinekit
For the motor replacement i think it's really not easy and something like messing for the machine because this one is a integrated to spindle 

I'm happy this is now really better than my old configuration !! You are right i wait for delivery before start again to play with the spindle config.
Don"t afraid for the relay, this one work fine already except if i close GUI before stopping spindle or machine power.


One other question, i like to know what do you think about using spindle orient M19 with this type of motor/config/hardware ?

Really thanks a lot for your help and rewrite ! Have a nice day

Aurelien

unread,
Jan 2, 2020, 7:54:08 AM1/2/20
to Machinekit
I have test all the output they do the same things but i have see something related to "net drv_enable axis.0.amp-enable-out"  used for enable driver signal, this one is revert to default after stopping GUI.

so i have do and seems to work fine :


loadrt and2 names=and2.spindle-ena
addf and2.spindle-ena                     servo-thread


# Spindle control signals + and2 for stop spindle after stopping GUI
net spindle-enable <= motion.spindle-on
net spindle-enable => pid.spindle.enable
net spindle-enable => and2.spindle-ena.in0
net drv-enable => and2.spindle-ena.in1
net spindle-and2enable <= and2.spindle-ena.out
net spindle-and2enable => fur.do-6


It is ok for you ?

Aurelien

unread,
Jan 2, 2020, 9:14:56 AM1/2/20
to Machinekit

# Spindle control signals + and2 for stop spindle after stop GUI
net spindle-enable <= motion.spindle-on
net spindle-enable => and2.spindle-ena.in0
net drv-enable => and2.spindle-ena.in1
net spindle-and2enable <= and2.spindle-ena.out
net spindle-and2enable => pid.spindle.enable
net spindle-and2enable => fur.do-6


adding pid.spindle.enable and now the PWM output is also revert to offset !!

really happy

justin White

unread,
Jan 2, 2020, 9:47:25 AM1/2/20
to Aurelien, Machinekit
The and2 component is fine but what I was assuming was that you were saying the hardware pins were staying frozen in state when the display program crashed.  All software enables already drop out so it sounds like the hardware has hung....dont think and2 will help you with that. Which is why I said try to use a different hardware pin that is maybe not a PRU pin. I dont even think a watchdog/chargepump will help if the hardware has stuck.


M19 should work if you get your encoder hooked up right. Is it really only a 100ppr encoder? A bit low in my opinion. The encoder needs an index as well for that.



--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.

Aurelien

unread,
Jan 2, 2020, 10:26:26 AM1/2/20
to Machinekit
Yes only 100ppr quadrature (one years ago the motor run fine according to pid and encoder for single direction with old DAC and KBMG)

Yes i have a index working pin.
I do not dare to abuse yet but i like trying to include the needed config for orient spindle with some help.

Not sur i understand fine the first part : you says more or less to replace or modify the cape for use other pin ? 
For now only have some free digital out pin (+ encoder eQEP0 eQEP2 EncX free pin + analogic Ain0 to Ain3) all other pin are already used.




Aurelien

unread,
Jan 2, 2020, 10:26:55 AM1/2/20
to Machinekit

Aurelien

unread,
Jan 2, 2020, 12:18:58 PM1/2/20
to Machinekit
One more things, your setup doesn't need "pid.spindle.feedback" ?

justin White

unread,
Jan 2, 2020, 1:34:22 PM1/2/20
to Aurelien, Machinekit
It does

Connect the spindle-vel-fb-rps signal to the pid fb pin.

On Thu, Jan 2, 2020, 12:19 PM Aurelien <golf...@gmail.com> wrote:
One more things, your setup doesn't need "pid.spindle.feedback" ?

--
You received this message because you are subscribed to a topic in the Google Groups "Machinekit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/machinekit/hD50Ilh6IPI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to machinekit+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/0fafc139-b0e9-4ba3-b88a-fa6267dad57b%40googlegroups.com.

Aurelien

unread,
Jan 2, 2020, 2:44:49 PM1/2/20
to Machinekit
perfect !

i try to match something like this for spindle orient :


Le jeudi 2 janvier 2020 19:34:22 UTC+1, justin White a écrit :
It does

Connect the spindle-vel-fb-rps signal to the pid fb pin.
On Thu, Jan 2, 2020, 12:19 PM Aurelien <golf...@gmail.com> wrote:
One more things, your setup doesn't need "pid.spindle.feedback" ?

--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to a topic in the Google Groups "Machinekit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/machinekit/hD50Ilh6IPI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to machi...@googlegroups.com.

Aurelien

unread,
Jan 2, 2020, 6:49:43 PM1/2/20
to Machinekit
My attempt :

#####################################################################
# Spindel VFD closed loop : PID NEAR SCALE OFFSET for Rev/stop/fw -10v 0v +10v
# from 0/24v PWM to +-10v isolator/convertissor
#####################################################################

loadrt pid names=pid.spindle
loadrt offset names=offset.pwmgen
loadrt near names=near.at-speed
loadrt scale names=scale.spindle-vel-rpm 
loadrt and2 names=and2.spindle-ena

addf pid.spindle.do-pid-calcs             servo-thread
addf offset.pwmgen.update-output          servo-thread
addf near.at-speed                        servo-thread
addf scale.spindle-vel-rpm                slow-thread
addf and2.spindle-ena                     servo-thread

# scale RPS to RPM
setp scale.spindle-vel-rpm.gain [SPINDLE]VELOCITY_RPM_GAIN

# setup Spindle PID
setp pid.spindle.Pgain     [SPINDLE]P
setp pid.spindle.Igain     [SPINDLE]I
setp pid.spindle.Dgain     [SPINDLE]D
setp pid.spindle.FF0       [SPINDLE]FF0
setp pid.spindle.FF1       [SPINDLE]FF1
setp pid.spindle.FF2       [SPINDLE]FF2
setp pid.spindle.bias      [SPINDLE]BIAS
setp pid.spindle.deadband  [SPINDLE]DEADBAND
setp pid.spindle.maxerror  [SPINDLE]MAX_ERROR
setp pid.spindle.maxoutput [SPINDLE]MAX_OUTPUT

# setup hardwar (encoder + PWMgen)
setp hpg.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE
setp hpg.encoder.00.chan.00.counter-mode 0

setp hpg.pwmgen.00.pwm_period [SPINDLE]PWM_PERIOD
setp hpg.pwmgen.00.out.00.enable 1                # allow to be at half value when spindle is off due to offset

# offset the pid output the value of max output to shift the pwm output above 12v for output 0v from +-10 DAC
setp offset.pwmgen.offset [SPINDLE]OFFSET_OUTPUT
net DAC-ctrl-in <= pid.spindle.output
net DAC-ctrl-in => offset.pwmgen.in
#net spindle-vel-cmd-rps => offset.pwmgen.in      # for bypass PID only for some test

# scale max expected input * 2 to equal a PWM duty cycle of 1.0 
setp hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE

# encoder connections
net spindle-pos <= hpg.encoder.00.chan.00.position 
net spindle-pos => motion.spindle-revs

net spindle-vel-fb-rps <= hpg.encoder.00.chan.00.velocity
net spindle-vel-fb-rps => motion.spindle-speed-in
net spindle-vel-fb-rps => scale.spindle-vel-rpm.in
net spindle-vel-fb-rps => pid.spindle.feedback

net spindle-vel-rpm <= scale.spindle-vel-rpm.out
net spindle-vel-cmd <= motion.spindle-speed-out

# Speed command in RPS
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => pid.spindle.command

# offset output to feed to pwmgen output
net DAC-ctrl-out <= offset.pwmgen.out
#net DAC-ctrl-out => hpg.pwmgen.00.out.00.value                  # do in the orient mux2

# Spindle control signals + and2 for stop spindle after stop GUI
net spindle-enable <= motion.spindle-on
net spindle-enable => and2.spindle-ena.in0
net drv-enable => and2.spindle-ena.in1
net spindle-and2enable <= and2.spindle-ena.out
net spindle-and2enable => pid.spindle.enable
#net spindle-and2enable => fur.do-6                               # do in the orient or2

# Spindle at speed near signal
setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => near.at-speed.in1 
net spindle-vel-fb-rps  => near.at-speed.in2
net spindle-at-speed <= near.at-speed.out
net spindle-at-speed => motion.spindle-at-speed 

#####################################################################


#####################################################################
# Spindle orient mode
#####################################################################
loadrt orient names=orient.spindle
loadrt pid names=pid.orient-value
loadrt offset names=offset.orient
loadrt near names=near.orient-ok
loadrt or2 names=or2.orient-ena
loadrt and2 names=and2.orient-ena
loadrt mux2 names=mux2.orient-value

addf orient.spindle                       servo-thread
addf pid.orient-value.do-pid-calcs        servo-thread
addf offset.orient.update-output          servo-thread
addf near.orient-ok                       servo-thread
addf or2.orient-ena                       servo-thread
addf and2.orient-ena                      servo-thread
addf mux2.orient-value                    servo-thread

# setup Orient Spindle PID
setp pid.orient-value.Pgain     [ORIENT]P
setp pid.orient-value.Igain     [ORIENT]I
setp pid.orient-value.Dgain     [ORIENT]D
setp pid.orient-value.FF0       [ORIENT]FF0
setp pid.orient-value.FF1       [ORIENT]FF1
setp pid.orient-value.FF2       [ORIENT]FF2
setp pid.orient-value.bias      [ORIENT]BIAS
setp pid.orient-value.deadband  [ORIENT]DEADBAND
setp pid.orient-value.maxerror  [ORIENT]MAX_ERROR
setp pid.orient-value.maxoutput [ORIENT]MAX_OUTPUT


# Set asked mode from M19 P0/1/2
net spindle-orient-mode <= motion.spindle-orient-mode
net spindle-orient-mode => orient.spindle.mode


# Spindle orient control signals + and2 for stop spindle after stop GUI
net spindle-orient-enable <= motion.spindle-orient
net spindle-orient-enable => and2.orient-ena.in0
net drv-enable => and2.orient-ena.in1
net spindle-orient-and2enable <= and2.orient-ena.out
net spindle-orient-and2enable => orient.spindle.enable
net spindle-orient-and2enable => mux2.orient-value.sel
net spindle-orient-and2enable => pid.orient-value.enable


# enable out for controler from regular spindle or orient mode
net spindle-and2enable => or2.orient-ena.in0
net spindle-orient-and2enable => or2.orient-ena.in1
net spindle-orient-or2enable <= or2.orient-ena.out
net spindle-orient-or2enable => fur.do-6


# Spindle at orient near signal
net spindle-pos => orient.spindle.position
net spindle-pos => pid.orient-value.feedback
net spindle-pos => near.orient-ok.in2

net spindle-orient_cmd <= motion.spindle-orient-angle
net spindle-orient_cmd => near.orient-ok.in1
net spindle-orient_cmd => orient.spindle.angle

net spindle-is-oriented <= near.orient-ok.out
net spindle-is-oriented => motion.spindle-is-oriented


# Rotation command in degree
net spindle-orient-pid-cmd <= orient.spindle.command
net spindle-orient-pid-cmd => pid.orient-value.command


# offset the pid output the value of max output to shift the pwm output above 12v for output 0v from +-10 DAC
setp offset.orient.offset [SPINDLE]OFFSET_OUTPUT
net DAC-ctrl-orient-in <= pid.orient-value.output
net DAC-ctrl-orient-in => offset.orient.in


# offset output to feed to pwmgen output + mux with regular spindle modul
net DAC-ctrl-orient-out <= offset.orient.out
net DAC-ctrl-orient-out <= mux2.orient-value.in1
net DAC-ctrl-out        => mux2.orient-value.in0
net DAC-computed-ctrl-out <= mux2.orient-value.out
net DAC-computed-ctrl-out => hpg.pwmgen.00.out.00.value



#####################################################################


# Spindle
[SPINDLE]
# PID, input is RPS
P = 1
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_ERROR = 0.0
#Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. 
MAX_OUTPUT = 55.00
OFFSET_OUTPUT = 55
# quadrature mode (mode-0) is encoder PPR * 4
ENCODER_SCALE = 400
# scale pid output to pwm control value. Max duty cycle of 1.0 / (Max speed * 2) ---range of both directions 
# +30 for having correct 0v at 0rpm at offset output value and allow to increase max speed to 3600 if wanted
PWM_OUTPUT_SCALE = 110
# PWMgen output frequency in Hz
PWM_PERIOD = 20000000
AT_SPEED_SCALE = 1.01
VELOCITY_RPM_GAIN = 60


# Orient Spindle
[ORIENT]
# PID, input is degree
P = 1
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_ERROR = 0.0
#Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. 
MAX_OUTPUT = 55.00


I hope the basic work, but i'm pretty sure something is needed for scale encoder to degree.

i appologize this is a lot of work to understand but any help/suggestion are another time really welcome.

Thanks

Aurelien

unread,
Jan 3, 2020, 3:21:33 PM1/3/20
to Machinekit
For increase safety with the hpg.pwmgen i have to use a 2rt relay for enable, so is possible to unconnect this wire from kbmg sig input at same time enable signal is removed.

I have any watchdog for now, you make me thinking about adding this lol

Br


justin White

unread,
Jan 3, 2020, 9:33:39 PM1/3/20
to Machinekit
I don't really understand what you mean here. I thought your problem was the hardware outputs "stick". If "losing" the software enable from Machinekit will drop an output and disconnect a relay then why isn't that relay the drive enable for the KB drive? That's the only relay that needs to disconnect to kill the drive.

As for the spindle orient thing, you are getting ahead of yourself (again). Really shouldn't bother with something so convoluted until you see the thing turn. Why don't you put that "spindle orient" thing in a separate hal file, and once you see the thing run OK then you can add the second hal file to your ini file.

Aurelien

unread,
Jan 3, 2020, 10:58:36 PM1/3/20
to Machinekit

Le samedi 4 janvier 2020 03:33:39 UTC+1, justin White a écrit :
I don't really understand what you mean here. I thought your problem was the hardware outputs "stick". If "losing" the software enable from Machinekit will drop an output and disconnect a relay then why isn't that relay the drive enable for the KB drive? That's the only relay that needs to disconnect to kill the drive.
Actually this relay is correctly managed for enable/disable the drive else if i kill GUI (after some delay) or push Estop, i have think about unconnect also the drive sig input because you make me paranoid with some older message ^^

As for the spindle orient thing, you are getting ahead of yourself (again). Really shouldn't bother with something so convoluted until you see the thing turn. Why don't you put that "spindle orient" thing in a separate hal file, and once you see the thing run OK then you can add the second hal file to your ini file.
Because i have some time now and like to use this time for preparing the job, i hope delivery for drive soon. I apologize but your setup make me wanting to fly too speed !
Today i have do some test turning the motor from hand and i "have understand" regarding to the schematics that i need to use a scale.2.gain 1.11111    (400ppr/360) resulting to 360 pulse per rev for orient.pid.feedback and orient.position
But i have not understand what the author have writes "Set to1/360" "Scaled to give 0 to 1 /rev" "Encoder Scaled to give 0 to 360 /rev"
I have see that this encoder 400ppr is not really accurate with the scale 1.11111 the precision from 2 position is 0.9 to 1.8 for 1degree   /    4.5 to 5.4 for 5 degree  : maybee this is only some bad settings (but one full rev is exactly 360 degree)

For what i have try and see the basic work fine from "halcmd show" regarding to the mux2 or2 and2 near2. 
You are right for remove this parts when i receive the drive and restart this spindle (i have already test to comment out and uncomment 2 line in spinlde section for return to normal) but another time i apologize and for sure you are right.


For now the most problem is to be sure to not forget something for spindle "really important" like this scale on the orient input from encoder or something like this.
Studying for create whatchdog. 
Another problem is i don't really know how to check the status from this particular pin hpg.encoder.00.chan.00.index-pin.

I don't know how to thank you enough for your time and interest !

Br

Aurelien

unread,
Jan 3, 2020, 11:04:38 PM1/3/20
to Machinekit
setp hpg.pwmgen.00.out.00.enable 1                # allow to be at offset value else when spindle is off

# offset the pid output the value of max output to shift the pwm output above 12v for output 0v from +-10 DAC
setp offset.pwmgen.offset [SPINDLE]OFFSET_OUTPUT
net DAC-ctrl-in <= pid.spindle.output
net DAC-ctrl-in => offset.pwmgen.in
#net spindle-vel-cmd-rps => offset.pwmgen.in     # for bypass PID only for some test

# scale max expected input * 2 to equal a PWM duty cycle of 1.0 
setp hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE

# encoder connections
net spindle-index-enable <= motion.spindle-index-enable
net spindle-index-enable <=> hpg.encoder.00.chan.00.index-enable
net spindle-index-enable => pid.spindle.index-enable

net spindle-pos <= hpg.encoder.00.chan.00.position 
net spindle-pos => motion.spindle-revs

net spindle-vel-fb-rps <= hpg.encoder.00.chan.00.velocity
net spindle-vel-fb-rps => motion.spindle-speed-in
net spindle-vel-fb-rps => scale.spindle-vel-rpm.in
net spindle-vel-fb-rps => pid.spindle.feedback

net spindle-vel-rpm <= scale.spindle-vel-rpm.out
net spindle-vel-cmd <= motion.spindle-speed-out

# Speed command in RPS
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => pid.spindle.command

# offset output to feed to pwmgen output
net DAC-ctrl-out <= offset.pwmgen.out
#net DAC-ctrl-out => hpg.pwmgen.00.out.00.value                  # moved in the orient mux2

# Spindle control signals + and2 for stop spindle after stop GUI
net spindle-enable <= motion.spindle-on
net spindle-enable => and2.spindle-ena.in0
net drv-enable => and2.spindle-ena.in1
net spindle-and2enable <= and2.spindle-ena.out
net spindle-and2enable => pid.spindle.enable
#net spindle-and2enable => fur.do-6                               # moved in the orient or2

# Spindle at speed near signal
setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => near.at-speed.in1 
net spindle-vel-fb-rps  => near.at-speed.in2
net spindle-at-speed <= near.at-speed.out
net spindle-at-speed => motion.spindle-at-speed 

#####################################################################


#####################################################################
# Spindle orient mode
#####################################################################
loadrt orient names=orient.spindle
loadrt pid    names=pid.orient-value
loadrt offset names=offset.orient
loadrt near   names=near.orient
loadrt or2    names=or2.orient-ena
loadrt and2   names=and2.orient-ena
loadrt mux2   names=mux2.orient-value

addf orient.spindle                       servo-thread
addf pid.orient-value.do-pid-calcs        servo-thread
addf offset.orient.update-output          servo-thread
addf near.orient                          servo-thread
addf or2.orient-ena                       servo-thread
addf and2.orient-ena                      servo-thread
addf mux2.orient-value                    servo-thread

# setup Orient Spindle PID
setp pid.orient-value.Pgain     [ORIENT]P
setp pid.orient-value.Igain     [ORIENT]I
setp pid.orient-value.Dgain     [ORIENT]D
setp pid.orient-value.FF0       [ORIENT]FF0
setp pid.orient-value.FF1       [ORIENT]FF1
setp pid.orient-value.FF2       [ORIENT]FF2
setp pid.orient-value.bias      [ORIENT]BIAS
setp pid.orient-value.deadband  [ORIENT]DEADBAND
setp pid.orient-value.maxerror  [ORIENT]MAX_ERROR
setp pid.orient-value.maxoutput [ORIENT]MAX_OUTPUT


# Set asked mode from M19 P0/1/2
net spindle-orient-mode <= motion.spindle-orient-mode
net spindle-orient-mode => orient.spindle.mode

# encoder connections
net spindle-index-enable => pid.orient-value.index-enable                  # need investigation


# Spindle orient control signals + and2 for stop spindle after stop GUI
net spindle-orient-enable <= motion.spindle-orient
net spindle-orient-enable => and2.orient-ena.in0
net drv-enable => and2.orient-ena.in1
net spindle-orient-and2enable <= and2.orient-ena.out
net spindle-orient-and2enable => orient.spindle.enable
net spindle-orient-and2enable => mux2.orient-value.sel
net spindle-orient-and2enable => pid.orient-value.enable


# enable out for controler from regular spindle or orient mode
net spindle-and2enable => or2.orient-ena.in0
net spindle-orient-and2enable => or2.orient-ena.in1
net spindle-orient-or2enable <= or2.orient-ena.out
net spindle-orient-or2enable => fur.do-6


# Spindle at orient near signal
setp near.orient.scale [ORIENT]AT_ANGLE_SCALE     #AT_ANGLE_SCALE = 1.12
net spindle-pos => orient.spindle.position
net spindle-pos => pid.orient-value.feedback
net spindle-pos => near.orient.in2

net spindle-orient_cmd <= motion.spindle-orient-angle
net spindle-orient_cmd => near.orient.in1
net spindle-orient_cmd => orient.spindle.angle

net spindle-is-oriented <= near.orient.out

Aurelien

unread,
Jan 4, 2020, 1:58:49 PM1/4/20
to Machinekit
I have setup the pru index pin as a general gpio input and test from halcmd show pin = work fine.

But i never see some reset for count vs rawcount when this pin is set for pru index else never see some changing status False/True.

setp hpg.encoder.00.chan.00.A-pin 0         # 931 
setp hpg.encoder.00.chan.00.B-pin 1         # 929 
setp hpg.encoder.00.chan.00.index-pin 2     # 930

P9_29 pruin # ENCyB
P9_30 pruin # ENCyI
P9_31 pruin # ENCyA


net spindle-index-enable hpg.encoder.00.chan.00.index-enable <=> motion.spindle-index-enable
or 
net spindle-index-enable <= motion.spindle-index-enable
net spindle-index-enable <=> hpg.encoder.00.chan.00.index-enable
or
#setp motion.spindle-index-enable 1


Is there something i can try for check if this index work correctly ?

Br

justin White

unread,
Jan 4, 2020, 3:31:52 PM1/4/20
to Machinekit
I don't know what you mean by "set the index pin as general gpio" if the hpg encoder hardware pins are setup as they should be you shouldn't have a problem.

index-enable doesn't reset counts, if "arms" the index-pin itself to reset the counts and the index-enable pin on the next index pulse.

So setp index-enable true, then physically trigger index pin > index-enable will go false and counts will reset. If index-enable is staying true, then the index pin is not getting triggered. You will likely never be able to see the index pin from an encoder go true in hal, it is too short for a servo-thread to sample usually. The encoder firmware (HPG) will catch it which is why the index-enable pin exists. You can't trigger a reset based on the index-pin itself being read from hal, you enable the encoder firmware to reset itself when it sees the index.

Aurelien

unread,
Jan 4, 2020, 4:22:00 PM1/4/20
to Machinekit
for the first message about gpio forget that i have only do something for check if the pin input for encoder index work correctly.

from linuxcnc forum i have found this test for check index:

and seems to work fine according to the topic and your information (set true, trigger, check state = false) also  hpg.encoder.00.chan.00.count is reseted to 0


halcmd -kf
loadusr halmeter signal spindle-index-enable
sets spindle-index-enable 1

Aurelien

unread,
Jan 4, 2020, 9:56:06 PM1/4/20
to Machinekit
Well i have succefully play with some synchronized motion with a simulated spindle-at-speed with hand turning motor ang using G33 G33.1 G76 i think all work as expected (with G18). 
But G73 G81 G82 G83 work only with G17 on a lathe ??

Br


Aurelien

unread,
Jan 17, 2020, 7:25:34 AM1/17/20
to Machinekit
Hello

Firstly another time many thanks for your help !

Yesterday the kbmg was delivered after so much waiting and i'm really happy (with your help) now the motor run again and i have now both direction !!!

Finally i have do some little change in the proposed config like use more pwm scale (140) and allow more max_output (60) with a offset 64 (~DAC at 0rpm). and added a limit2 component on the pid.command, the result seems to be good : asked RPM can't be more than 3300 for pid input, and pid is able to deliver more power for compensation. (in other way ask rpm higher than max_output saturate the pid)
I can reach the max rpm with some DAC output near +-8.5v.

I need to study PID now because is really not perfect (maybee too slow) for now with these default settings
P = 0
I = 1.0
D = 0.0
FF0 = 1.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0


I have play a little with deadband, bias, FF0, I without big success.

from linuxcnc forum PCW user says :
For the normal spindle in velocity mode I would use only FF0 and P and I, and only add I when you are quite close to correct velocity following.
(FF0 only is pure open loop voltage mode with a PWM driven servo motor)
So for this mode I would get the spindle speed as accurate as possible over the
full speed range with just FF0 and then add feedback with some P (as much as it
stable) and then some I

For position mode you use As much D&P (more D allows more P) as is stable then
adjust FF1 for minimum following error vs velocity. Then finally add as much I as is stable
 

Maybee try to use http://www.linuxcnc.org/docs/html/man/man9/at_pid.9.html or Ziegler-Nichols method

One things i'm unsure it is better to tune the kbmg firstly as best as possible with original potentiometer ?

IMH with PID and limit2 component including max_accel i need to set the drive as : 
--maximum or near value for Max Facc Racc 
--default value or lower for FWD-CL REV-CL
--tune value DB with enable closed and 0rpm ~0v DAC
--tune as best IR-Comp RESP

Br

justin White

unread,
Jan 17, 2020, 8:15:07 AM1/17/20
to Aurelien, Machinekit
Good you got it working.

I still dont understand why your pid has 0 Pgain. That's more or less your basic starting point for a pid

--
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/4f07a30d-673e-4a9f-ade1-af3263322414%40googlegroups.com.

Aurelien

unread,
Jan 17, 2020, 8:33:38 AM1/17/20
to Machinekit
P = 20
I =  0.002
D = 0.0
FF0 = 1.0

really better with these setting PID 0 before starting to better understand lol

Regarding to KBMG-212D setting you think i'm in the right way ?




Aurelien

unread,
Feb 7, 2020, 6:44:06 PM2/7/20
to Machinekit
Hi


Sorry to comme back again with this stupid motor.

After taking some time to test the motor with the kbmg-212D and PID and test to load motor, it appears the torque at low RPM is really little, it's really too easily stop the spindle.

I have also test with original potentiometer without CNC and the issue seem to be the same.

Regarding to this test i have find in my archive the original motor board, this one use a 100 pulse encoder for feedback and the most important the torque is really really better...
This board is not perfect :
kbmg is more smooth for speed change and allow changing direction
Firstly i think there is no brake i have now see the big resistor used as original brake (wire uncompleted and was poorly "changed" by precedent owner)
The control is done with 6.35v and 1K potentiometer
Unfortunatly 2 potentiometer for calibration are missing
This is SCR controler 30 years old

I have thinked some wire for make reverse possible and keep the resitor brake usage, in other post i speak about burn too many controler and i'm now really affraid about doing some other stupid test...

If you can give me what is your opinion about that and about my schematic i'm really lost with these spindle...

for reference motor is 1Hp 180v DC ~5A + 180v Field

Br


Original motor board.png

Potential Wiring Original board.PNG





Aurelien

unread,
Feb 7, 2020, 6:55:05 PM2/7/20
to Machinekit
3AFD0F99-A102-4E03-A5C5-5C01E66FCB7F.jpeg

Aurelien

unread,
Feb 7, 2020, 7:14:26 PM2/7/20
to Machinekit

Original wiring use a filter for brake relay, it is better to use it again ? 


Original motor wiring.png

justin White

unread,
Feb 8, 2020, 10:07:00 AM2/8/20
to Machinekit
That KBMG can easily handle that 1hp motor, it's designed for up to 2hp. On a brushed DC motor the torque is directly related to current. If you have a problem with low end torque you probably did not setup the IR comp and CL pots correctly. That drive needs to be setup in speed mode as you are controlling the speed with the analog input from the PID. The drive itself will control torque and it needs to be setup correctly.

I suggest you go back to the KBMG and set it up right. These drives have been used in industrial machinery for years, there's no reason it can't handle a 1hp spindle motor. 

Aurelien

unread,
Feb 8, 2020, 11:03:03 AM2/8/20
to Machinekit
Hi

Thanks for your reply, at middle to high rpm ~800/3000 the KBMG have a good torque. This is only for low rpm i have try many things with IR and Resp max etc but as you suggest i can try another attempt ! I haven't change the default RCL FCL settings.

Yes setup is speed mode, regen to stop, 5A, 180V, field full voltage, 250v input, 10v for speed.

Except the low rpm torque, the KBMG is better on all other stuff.

Br

Aurelien

unread,
Feb 8, 2020, 11:06:02 AM2/8/20
to Machinekit
Potentiometer position
A5A7C4EA-6C3E-4B3C-94FC-0539AC4FA256.jpeg

Aurelien

unread,
Feb 8, 2020, 5:57:18 PM2/8/20
to Machinekit
Well at the end i have test the original board with ampere meter and i have see some current pic until 13/16A when i load the motor at low rpm.

Over the web info about this lathe or this motor power and with math i have set the KBMG to 5A max, RCL/FCL set to default 150% so i wait for max ~7.5A (ampere meter display 5.5A...)

Setting the KBMG to 10A and RCL/FCL to max i have now something near 11.5A max and off course torque is now really really better !

Thousand of thanks
Reply all
Reply to author
Forward
0 new messages