zigbee-configurable-firmware icon indicating copy to clipboard operation
zigbee-configurable-firmware copied to clipboard

Using PWM output as servo control signal (1ms to 2ms pulse) corresponding to 0-100% set point

Open HardSoftMus opened this issue 3 years ago • 2 comments

It would be very interesting to have a "modified" PWM output for controlling mechanical servos. It sould generate a PWM pulse of about 50Hz with an "on" time varying from 1ms to 2ms when the parameter goes from 0% to 100%

This opens a new world of oportunities for controlling a lot of common mechanic devices (venetian curtains, AC grids...) There are a lot of powerful servos out there, moving up to 50kg/cm force that could be used, like these:

https://es.aliexpress.com/item/1005003352672567.html?spm=a2g0o.productlist.0.0.2cc75d4aZgOwbA&algo_pvid=f67a634b-9e75-451a-9402-b8f1044549b0&algo_exp_id=f67a634b-9e75-451a-9402-b8f1044549b0-4&pdp_ext_f=%7B"sku_id"%3A"12000025360895100"%7D&pdp_pi=-1%3B50.28%3B-1%3B-1%40salePrice%3BEUR%3Bsearch-mainSearch https://es.aliexpress.com/item/725115447.html?spm=a2g0o.productlist.0.0.2cc75d4aZgOwbA&algo_pvid=f67a634b-9e75-451a-9402-b8f1044549b0&aem_p4p_detail=202203071451144733336428780000003821898&algo_exp_id=f67a634b-9e75-451a-9402-b8f1044549b0-0&pdp_ext_f=%7B"sku_id"%3A"66461318699"%7D&pdp_pi=-1%3B32.81%3B-1%3B-1%40salePrice%3BEUR%3Bsearch-mainSearch

Thank you very much for your wonderful software. Best regards

HardSoftMus avatar Mar 07 '22 22:03 HardSoftMus

What do you mean by ""on" time varying from 1ms to 2ms"?

ptvoinfo avatar Mar 12 '22 10:03 ptvoinfo

To control a servo you need a pulse repeating at about 50 times per second. This signal is a positive pulse that has a minimum of 1 ms (0%) up to a maximum of 2 ms (100%) so, the mechanism goes from one end position to another end position where the pulse width varies from 1 to 2 ms.

I hope to have explained

El sáb., 12 mar. 2022 11:09, ptvo @.***> escribió:

What do you mean by ""on" time varying from 1ms to 2ms"?

— Reply to this email directly, view it on GitHub https://github.com/ptvoinfo/zigbee-configurable-firmware/issues/99#issuecomment-1065855545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOL66VSDAII2U5MPI2JAE5DU7RUPBANCNFSM5QEVVAJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

HardSoftMus avatar Mar 12 '22 22:03 HardSoftMus

I could definitely use this feature!!!!!

To be able to control a Servo using PWM just like ATMEGA chips can would be ideal.

Right now the only solution is to use the PCA9685 with adds unnecessary costs to a project, especially when you only need one or two Servos.

LenirSantiago avatar Nov 03 '22 16:11 LenirSantiago

I've tested low frequency PWM output that is available in the Premium version with MG90S, and it works well at 120 Hz. The main disadvantage is you cannot use the full range of the PWM output. The servo accepts impulses in the range from 20 to 79.

ptvoinfo avatar Nov 04 '22 06:11 ptvoinfo

Ok. Thank you. If you decide to include this feature let me know. I don't need it just now because I don't have time. I will make the design about January. If not, I could use another approach with an all analog servo, but it is far less convenient for me.

El vie, 4 nov 2022 a las 7:09, ptvo @.***>) escribió:

I've tested low frequency PWM output that is available in the Premium version with MG90S, and it works well at 120 Hz. The main disadvantage is you cannot use the full range of the PWM output. The servo accepts impulses in the range from 20 to 79.

— Reply to this email directly, view it on GitHub https://github.com/ptvoinfo/zigbee-configurable-firmware/issues/99#issuecomment-1303020694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOL66VXSAXEXVF5LGVHUOOLWGSSDLANCNFSM5QEVVAJA . You are receiving this because you authored the thread.Message ID: @.***>

-- Luis Hierro

HardSoftMus avatar Nov 04 '22 10:11 HardSoftMus

I've tested low frequency PWM output that is available in the Premium version with MG90S, and it works well at 120 Hz. The main disadvantage is you cannot use the full range of the PWM output. The servo accepts impulses in the range from 20 to 79.

The reason that it only accepts 20 to 79 may be because the servos need a PWM signal at 50Hz, not 120Hz. I believe this is the case for most servos in the market.

Could you retest using 50Hz?

LenirSantiago avatar Dec 11 '22 17:12 LenirSantiago

Or perhaps looking at the Servo class for Arduino. Here are some good references: https://gist.github.com/ajfisher/8c5146bff264b88d04cc https://github.com/arduino-libraries/Servo

LenirSantiago avatar Dec 11 '22 17:12 LenirSantiago

The standard time for servos is a pulse of between 1ms and 2 ms. 1ms corresponds to one mechanical end of the servo and 2ms to the other end. The repetition time is nor relevant, but usually is in between 10 and 20 ms

El dom, 11 dic 2022 a las 18:38, Lenir Santiago @.***>) escribió:

Or perhaps looking at the Servo class for Arduino. Here are some good references: https://gist.github.com/ajfisher/8c5146bff264b88d04cc https://github.com/arduino-libraries/Servo

— Reply to this email directly, view it on GitHub https://github.com/ptvoinfo/zigbee-configurable-firmware/issues/99#issuecomment-1345613503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOL66VX5EODPRRAEMLZJP2DWMYGS3ANCNFSM5QEVVAJA . You are receiving this because you authored the thread.Message ID: @.***>

-- Luis Hierro

HardSoftMus avatar Dec 11 '22 20:12 HardSoftMus

@LenirSantiago With the 50Hz frequency, this range (20 - 79) is rather narrow. I don't know the precise numbers, but in my case, 120 Hz provides more smooth control.

ptvoinfo avatar Dec 12 '22 08:12 ptvoinfo

I don't use 1,0,high,low because it depends on polarity. I prefer to use the terms on off or active inactive. That said, the "off" inactive part of the pulse is the rest level between pulses and the "on" or active part of the pulse is what indicates the mechanical position that should have the servo. Thus, the "on" time has to be between 1ms and 2 ms. If it is narrower or wider than these values, the electronics will drive the servo to either end and force the mechanics and the motor, which causes a lot of power consumption and possibly damage something. Some electronics detects the overdriving and limits the driving to avoid damage.

With each pulse that the servo receives (on time), it compares the actual position with the width of the pulse (on tiime) and eventually drives the motor to coincide with the received consign.

Don't hesitate to ask if you need more explanation. Best regards.

El lun, 12 dic 2022 a las 9:39, ptvo @.***>) escribió:

@LenirSantiago https://github.com/LenirSantiago With the 50Hz frequency, this range (20 - 79) is rather narrow. I don't know the precise numbers, but in my case, 120 Hz provides more smooth control.

— Reply to this email directly, view it on GitHub https://github.com/ptvoinfo/zigbee-configurable-firmware/issues/99#issuecomment-1346094921, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOL66VVU436PVAR2RBME6JTWM3QF5ANCNFSM5QEVVAJA . You are receiving this because you authored the thread.Message ID: @.***>

-- Luis Hierro

HardSoftMus avatar Dec 12 '22 10:12 HardSoftMus

@LenirSantiago With the 50Hz frequency, this range (20 - 79) is rather narrow. I don't know the precise numbers, but in my case, 120 Hz provides more smooth control.

In that case, as long as follows how servos signal works, meaning 20 is an ON pulse of 0.5ms, 50 is an ON pulse of 1.5ms and 79 is an ON pulse of 2.5ms, updating at least every 20ms, then as per @HardSoftMus it should work without causing any mechanical/electrical problems.

LenirSantiago avatar Dec 12 '22 16:12 LenirSantiago

Here's a few articles about interfacing an 8051 MCU with a servo, including C code: https://technobyte.org/8051-servo-motor-interfacing/ https://www.electronicwings.com/8051/servo-motor-interfacing-with-8051 https://myvirtualgarage.wordpress.com/2012/07/19/servo-motor-serial-com-and-8051/

LenirSantiago avatar Dec 12 '22 16:12 LenirSantiago

0.5ms and 2.5ms are clearly out of margins. The pulse *has to be *between 1ms and 2ms. This is a standard comes from the invention of the micro-servos for aeromodels, many many years ago and remains unchanged.

with less than 1ms or more than 2ms the mechanic and/or the electronic part can suffer. Furthermore, the position of the servo will not correspond with the input consign, as it would be out of the mechanical and electrical margins of the servo.

I attach a PDF that explains the fundamentals of servos.

El lun, 12 dic 2022 a las 17:28, Lenir Santiago @.***>) escribió:

Here's a few articles about interfacing an 8051 MCU with a servo, including C code: https://technobyte.org/8051-servo-motor-interfacing/ https://www.electronicwings.com/8051/servo-motor-interfacing-with-8051

https://myvirtualgarage.wordpress.com/2012/07/19/servo-motor-serial-com-and-8051/

— Reply to this email directly, view it on GitHub https://github.com/ptvoinfo/zigbee-configurable-firmware/issues/99#issuecomment-1346834328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOL66VXF66MH4NJMDSQUV23WM5HETANCNFSM5QEVVAJA . You are receiving this because you were mentioned.Message ID: @.***>

-- Luis Hierro

HardSoftMus avatar Dec 12 '22 23:12 HardSoftMus