Industrial Automation HAT OD PWM Frequency

bob_widlar

New member
I am using your Industrial Automation HAT with 2x 8 relay boards and 1x 16 LV input board with a raspberry pi 5 and everything worked out of the box with no issues at all, complements for a well engineered system.

The fixed frequency on the open-drain PWM outputs (fixed to 6.4kHz) are a bit of a limitation at the moment, as it makes it impossible to drive interfaces such as servos that require a much lower PWM frequency (50-400Hz).
Is there a way to modify this frequency? If not, can I please submit this as a feature request in a software update? Is there another HAT that does implement variable frequency PWM?
 

alexburcea

Moderator
Staff member
Hi,
Thank you for the appreciations. please add some stars at the products rating on our website.
The Home Automation HAT has variable PWM frequency.
Industrial card share one timer channels with the 4-20mA outputs so the changing frequency will influence also that outputs. On the current hardware only 3 of 4 channels frequency can be modified with a new firmware version.
 

bob_widlar

New member
Thanks for the prompt response. I have looked at the documentation and repository for the Home Automation HAT but I cannot see how one would change the PWM frequency using e.g. the Python library, it seems asif it is fixed to 48kHz. Could you point me in the right direction?
 

bob_widlar

New member
Thank you, will unfortunately only be able to test if I order a Home Automation Board. Will rather investigate other options for servo control.
 

alexburcea

Moderator
Staff member
The fastest way to use the industrial for the servo is to create a firmware with changed frequency (name a value)for 3 of 4 od outputs, put it on our server, you make a firmware update the I rollback the current version.. or not.
Please tell me the frequency you need.
 

alexburcea

Moderator
Staff member
The duty cycle is form 0 to 10000 or for the command the resolution is 0.01%
Please update your card firmware and your channels 1,2and 4 frequency will be 50Hz.
Let me know when you done to revert the changes.
Update instructions here.
 

bob_widlar

New member
Servo control works perfect, thank you. You mentioned that the 4-20mA outputs will be effected by this change in firmware, will they be unusable now?

Here is some typescript code for calculating the duty cycle from the angle for my specific servo (CLS-HV7346MG), in case anyone needs this in the future:
JavaScript:
const calculatePwmFromAngle = (angle: number) => {
        const theta = angle > 90 ? 90 : angle < -90 ? -90 : angle;
        const zero_pulse_width = 1520; //zero angle microseconds, from servo data sheet
        const pulse_width = zero_pulse_width + theta * 10 * 1.1; //microseconds, tune for servo
        const period = 20000; //50Hz PWM output
        const duty = pulse_width / period * 100; //calculate duty cycle
        return duty <= 100 ? 100 - duty : 0; //Open-Drain inverted output
    }
 

alexburcea

Moderator
Staff member
The 4-20 mA outputs and 0-10V outputs are not affected by this change. This is the reason we modify the frequency for only 3 of 4 OD outputs.
Thanks for sharing the calculus.
We have two dedicated ports for this kind of servo's on our Multi-IO card.
 
Top