4700 views|3 replies

25

Posts

0

Resources
The OP
 

[Runhe Neptune Review] Five PWM [Copy link]

 

PWM: Pulse Width Modulation

It is to periodically control the time (duty cycle) of IO pulling high and low to control the on and off of the switch tube to achieve power control, such as LED dimming, DC motor speed control, etc.

I mainly use it here to control LED dimming. We know that the frequency at which the human eye does not see the light flicker is above 50hz, so if we want our eyes to see the light without flickering, the high and low PWM should be 10ms respectively, and the off time cannot be greater than 10ms. If it is greater than this value, we will see flickering. If I don't want the switch on time to be so bright and less than 10ms, then we can only increase the frequency. By increasing the frequency, we can control the length of time the switch is on, so as to achieve power control and control the brightness of the LED without flickering.

W800 PWM usage :

Initialization: Since it has been officially packaged, initialization is very simple. You only need to call an initialization to turn on the PWM function. Through the following enumeration values, we know that up to 6 PWM channels can be turned on.

Startup: There is only one function for startup, but we must pay attention to the entry parameters. The first is to configure the PWM channel, the second is the period, that is, the duty cycle, and the third is the frequency. By changing the last two parameters, we can achieve the PWM parameters we want.

Test : Test Many students may be like me. How can we view the waveform without an oscilloscope? As a hardware developer, you can prepare some small tools. The following picture shows a simple logic analyzer I bought online. It can be used to capture PWM waveforms and analyze serial communication protocols (such as UART I2C SPI, etc.), which are very useful.

In order to facilitate viewing of the waveform, I wrote an operation: when the protocol interface receives data, the PWM value increases by 10, and the cycle continues like this. The figure below shows that my frequency is set to 1000, which is 1K, and the period is 255. Why is it 255? There is no comment on the interface, and I have not turned to the manual to explain how to set this period. Through testing, I found that this period is just an 8-bit register, and the overflow starts from the beginning, so 255 is given.

The following pictures are waveforms captured by logic analyzer software: by sending instructions, only the waveform of channel 0 is changed, and channel 1 remains unchanged. Figure 1 shows the waveform when both PWM channels are set to 0 when the power is turned on, and the frequency is exactly 1K.

Set the waveform close to 50%:

Set the waveform close to 100%:

This section will briefly talk about PWM. Knowing the role of PWM, the brightness and color temperature of the two-color LED light to be made in the next section are both based on PWM.

Latest reply

255 This counter is a bit short, the pulse time is a bit short. At least give me a 16-bit one.   Details Published on 2021-11-9 17:40
 

6547

Posts

0

Resources
2
 

Which function can change the frequency and duty cycle of PWM?

Comments

The first parameter of the pwmStart function is the channel, the second parameter is the duty cycle, and the third is the frequency.  Details Published on 2021-11-10 23:29
 
 
 

7422

Posts

2

Resources
3
 

255 This counter is a bit short, the pulse time is a bit short. At least give me a 16-bit one.

 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

25

Posts

0

Resources
4
 
Jacktang posted on 2021-11-9 07:17 Which function is started to change the frequency and duty cycle of PWM

The first parameter of the pwmStart function is the channel, the second parameter is the duty cycle, and the third is the frequency.

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list