PWM - Pulse Width Modulation
This class provides the feature of PWM output.
Note: BC25 series module does not support this feature.
Constructor
misc.PWM
class misc.PWM(PWM.PWMn,PWM.ABOVE_xx, highTime, cycleTime)
Parameter:
PWM.PWMn
- Integer type. PWM channel. Click here to learn more for supported channels and corresponding pins.PWM.ABOVE_xx
- Integer type. Time range.For EC200U, EC600U , EG915U and EG912U series modules:
PWM.ABOVE_MS ms-level time range: (0,10]
PWM.ABOVE_1US us-level time range: (0,10000]
PWM.ABOVE_10US us-level time range: (1,10000]
PWM.ABOVE_BELOW_US ns-level time range: [100,65535]highTime
- Integer type. High level time.For ms-level time, unit: ms.
For us-level time, unit: us.
For ns-level: it needs to be calculated by users.
Frequency = 13Mhz / cycleTime
Duty cycle = highTime/ cycleTimecycleTime
- Integer type. Cycle time.For ms-level time, unit: ms.
For us-level time, unit: us.
For ns-level: it needs to be calculated by users.
Frequency = 13Mhz / cycleTime
Duty cycle = highTime/ cycleTime
Example:
from misc import PWM
pwm1 = PWM(PWM.PWM1, PWM.ABOVE_MS, 1, 2)
Mapping Relationship Between PWM Channels and Pysical Pins:
The corresponding pins of EC100Y series module for PWM0-PWM3 are as follows:
PWM0 – pin19
PWM1 – pin18
PWM2 – pin23
PWM3 – pin22
The corresponding pins of EC600S-CN and EC600N modules for PWM0-PWM3 are as follows:
PWM0 – pin52
PWM1 – pin53
PWM2 – pin70
PWM3 – pin69
The corresponding pins of EC800N module for PWM0-PWM3 are as follows:
PWM0 – pin79
PWM1 – pin78
PWM2 – pin16
PWM3 – pin49
The corresponding pin of EC200U series module for PWM0 is as follows:
PWM0 – pin135
The corresponding pin of EC600U series module for PWM0 is as follows:
PWM0 – pin70
The corresponding pins of EC600M module for PWM0-PWM3 are as follows:
PWM0 – pin57
PWM1 – pin56
PWM2 – pin70
PWM3 – pin69
The corresponding pin of EG915U series module for PWM0 is as follows:
PWM0 – pin20
The corresponding pins of EC800M/EG810M module for PWM0-PWM3 are as follows:
PWM0 – pin83
PWM1 – pin78
PWM2 – pin16
PWM3 – pin49
The corresponding pins of EG912N module for PWM0-PWM3 are as follows:
PWM0 – pin21
PWM1 – pin116
PWM2 – pin107
PWM3 – pin92
The corresponding pins of EG912U module for PWM0 are as follow:
PWM0 – pin20
The corresponding pins of BG95 module for PWM0-PWM1 are as follow:
PWM0 – pin66
PWM1 – pin85
The corresponding pins of EC200A/UC200A module for PWM0-PWM2 are as follow:
PWM0 – pin1
PWM1 – pin4
PWM2 – pin6
Methods
PWM.open
PWM.open()
This methods enables PWM output.
Return Value:
0
- Successful execution
-1
- Failed execution
PWM.close
PWM.close()
This methods disables PWM output.
Return Value:
0
- Successful execution
-1
- Failed execution
Example:
from misc import PWM
import utime
if __name__ == '__main__':
pwm = PWM(PWM.PWM0, PWM.ABOVE_MS, 1, 2) # Initializes a PWM object
pwm.open() # Enables PWM output
utime.sleep(10)
pwm.close() # Disables PWM output
Constants
Constant | Description | Module |
---|---|---|
PWM.PWM0 | PWM0 | EC600S / EC600N / EC100Y/EC600U/EC200U/EC800N/EC600M/EG915U/EC800M/EG912N/EG912U |
PWM.PWM1 | PWM1 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N |
PWM.PWM2 | PWM2 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N |
PWM.PWM3 | PWM3 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N |