Here, the receiver outputs a pwm waveform with a frequency of 50hz and a period of 20ms. The pwm signal is received by the external interrupt port of the MCU, and the timer/counter is enabled to count the duration of the pwm high level.
The pulseIn function in Arduino can directly read the value of pwm, and can refer to its underlying implementation.
The key part of the article:
Subtle, infinite loop read pin level. Because it is not sure whether the instant of receiving the input pwm of the IO port is high level or low level, the first level is judged in the While loop, then the low level is judged, and then the high level is judged, thereby obtaining accurate duty. ratio.
As for how to read pwm on the microcontroller? After looking up some information on the Internet, I learned that it can be implemented by an external interrupt + timer. Initially I refer to this source code:
One problem in this code is that when the MCU meets the interrupt condition, it will jump to the external interrupt handler function. It feels that this is too much CPU resource. You can write a function to open the external interrupt when listening to the pwm value. The value is turned off when the value is turned off. The specific method is as follows:
STC15F104W MCU external interrupt 0 (INT0) and external interrupt 1 (INT1) trigger have two trigger modes, rising edge or falling edge can be triggered mode and only falling edge trigger mode.
IT0/TCON.0 and IT1/TCON.2 in the TCON register determine whether external interrupts 0 and 1 can be triggered on both rising and falling edges or only falling edge. If ITx = 0 (x = 0, 1), the system can generate an external interrupt after detecting a rising or falling edge on the INTx (x = 0, 1) pin. If ITx = 1 (x = 0, 1), the system will generate an external interrupt after the falling edge of the INTx ( x = 0, 1) pin is detected.
In the program
[cpp] view plain copyIT0 = 0;
IT1 = 0;
Therefore, an external interrupt can be generated after a rising edge or a falling edge. I assume that the interrupt is triggered by a rising edge.
[cpp] view plain copyvoid pulseIn0(){
While(INT0==1);
EX0 = 1;
}
The meaning of this code is that if the received pwm signal is at a high level, it will enter an infinite loop first. When the pwm signal is at a low level and then the interrupt is turned on, the next rising edge can trigger the interrupt, and the trigger is enabled immediately after the interrupt is triggered. Timer 0 can count high levels and turn off interrupts on the next falling edge.
The test results are as follows:
The pwm signal received by the INT1 port satisfies a1"1480&&a1"1520, and the led1 is extinguished.
Moreover, the pwm value read by Arduino is also in this interval. It can be seen that the accuracy of reading the value of pwm by this method is very high. After that, the STC15F104W MCU can be used instead of Arduino, and the IO port of the MCU can be controlled by pwm.
Household Lighting Led Driver
A comprehensive series of Office lightings drivers, suitable for use in a range of household Lighting applications, including livung room Lighting, Kitchen Lighting, bathroom Lighting, Entertainment Lighting, etc. We have skilled engineers to answer all your questions and enquiries and provide all-round solutions basis on your project(s) and provide technical supporting.
Specifically for household light, As long as the home for the panel lights, lamps and the like, indoor waterproof LED driver.Europe and the United States with the earlier, energy-saving environmental awareness earlier, widely popular.Home, then the safety performance requirements are relatively high, high voltage short circuit protection.
Parameter:
Input voltage: 100-277vac / 100-240vac / 100-130vac / 180-240vac / 100-347V
output voltage: 25-40vdc / 27-42vdc / 35-45vdc / 50-70vdc / 12Vdc / 24vdc
current: 100mA-8000mA.
Power factor: >0.9
Dimming:0-10V / PWM / RX / DALI.
>=50000hours, 3-5 years warranty.
certificate: UL CE FCC TUV SAA ect.
What's the benefits of Fahold Driver?
- Standard Linear Lighting
- Cost-effective led driver solution for industry,commercial and other applications
- Good quality of led driver with high efficiency output to meet different requirements
- Easy to order and install,requiring less time,reducing packaging waste and complexity
- Flexible solution
FAQ:
Question 1:Are you a factory or a trading company?
Answer: We are a factory.
Question 2: Payment term?
Answer: 30% TT deposit + 70% TT before shipment,50% TT deposit + 50% LC balance, Flexible payment
can be negotiated.
Question 3: What's the main business of Fahold?
Answer: Fahold focused on LED controllers and dimmers from 2010. We have 28 engineers who dedicated themselves to researching and developing LED controlling and dimming system.
Question 4: What Fahold will do if we have problems after receiving your products?
Answer: Our products have been strictly inspected before shipping. Once you receive the products you are not satisfied, please feel free to contact us in time, we will do our best to solve any of your problems with our good after-sale service.
Ceiling Light Panels Drivers,Led Light Fixtures,Led Ceiling Lights Driver
ShenZhen Fahold Electronic Limited , https://www.fahold.net