I have spwm output from arduino, and when i read on analogread it shows only 1023 and 0, because it is digital signal. Is there any way to convert these spwm value into analog value reading
-
arduino had 10 bit ADC that means maximum value that you can read is 0-1023. It is an analog signal. or if you want to convert digital value into analog value use can DAC IC easily available in the market.– VaibhavMay 13, 2019 at 6:09
-
Thanks try to search it– rahulMay 13, 2019 at 13:54
1 Answer
The problem seems to be clear to you: for slow systems a pwm signal can be considered analog, but measuring at higher rates and without a filter reveales the digital nature behind pwm and all you see is either logic high (1023) or low (0). Possible solutions are:
- apply a filter in hardware (LC low-pass)
- apply a filter in software (e.g. by calculating a running mean)
- attach interrupts to the rising/falling edge of your signal and measure the high/low time to calculate the duty cycle
Which of those options to choose will mainly depend on the PWM frequency you want to measure. For low frequency I recommend option 3 (special cases are duty cycles around 0% and 100% as there are no edges), for higher frequencies I would use option 1/2.