PWM frequency

Question/Answers related to this version of the board.
Post Reply
chirameto
Posts: 1
Joined: Sun Jan 15, 2017 3:16 pm

PWM frequency

Post by chirameto » Sun Jan 15, 2017 4:34 pm

Hi,

I had my 2.51 board quite a while and it is working wonderfully. Now I would like to try PWM function.
I also bought a PWM module which is mach3 compatible and I almost got it working.

The problem is I cannot get my spindle working at full speed with pi cnc board. I can manage full speed just fine with mechanical pots.
Here is my setup:
- A 400w 48v 12000rpm spindle
- grbl is at default setting which S1000 represent 100% duty cycle.
- a PWM module that can accept external PWM signal, manual said 10Khz range.

Here are sample situations:
- at s250 command, my spindle will run around 6000rpm.
- at s500, My spindle will run at 9000rpm which is the fastest spindle speed I can get. The voltage of PWM pin read 2.5V
- at s750, my spindle speed goes down to 6000 again.
- at s1000 my spindle totally stop.

From the result, I can only guess that the frequency output from the pi cnc is not within range of my PWM module.
I know the pi cnc PWM output switching rapidly between 0 and 5v. But, I don't know the period so I cannot calculate the frequency.
What is the PWM frequency that pi cnc board provide? Is it the same as arduino PWM frequency? Which Pin?

I don't know much about electrical stuff so I might get everything wrong.
Any information would be appreciated. Thank you.

Bertus Kruger
Site Admin
Posts: 1670
Joined: Wed Feb 03, 2016 10:26 pm
Location: Wellington , New Zealand
Contact:

Re: PWM frequency

Post by Bertus Kruger » Tue Jan 17, 2017 8:40 pm

This is the GRBL specs I found on the GRBL site:

https://github.com/grbl/grbl/issues/1163
In v0.9, the default PWM frequency is 7.8 kHz. In v1.1, it was updated to 1 kHz.

gmoney484
Posts: 135
Joined: Wed Nov 09, 2016 8:52 pm

Re: PWM frequency

Post by gmoney484 » Tue Feb 28, 2017 10:58 pm

I think I understand what you are doing, but if I'm wrong let me know.

I tried to solve this problem by using an Arduino to convert the PWM to an analog voltage but the results were poor.

Instead I built a simple low-pass filter and tested that. It works perfectly. Something like this..

http://www.instructables.com/id/Analog- ... o-Voltage/
Gavin Milne
HoD Science
Dilworth School

gmoney484
Posts: 135
Joined: Wed Nov 09, 2016 8:52 pm

Re: PWM frequency

Post by gmoney484 » Tue Feb 28, 2017 11:06 pm

BTW I measured the frequency of my PI's PWM output and it was 1kHz or near enough (GRBL v1.1)
Gavin Milne
HoD Science
Dilworth School

pffabrications
Posts: 2
Joined: Sun Jan 01, 2017 1:20 pm

Re: PWM frequency

Post by pffabrications » Thu Dec 21, 2017 7:17 pm

gmoney484 wrote:
Tue Feb 28, 2017 10:58 pm
I think I understand what you are doing, but if I'm wrong let me know.

I tried to solve this problem by using an Arduino to convert the PWM to an analog voltage but the results were poor.

Instead I built a simple low-pass filter and tested that. It works perfectly. Something like this..

http://www.instructables.com/id/Analog- ... o-Voltage/
Hi what values are you using for your resistor and capacitor? I have tried this but im obviously doing something wrong as Its just not working for me.
Im trying to develop my own PID spindle control with a second arduino, taking the set point from GRBLs PWM signal. I have good results using arduinos Pulsein function to measure duty cycle and calculate rpm. This works very well for me on grbl 1.1f but so far I have had trouble including it into a PID control as I am very much a novice with any kind of programming.
  • //Reads a GRBL's spindle PWM signal's duty cycle and converts to rpm value.


    #define READ_PIN 6


    int RPM;
    int maxrpm = 12000;
    static double duty;
    static double freq;
    static long highTime = 0;
    static long lowTime = 0;
    static long tempPulse;




    void setup()

    {

    pinMode(READ_PIN,INPUT);

    Serial.begin(9600);

    }

    byte x = 0;



    void loop()


    //================================================================================================
    //CALCULATING PWM DUTY CYCLE AND CONVERTING TO RPM
    //================================================================================================

    {
    readPWM(READ_PIN);

    //=================================================================================================================
    // Print duty to serial
    //=================================================================================================================

    // Serial.println(duty); //prints 'duty' to serial monitor

    //=================================================================================================================
    //Print calculated RPM to serial
    //=================================================================================================================

    Serial.println(RPM); //Prints calculated RPM
    }

    //================================================================================================
    //Takes in reading pins and outputs pwm duty cycle.
    //================================================================================================

    void readPWM(int readPin){
    highTime = 0;
    lowTime = 0;

    tempPulse = pulseIn(readPin,HIGH);
    if(tempPulse>highTime){
    highTime = tempPulse;
    }

    tempPulse = pulseIn(readPin,LOW);
    if(tempPulse>lowTime){
    lowTime = tempPulse;
    }

    //========================================================================================
    //Calculates rpm from duty cycle % (120 = max rpm 12000/100 )
    //========================================================================================


    duty = (100*(highTime/(double (lowTime+highTime))));
    RPM = duty * (maxrpm/100);

    delay(500); // delay in between reads for stability


    }

LauriBuell
Posts: 1
Joined: Thu Nov 01, 2018 5:44 pm

Re: PWM frequency

Post by LauriBuell » Thu Nov 01, 2018 5:59 pm

I think its 8khz, but have no oscilloscope to confirm... and no way I can go through the software sources to figure it out. I am a complete novice at programming, just slightly beyond "blinkish" type arduino sketches thus far.

pcb assembly

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest