The firmware supports two PWM types: software and hardware.

Software, configurable 1, 2, 3, 5 kHz – the firmware can generate the PWM signal on any pin. The higher frequency requires more CPU resources. The frequency may slightly float. You may configure up to two PWM outputs in the configuration.

Hardware, configurable 1, 2, 4, 8, 16, 32, 64, 128 kHz or low frequencies 480, 240, 120, 60, 30, 16, 8, 4 Hz – the firmware uses the hardware PWM generator on the chip. The PWM duty cycle has 256 states (8 bits). It is precise and does not use CPU resources.

C253x

The hardware PWM on CC253x can work on the following pins only:

PWM #1 pins: P13, P14, P16, P17 (one of these pins)
PWM #2 pins: P10, P11, P20, P23 (one of these pins)
PWM #3 (it is the Premium feature) pins: P03, P04, P05, P06 (one of these pins). This PWM also supports low frequencies below 1 kHz.

If the frequency of all PWM is identical, you may create up to five hardware PWM.

PWM #1 pins: P13 or P16
PWM #2 pins: P10 or P20
PWM #3 pins: P14 or P17
PWM #4 pins: P11 or P23
PWM #5 (it is the Premium feature) pins: P03, P04, P05, P06. This PWM also supports low frequencies below 1 kHz.

If you select any of the P03, P04, P05, P06 pins for PWM, you cannot use UART in your configuration because these pins use the same hardware resources.

CC2652 or CC1352

Hardware PWM on C2652 or CC1352 can work on any pin and does not have hardware restrictions.

Features

If a PWM output is linked to a corresponding input (e.g., Input 2 – Output 2), the input can control the PWM state:

  1. If the “switch” option for a linked input is “off” and the “Linked input” option for the PWM output is “Changes level”, every click changes the PWM level value step-by-step (12 steps, cyclic, 0 – 20 – 40 .. 240 – 255 – 0).
  2. If the “switch” option for a linked input is “off” and the “Linked input” option is “On/Off,” every click toggles the state of the PWM output from ON to OFF and vice versa. If you press and hold the linked button, the firmware will change the PWM level value step-by-step (12 steps, cyclic, 0 – 20 – 40 .. 240 – 255 0).
  3. If the “switch” option for input is “on,” the switch changes the output state to on or off. The firmware can remember the PWM level before switching off and restore it after switching on. You can set the exact PWM level from a bounded control or a coordinator.

Transition – defines the time interval when the firmware smoothly changes the level value from 0 to 254. The firmware calculates the corresponding time interval for short transitions. If the transition time is zero, the firmware immediately changes the PWM level.

Linked input – change the mode if a linked push button.

Remember state – the firmware saves the last state of the PWM output and restores it after power loss.

Inverted – if this option is on, the firmware decreases the duty cycle of a PWM output. So, the maximum level means the permanent LOW state of a PWM output.

Minimum, Maximum – you can define limits of PWM signal width. Default values are 0 and 255. You can use these limits if your device only accepts impulses with a limited width.

Shift (Offset) – the additional offset value for the PWM signal width from -127 to +127. The default value is 0. It can be useful if your device does not react to impulses with a width in a some range.

Zigbee cluster: ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL
Zigbee attributes: ATTRID_LEVEL_CURRENT_LEVEL (uint8)
Zigbee commands: read, write, moveToLevel, moveToLevelWithOff

Zigbee cluster: ZCL_CLUSTER_ID_GEN_ANALOG_INPUT_BASIC
Zigbee attributes: ATTRID_IOV_BASIC_PRESENT_VALUE (float, range: 0-255)
Zigbee commands: read, write

Zigbee2MQTT commands

on/off - Look for commands and examples for GPIO outputs.
write - sets the PWM duty cycle.
Topic: zigbee2mqtt/[friedly_name]/[channel]/set/brightness
Channel: l1, l2, l3 … l16
Payload: value
Topic: zigbee2mqtt/[friedly_name]/set/[channel]
Channel: l1, l2, l3 … l16
Payload: {"brightness": value, "transition": 3}
value - 0 .. 254.
transition - (optional) the transition time in seconds between states.
read - reads the current value
Topic: zigbee2mqtt/[friedly_name]/[channel]/get/brightness
Payload: none
Returns: {"brightness_[channel]": value}

Comments
Harvey Specter
Posted at 17:41 March 19, 2024
Vihaan
Reply
Author

Hello, Owner. Thanks for your reply!
IMO, you’ll should to add an option that will allow simply toggle the brightness between 0% and 100% using a connected phisical switch.
Basically, people use switches when they just need to make a light in a room in a quick way.
And that’s a very annoying situation when you just want to turn on the light quickly by flipping the switch, but then you’ve to go look for your phone to see something around. For example, when your family was watching movie with dim light night before.
Unfortunately, the lack of this option makes your beautiful firmware completely useless for using as a dimmer with physical switch connected

    Harvey Specter
    Posted at 03:34 March 20, 2024
    Owner
    Reply
    Author

    The linked button toggles between 0 and the last level (before off). It is enough in most cases.

Harvey Specter
Posted at 19:55 March 16, 2024
Vihaan
Reply
Author

Firmware remembers the brightness level even with unchecked “Remember state” option. After turning on with a phisical on/off switch it always sets to last brightness level. Is there way to get simple toggling between 0% and 100% brightness with connected basic phisical switch and tune other brightness levels with z2m?

    Harvey Specter
    Posted at 09:47 March 19, 2024
    Owner
    Reply
    Author

    The “Remember state” option works when you power on/off the device. Sorry, but you cannot set the maximum level from the linked switch.

Harvey Specter
Posted at 18:32 November 19, 2022
frederic
Reply
Author

Hello.
About the PWM feature :
I need to have 0 volt at power up until the microcontroler receives a command.
I think I tried all the possible settings but I always get 3.3V (CC2530 power supply) at power up.
Is there is solution to have 0 volt at power up until the microcontroler receives a command ?
Thanks.

    Harvey Specter
    Posted at 05:35 November 21, 2022
    Owner
    Reply
    Author

    The firmware may remember a last state and restore it after power up, if it helps.

Harvey Specter
Posted at 23:43 June 24, 2022
Goridat
Reply
Author

Is there a way to get a 50 Hz PWM output?

    Harvey Specter
    Posted at 03:58 June 25, 2022
    Owner
    Reply
    Author

    The Premium version has the slow PWM feature with this frequency. Please note, it can only with a specific pin on cc2530 or with any pin on cc2652.

Harvey Specter
Posted at 08:02 April 28, 2021
Ilya
Reply
Author

Is it possible to get a transition slider (like brightness slider, or text field) in zigbee2mqtt web interface? (in custom converter for Z2M).

Thanks for answer!

    Harvey Specter
    Posted at 08:40 April 28, 2021
    Owner
    Reply
    Author

    You should create and use a custom converter for your device. This slider will appear.

      Harvey Specter
      Posted at 14:09 April 28, 2021
      Ilya
      Reply
      Author

      Button in ptvo creates custom converter without this slider. Where I can find info about transition variable for converter?

        Harvey Specter
        Posted at 03:34 April 29, 2021
        Owner
        Reply
        Author

        Sorry, but I didn’t understand your question correctly. Unfortunately, you cannot get a slider for a transition time.

Harvey Specter
Posted at 21:49 January 7, 2021
Sandr
Reply
Author

Thank you for your work!

I have write converter for Homeassistant-Zigbee2mqtt
https://github.com/SandrRu/Hassio_Zigbee2mqtt_converters

Leave a Reply