PWM frequency ?

16 views
Skip to first unread message

Dean Gouramanis

unread,
May 13, 2020, 1:12:59 PM5/13/20
to beagleg-dev
Hello beagleg-dev.

Is there a way to adjust the PWM frequency without recompiling?

Henner Zeller

unread,
May 13, 2020, 1:51:07 PM5/13/20
to Dean Gouramanis, beagleg-dev
Hi,
> Is there a way to adjust the PWM frequency without recompiling?

Right now it is indeed fixed at 16kHz, but should probably made
configurable. Let me have a look this evening.

Did you run into trouble with the default frequency in your system ?

Cheers,
Henner.

Dean Gouramanis

unread,
May 13, 2020, 3:21:00 PM5/13/20
to beagleg-dev
I am searching for the best way to control a hobby servo from G code. Ideally I could map an axis to the duty_cycle to create a 1-2 ms pulse @ 300 Hz.

Henner Zeller

unread,
May 13, 2020, 3:28:22 PM5/13/20
to Dean Gouramanis, beagleg-dev
On Wed, 13 May 2020 at 12:21, Dean Gouramanis <temprod...@gmail.com> wrote:
>
> I am searching for the best way to control a hobby servo from G code. Ideally I could map an axis to the duty_cycle to create a 1-2 ms pulse @ 300 Hz.

You can change the default frequency at
https://github.com/hzeller/beagleg/blob/master/src/pwm-timer.cc#L90
and re-compile.
... but I don't know if the wave-form would be useful, but on the
highlevel you should be able to generate the proper pulse-length with
values between 30% and 60% 'speed'.

Hope this helps,
-h

>
>
>
> On Wednesday, May 13, 2020 at 1:51:07 PM UTC-4, Henner Zeller wrote:
>>
>> Hi,
>> > Is there a way to adjust the PWM frequency without recompiling?
>>
>> Right now it is indeed fixed at 16kHz, but should probably made
>> configurable. Let me have a look this evening.
>>
>> Did you run into trouble with the default frequency in your system ?
>>
>> Cheers,
>> Henner.
>
> --
> You received this message because you are subscribed to the Google Groups "beagleg-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beagleg-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beagleg-dev/fdac98f3-958c-40f1-b367-91be99148b0b%40googlegroups.com.

Henner Zeller

unread,
May 15, 2020, 2:42:36 AM5/15/20
to Dean Gouramanis, beagleg-dev
On Wed, 13 May 2020 at 12:28, Henner Zeller <h.ze...@acm.org> wrote:
>
> On Wed, 13 May 2020 at 12:21, Dean Gouramanis <temprod...@gmail.com> wrote:
> >
> > I am searching for the best way to control a hobby servo from G code. Ideally I could map an axis to the duty_cycle to create a 1-2 ms pulse @ 300 Hz.
>
> You can change the default frequency at
> https://github.com/hzeller/beagleg/blob/master/src/pwm-timer.cc#L90
> and re-compile.
> ... but I don't know if the wave-form would be useful, but on the
> highlevel you should be able to generate the proper pulse-length with
> values between 30% and 60% 'speed'.

Did it work ?

Dean Gouramanis

unread,
May 20, 2020, 8:04:35 PM5/20/20
to beagleg-dev
I wrote a C++ program that works to control the hobby servo from the shell. I've been trying to integrate it with beagleg. I added a M code 150 to gcode-parser.cc for testing. The program freezes on fopen. Any idea why?

Here is the C program that works from the shell:

int main(int argc, char* argv[]){
        FILE *pulse = NULL;
        pulse = fopen ("/sys/class/pwm/pwm-1:1/duty_cycle", "w");
        fwrite ("1000000", sizeof(char), 7, pulse);
        fclose (pulse);
        return 0;
}

And here is the code that freezes in gcode-parser.cc:
const char *GCodeParser::Impl::handle_M150(const char *line) {
        FILE *fp;
        fp = fopen("/sys/class/pwm/pwm-1:1/duty_cycle", "w");
        fclose(fp);
        return NULL;
}
Reply all
Reply to author
Forward
0 new messages