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]
FCM360W:
PWM.ABOVE_MS ms-level time range:[0,1]
PWM.ABOVE_1US us-level time range:[0,1638]
PWM.ABOVE_10US us-level time range:[0,1638]
PWM.ABOVE_BELOW_US ns-level time range: [2500,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)
misc.PWM_V2
class misc.PWM_V2(PWM_V2.PWMn,frequency, duty)
Parameter:
PWM_V2.PWMn
- Integer type. PWM channel. Click here to learn more for supported channels and corresponding pins.frequency
- float type. will be in a form of float (I.e. 100.0 indicates 100Hz) .duty
- Integer type. a input range 0~100. The 50 means the duty ratio is 50%.
EC600U/EC200U/EG912U/EG915U para
duty
can't set to 0.
Example:
from misc import PWM_V2
pwm1 = PWM_V2(PWM_V2.PWM1, 100.0, 50)#set frequence to 100Hz,duty to 50%
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
The corresponding pins of EG915N module for PWM0-PWM3 are as follow:
PWM0 – pin25
PWM1 – pin26
PWM2 – pin104
PWM3 – pin18
Methods
PWM.open
PWM.open()
This methods enables PWM output.
Return Value:
0
- Successful execution
-1
- Failed execution
PWM_V2.open
PWM_V2.open([frequency],[duty])
This methods enables PWM output.frequency
and duty
are default parameters,only allow input both or neither.
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
PWM_V2.close
PWM_V2.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
from misc import PWM_V2
import utime
if __name__ == '__main__':
pwm = PWM_V2(PWM_V2.PWM0,100.0,50) #Initializes a PWM object,frequency is 100Hz,duty is 50%
pwm.open() # Enables PWM output
utime.sleep(10)
pwm.open(200.0,40)#Enables PWM output,and set frequecy to 200Hz,duty to 40%
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/EG915N |
PWM.PWM1 | PWM1 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N/EG915N |
PWM.PWM2 | PWM2 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N/EG915N |
PWM.PWM3 | PWM3 | EC600S / EC600N / EC100Y/EC800N/EC600M/EC800M/EG912N/EG915N |