Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there away to add implement a "map" for PWM output #383

Closed
terjeio opened this issue Oct 24, 2023 · 54 comments
Closed

Is there away to add implement a "map" for PWM output #383

terjeio opened this issue Oct 24, 2023 · 54 comments

Comments

@terjeio
Copy link
Contributor

terjeio commented Oct 24, 2023

Is there away to add implement a "map", where a pwm of 0=0, the smallest increment above 0 detectable by micro can be set to a selected pwm value, and what a program may perceive as 100% to another value(75% duty). I know that now you can do the later and the available option on lower value is almost the oposite of what im looking for..... also itd be nice to be tunable with out recompiling. Using the $$ settings or potentiometer would be slicker. Thanks

Originally posted by @customsolutions in #203 (comment)

@terjeio terjeio changed the title Is there away to add implement a "map", where a pwm of 0=0, the smallest increment above 0 detectable by micro can be set to a selected pwm value, and what a program may perceive as 100% to another value(75% duty). I know that now you can do the later and the available option on lower value is almost the oposite of what im looking for..... also itd be nice to be tunable with out recompiling. Using the $$ settings or potentiometer would be slicker. Thanks Is there away to add implement a "map" for PWM output Oct 24, 2023
@terjeio
Copy link
Contributor Author

terjeio commented Oct 24, 2023

I am not sure what you mean by this. $34-36 does not handle what you are after?

image

A plugin can override spindle functions or implement custom spindle drivers like this or these. So you are not stuck with what the standard implementation provides.

@phil-barrett
Copy link

I think what he is asking is for a PWM mapping function. In general terms if would be f(PWM_in) = PWM_out.

In practical terms it could be a table of PWM with linear interpolation between points. For example 11 entries in steps of 10%
fPWM[0] = 0.0 // 0%
fPWM[1] = 0.08 // 10%
fPWM[2] = 0.16 // 20%
fPWM[3] = 0.24 // 30%
fPWM[4] = 0.32 // 40%
fPWM[5] = 0.40 // 50%
fPWM[6] = 0.47 // 60%
fPWM[7] = 0.53 // 70%
fPWM[8] = 0.61 // 80%
fPWM[9] = 0.68 // 90%
fPWM[10] = 0.75 // 100%

So a requested PWM of 50% would actually be 40% PWM output. A requested PWM of 55% would be 43.5% ( (40+47)/2 ).

This could be useful in linearizing PWM and 0-10V output. A simple PWM to 0-10V converter often has some "sag" in the mid range and could benefit from a "boost" mapping. Also, I've noticed that straight PWM input on several HY VFDs I have is not very linear - sometimes the mid range is quite a bit low. They could benefit from a boost mapping.

It doesn't need to be steps of 10%. Could be a 5 entry table for steps of 25%. Also, allowing greater than 100% on the output would be useful.

@terjeio
Copy link
Contributor Author

terjeio commented Oct 24, 2023

I think what he is asking is for a PWM mapping function.

Something like this then?

@phil-barrett
Copy link

Yes. I had seen that but presumed it was only for lathe mode. It looks like a possibility but I don't quite understand how to use it. Needs a grblHAL build with spindle sync and tuning options, I presume. Will check it out today. My test bed for Pro is on a shelf and I have 100 Pico ETH boards to do intake processing on so will be later today. I'm sure I will have questions...

@terjeio
Copy link
Contributor Author

terjeio commented Oct 24, 2023

Yes. I had seen that but presumed it was only for lathe mode.

It is not, it only makes it possible to automate data collection since real RPM is available from the controller. One can use a tachometer to collect data points for the python algorithm.

Settings $66 - $69 becomes available when spindle linearization is enabled, it is not dependent on lathe mode. I guess I should make this option available from the Web Builder.

@customsolutions
Copy link

Similar however it'd be 0%=0%, 2% = x%, and 100% = y%. So off is off and any recognizable on would output a minimum pwm value, 100% could be set to max allowable pwm.
Right now it hold pwm to 0 until you reach a pwm minimum requested set to 1.5. Now...ex 0=0 .5=0 1=0 1.5 =1.5. Id like 0=0, .01=1.5, .5=2 ,1 =2.5, 1.5 =3( this is just an easy low end ex). If max was adjusted thes numbers would be diff

@phil-barrett
Copy link

Yes, from the Web builder would be very useful. Is it not enabled when I turn on Spindle sync? I have a tachometer but have been using VFD RPM readout.

@terjeio
Copy link
Contributor Author

terjeio commented Oct 24, 2023

Similar however it'd be 0%=0%, 2% = x%, and 100% = y%

You want a lookup table or function for the converting percentages? Currently the conversion is from RPM to PWM duty cycle and this code is called directly by the PWM spindle driver code and cannot be overridden by plugins. I may make them overridable if that helps.
It is possible to "fake" the RPM input as a percentage if you set $30 (max spindle speed) to 100, is this what you are doing? If so transforming the RPM input before it is sent to RPM -> PWM conversion might be what you are after.

Yes, from the Web builder would be very useful.

Ok, I'll add it.

Is it not enabled when I turn on Spindle sync?

No, it is not. IIRC linearization was mainly aimed at (CO2) lasers?

Edit: fixed copy/paste error.

@phil-barrett
Copy link

phil-barrett commented Oct 24, 2023

It is possible to "fake" the RPM input as a percentage if you set $30 (max spindle speed) to 100, is this what you are doing? If so transforming the RPM input before it is sent to RPM -> PWM conversion might be what you are after.

Probably better to set spindle max to 10000 and then you can express in 100ths %. 5005 is 50.05%

Ok, I'll add it.

Thank you!

@customsolutions
Copy link

customsolutions commented Oct 24, 2023 via email

@customsolutions
Copy link

customsolutions commented Oct 24, 2023

Here is an example. Lets say grbl is set to 10000rpm and lightburn also.... then 0%=0rpm, 5%=500rpm 100% = 10000rpm. Well 10k will prob burn up the laser so we set LB to a max of 5k, so max output from LB is what grbl sees as 50%(5k/10k).
Now when we request 5% we only get 250rpm which is not enough to fire laser... so it would be nice to map .1% in grbl to the needed 500rpm. So the user sees 0=off .1% = laser on minimum and 100% = a safe maximum. Hope that helps.

@terjeio
Copy link
Contributor Author

terjeio commented Oct 25, 2023

I still do not get why setting $35 isn't working for the just above 0 RPM input, is your $31 setting > 0?

@customsolutions
Copy link

customsolutions commented Oct 25, 2023 via email

@customsolutions
Copy link

customsolutions commented Oct 25, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Oct 25, 2023

Is they a version o should check also?

$I output contains build dates for both the core and the driver

Also is there a testing platform you are specifically using?

The main one is STM32F466 on a Nucleo dev board, but I test on several others as well - depending on what has been changed.

@terjeio
Copy link
Contributor Author

terjeio commented Oct 27, 2023

FYI I have now changed the code for RPM > PWM conversion to make it easier to override the default functionality from plugins. However, these changes will not be made available from github until after I am back home in early december. Until then I can make the code available, on request, from the master subversion repo.

@phil-barrett I have added the option to enable spindle linearization from the Web Builder.

@customsolutions
Copy link

customsolutions commented Oct 27, 2023 via email

@phil-barrett
Copy link

@phil-barrett I have added the option to enable spindle linearization from the Web Builder.

Thanks, have been building with it. Hope you are someplace warm/nice.

@customsolutions
Copy link

I decided to play with nucleo446 and a proteneerboard. When i use the web builder, and once connected to lightburn, I dont see $35, and when I try to set $32 to laser mode I get error 17. Under web builder general settings it does say spindle[pwm]. Am I 0 for 2 in webbuilder?

@terjeio
Copy link
Contributor Author

terjeio commented Nov 22, 2023

I dont see $35, and when I try to set $32 to laser mode I get error 17.

My bad - default for the Protoneer board is spindle on/spindle dir/no PWM. I have changed this to spindle on/PWM for the Web Builder - so please try again.

@customsolutions
Copy link

customsolutions commented Nov 23, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 23, 2023

Is the PWM pin listed in the $pins output?

@customsolutions
Copy link

customsolutions commented Nov 23, 2023 via email

@phil-barrett
Copy link

In a GCode sender's MDI section (aka Console), enter $pins and you should get back the pin assignments used for that build.

@customsolutions
Copy link

customsolutions commented Nov 23, 2023 via email

@customsolutions
Copy link

customsolutions commented Nov 23, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 23, 2023

The PWM output is on the spindle direction pin. Is this the pin you are checking?
There are several versions of the Protoneer board, including many clones. Some have an additional PWM pin assigned, seemigly swapped by the Z limit input. Which one do you have?

@customsolutions
Copy link

customsolutions commented Nov 23, 2023 via email

@phil-barrett
Copy link

The main way to tell the shields apart - Grbl 0.9 and earlier do not have a labeled PWM spindle output pin, Spindle Enable is on D12 and Z limit is on D11. Grbl 1.1 has PWM on D11, Z limit on D12 and they dropped spindle enable. The protoneer shield 3.1 is a Grbl 0.9 board. For what it is worth, you can use the pins how ever you choose, there is no filtering or optos on that shield - the connectors go straight into the arduino headers.

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 24, 2023

You should be using the Protoneer version, if the Uno board has compatible pin mappings that could of course be used instead.

I have a F446 Nucleo board at hand and luckily PA5 is wired to an on-board LED. I flashed Web Builder build and it works for me in that the LED intensity varies with the commanded spindle speed.
Either your PA5 pin is damaged or you have laser mode enabled ($32=1)?

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 24, 2023

Is pwm moved? Or disabled in this version?

For the Protoneer board: no and no.

When laser mode is enabled there will be no PWM output unless there is non-rapid motion ongoing. This is the same behaviour as legacy Grbl.

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 24, 2023

The on-board LED worked fine for me. Post your settings so I can check, use ioSender and select Help > About > To clipboard and paste in a comment. Or check yourself with an oscilloscope.

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 24, 2023

Just reset the settings with $rst=* and set $14 as needed.

Here is how the LD2 lights up with M3S1000 after I did that, IMO not "very dim":

IMG_20231124_142316

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 24, 2023

This is the firmware I tested with, built with default options in the Web Builder:

firmware(3).zip

I use ioSender and putty for control and I only change $14 after resetting.

@customsolutions
Copy link

customsolutions commented Nov 24, 2023 via email

@customsolutions
Copy link

customsolutions commented Nov 25, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 25, 2023

any other settings in webbuilder diff you think?

Could be - which ones did you select?

@customsolutions
Copy link

customsolutions commented Nov 25, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 25, 2023

Ok, spindle linearization is then the likely reason. Did you add setting values for that?

@customsolutions
Copy link

customsolutions commented Nov 25, 2023 via email

@terjeio
Copy link
Contributor Author

terjeio commented Nov 28, 2023

I was under the impression those were the $35 etc.

No, $66 - $69 are used for spindle linearization (if enabled). $35 and $36 is for min and max PWM output.

@dJOS1475
Copy link

dJOS1475 commented Jan 18, 2024

Hi All, I've just moved over from FluidNC (didnt play nice with my prefered sender OB Control), and Im finding the PWM spindle control to not work very well. 30k RPM works perfectly, but 10k RPM behaves oddly and is not stable. In FluidNC I was able to put in a simple speed map and this worked perfectly. I cant use the SPINDLE_LINEARIZATION module as my GRBL_SPD controller doesnt support the features AFAIK.

Here is my current grblHAL config vs FluidNC - am I missing something obvious?

grblHAL:

$30=30000.000 ;Maximum spindle speed, RPM
$31=10000.00 ;Minimum spindle speed, RPM
$32=0 ;Laser-mode enable, boolean
$33=1000.0 ;Spindle PWM frequency
$34=0.0 ;Spindle off Value
$35=1.0 ;Spindle min value
$36=100.0 ;Spindle max value

FluidNC:

PWM:
  pwm_hz: 1000
  direction_pin: NO_PIN
  output_pin: gpio.32
  enable_pin: gpio.27
  disable_with_s0: false
  s0_with_disable: true
  spinup_ms: 0
  spindown_ms: 0
  tool_num: 0
  speed_map: 0=0.000% 10000=1.000% 30000=100.000%

cheers Derek

@terjeio
Copy link
Contributor Author

terjeio commented Jan 19, 2024

@dJOS1475

I cant use the SPINDLE_LINEARIZATION module as my GRBL_SPD controller doesnt support the features AFAIK.

Did you try it? The GRBL_SPD controller takes a PWM input so it should work?

@dJOS1475
Copy link

@dJOS1475

I cant use the SPINDLE_LINEARIZATION module as my GRBL_SPD controller doesnt support the features AFAIK.

Did you try it? The GRBL_SPD controller takes a PWM input so it should work?

No, I got around the issue I was having by setting the minimum to 2. I’m not entirely sure why that worked tho (Jon the designer suggested it).

@dJOS1475
Copy link

dJOS1475 commented Jan 28, 2024

@dJOS1475

I cant use the SPINDLE_LINEARIZATION module as my GRBL_SPD controller doesnt support the features AFAIK.

Did you try it? The GRBL_SPD controller takes a PWM input so it should work?

OK, I thought I had it solved, but I didnt. So I recompiled grblHAL with the Spindle RPM linearization module and ran your software for it. Frankly Im confused!!I know im an idiot who cant code to save himself, but I do not understand how your system is supposed to work??

Please just implement a simple speed map, like FluidNC, and you wil save a lot of ppl a lot of trouble eg:

Speed_map: 0=0.000% 10000=1.000% 30000=100.000%

Honestly, if you assume ppl are as dumb as I am, you'll make life easier for everyone.

@terjeio
Copy link
Contributor Author

terjeio commented Jan 28, 2024

Looking at this again I believe the $30-$36 settings above should be equivalent to the FluidNC speed map. So what is not working?

@dJOS1475
Copy link

Looking at this again I believe the $30-$36 settings above should be equivalent to the FluidNC speed map. So what is not working?

Tbh, I have no idea what happened. I recompiled the firmware and zeroed out the linear settings and it started behaving.

Bizarre!

@terjeio terjeio closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants