Originally Posted by
CNCMAN172
printf("Spindle Set to %f pwm %d\n",speed, pwm); // print the desired speed
SetBitDirection(26+PWM_NUMBER,1); // Set bit PWM pin as an output
FPGA(IO_PWMS+2*PWM_NUMBER+1) = 1; // enable the PWM
FPGA(IO_PWMS+2*PWM_NUMBER) = pwm; // set the PWM
}
This file seems to imply that PWM sign comes out of 26 + 5 = 31. If you look at bit 31 that should be changing. Tom can probably explain exactly where you can look for this signal. They use two commands to the FPGA to enable the PWM output.
Tom can you detail how this works in more detail?
Russ
KMotionDef.h has the basic explanation, although Robert probably wants to ignore this to avoid any further confusion, as it's not really something that normal users need to worry about.
Code:
// Digital I/O bit PWM control (4 I/O bits 16-19 may be pulsed)
#define N_IO_PWMS 4 // Number of pwms that may be assigned to GPIO bits
#define IO_PWMS 0x20 // FPGA offset to IO PWM registers (2 bytes each - value, enable(bit0))
#define IO_PWMS_PRESCALE 0x2f // FPGA offset to IO PWM Pre-Scale clock divider 0-255, 0 = 16.6MHz, 1=8.33MHz, ...
#define IO_PWM_MAX_VALUE 255 // 0 = 0%, 255 = 100 % duty cycle
Code:
SetBitDirection(26+PWM_NUMBER,1); // Set bit PWM pin as an output
Does what it says. Sets bit 31 aka Aux1 pin 11 aka PWM 5 as an output.
Code:
FPGA(IO_PWMS+2*PWM_NUMBER+1) = 1; // enable the PWM
FPGA(IO_PWMS+2*PWM_NUMBER) = pwm; // set the PWM
As per the KMotionDef comment, IO_PWMS contains the offset to the PWM registers, which have 2 bytes per PWM. So the first line enables the PWM5, and the second line sets the PWM5 value.
I'm guessing there are default settings for the Pre-scaler and max values, given they're not included within the K2 code.
A crude way to test the output, which may or may not work depending on the multimeter, is to measure the DC voltage from the PWM. As the PWM increases, the voltage shown on the multimeter should increase. The accuracy of this depends on how much the multimeter smooths the input when on VDC, but I'd imagine the default PWM frequency should be high enough to give a reasonable reading on most multimeters.