can some one please explain how this works ?
// Set Timer up to use TIMER4B which is attached to Digital Pin 8 – Ramps 1.4 12v output with heat sink
#define SPINDLEPWMMAX_VALUE 1024.0 // Translates to about 1.9 kHz PWM frequency at 1/8 prescaler
#ifndef SPINDLEPWMMIN_VALUE
#define SPINDLEPWMMIN_VALUE 1 // Must be greater than zero.
#endif
#define SPINDLEPWMOFF_VALUE 0
#define SPINDLEPWMRANGE (SPINDLEPWMMAXVALUE-SPINDLEPWMMINVALUE)
//Control Digital Pin 6 which is Servo 2 signal pin on Ramps 1.4 board
#define SPINDLETCCRAREGISTER TCCR4A
#define SPINDLETCCRBREGISTER TCCR4B
#define SPINDLEOCRREGISTER OCR4C
#define SPINDLECOMBBIT COM4C1
// 1/8 Prescaler, 16-bit Fast PWM mode
#define SPINDLETCCRAINIT_MASK ((1<
#define SPINDLEOCRATOPVALUE 0x0400 // PWM counter reset value. Should be the same as PWMMAX_VALUE in hex.
// Define spindle output pins.
#define SPINDLEPWMDDR DDRH
#define SPINDLEPWMPORT PORTH
#define SPINDLEPWMBIT 5 // MEGA2560 Digital Pin 8
评论 (8)
#2 – sinfocomp 于 2019-11-23
Hello @fra589 , Im not facing that issue, i wish to learn how these settings work, since i need a 1khz and 500hz PWM output to suit the requirements of my laser psu, the way it is now (Im guessing a too high frequency) it does not allow for the plasma discharge to be stable, causing that after 80% pwm the power actually drops instead of going higher, i did not had these issue with GRBL on 328P processor, and for now im setting my laser power manually via pottentiometer, so i was seeking some tuition on how these configuration settings worked so i can learn how to adjust acordingly, Thanks and great Port
#3 – fra589 于 2019-11-24
Hello @sinfocomp,
Oh sorry… Your need was not so explicit for me :smirk:
Perhaps you will find reply about PWM ferquency managment in Arduino here:
https://forum.arduino.cc/index.php?topic=72092.msg541587#msg541587
Or here for full information:
Atmel ATmega640/V-1280/V-1281/V-2560/V-2561 Datasheet – Microchip Technology
Then, go to the spindlecontrol.c file, in spindleinit() function to make your adjustments.
@++;
Gauthier.
#4 – sinfocomp 于 2019-11-24
Hello, i have read and re-read many times, tryed to set prescaler to 1/32 but i dont get the results i need, can some one please shine a light on how to setup fot 1khz pwm frequency, thanks
#5 – bdurbrow 于 2019-11-24
OK, first, you should download and read the ATMega2560 data sheet if you haven’t already. In particular, sections 17 and 18.
> since i need a 1khz and 500hz PWM output
I’m not quite sure what you mean by that… 1Khz frequency, 50% duty cycle? Or you want the settings for both a 1Khz frequency and a 500hz frequency?
The timer is configured with these two lines:
“
#define SPINDLETCCRAINIT_MASK ((1<
The WGM bits set up the Waveform Generation Mode, and the 4 in the WGM bits indicates timer 4. The other number indicates which bit of the Waveform Generation Mode the constant is. These bits are described in Table 17-2.
The CS bits setup the prescaler; these are described in Table 17-6.
To get a 1Khz PWM frequency, these should work:
`
#define SPINDLEPWMMAX_VALUE 2000.0
#define SPINDLETCCRAINIT_MASK ((1<
`
To get a 500hz frequency, just double the SPINDLEPWMMAXVALUE and SPINDLEOCRATOPVALUE values:
```
#define SPINDLEPWMMAX_VALUE 4000.0
#define SPINDLEOCRATOP_VALUE 4000
These values were calculated using this:
https://eleccelerator.com/avr-timer-calculator/
(no affiliation, it's just the first thing that popped up in Google).
Note that I have not tested this, I'm sitting in a restaurant right now and don't have my o-scope or an Arduino with me.
#6 - sinfocomp 于 2019-11-25
@bdurbrow , Thanks for the help, im almost there, i changed my config.h as follows
Pin 8 - Ramps 1.4 12v output with heat sink
#define SPINDLEPWMMAX_VALUE 256.0 // Translates to about 1.9 kHz PWM frequency at 1/8 prescaler
#ifndef SPINDLEPWMMIN_VALUE
#define SPINDLEPWMMIN_VALUE 1 // Must be greater than zero.
#endif
#define SPINDLEPWMOFF_VALUE 0
#define SPINDLEPWMRANGE (SPINDLEPWMMAXVALUE-SPINDLEPWMMINVALUE)
//Control Digital Pin 6 which is Servo 2 signal pin on Ramps 1.4 board
#define SPINDLETCCRAREGISTER TCCR4A
#define SPINDLETCCRBREGISTER TCCR4B
#define SPINDLEOCRREGISTER OCR4C
#define SPINDLECOMBBIT COM4C1
//16-bit Fast PWM mode
#define SPINDLETCCRAINIT_MASK ((1<
#define SPINDLEOCRATOPVALUE 0x0100 // PWM counter reset value. Should be the same as PWMMAX_VALUE in hex.
// Define spindle output pins.
#define SPINDLEPWMDDR DDRH
#define SPINDLEPWMPORT PORTH
#define SPINDLEPWMBIT 5 // MEGA2560 Digital Pin 8
ii now have a more stable beam (not flickering any more)
however in my grbl setings
my min pwm is 0 and my max pwm is 1000
this so i can easily change my power settings in a 1% increments (ideally)
however if i go past S800 in a Gcode file, the actual laser power starts droping, i know my laser can still go higher becouse my ma meter is reading roughly 17ma and if go to manual power (via pot) i can get upto 25ma any advice on how to get max power on it ?
thanks a lot
Ed
#7 - sinfocomp 于 2019-11-25
BTW is the pwm 5v or 3.3v ?
#8 - sinfocomp 于 2019-11-25
so after much reading i came across a solution here
https://github.com/gnea/grbl-Mega/issues/55#issuecomment-403261212
i just changed to a 8bit timer and now getting 0 to 5v pwm control at the frequency i needed
closing
#1 – fra589 于 2019-11-23
Perhaps you should do a little bit search and you should see other (olders) issues before posting new question…
The answer is often present : https://github.com/gnea/grbl-Mega/issues/55#issuecomment-403261212