Hi,
for my project I need to measure a duty cycle of multiple PWM signals (cca 10) generated by another microcontroller so that I can work with those values in my UNO. Unfortunately the UNO can't handle that many PWM measurements (using timers) so I have to ask if there is another way to measure that duty cycle or some IC that can determine the duty cycles and send them to the UNO via SPI, I2c, etc . . .
You have 10 PWM signals from another controller and you want to measure the duty cycle of each?
Maybe you can use a 74HC4067 to mux the 10 inputs to PB0 (pin 8) and use the input capture function of TIMER1.
or an oscilloscope�
Or a logical analyzer.
I got one of these
only I paid less. Shop around.
It works very well.
What is the frequency of these signals? What precision do you need in measuring them?
a7
+1 for that. I have not used my scope since I bought one.
Add the free PulseView software and you have a great logic analyzer tool. There are many many decoders that come with the software, including a PWM (duty cycle) decoder.
I think Pin Change Interrupts would be fairly good at doing that. You will need 10 input pins. Use the PinChangeInterrupt library and store micros() for the last two pin changes. On a rising edge, the current micros() minus the first sample (the previous rising edge) will get you the cycle period. The second sample minus the first will be the ON time. Then divide to get duty-cycle. If the latest previous sample was a long time ago, us the state of the pin to tell if the duty-cycle is 0% oe 100%.
Why not have the microcontroller that's creating the PWM signals send the duty cycle values?
It depends ...
- What are the PWM signals used for?
- Perhaps a timing diagram would help?
- What are the PWM frequencies?
- Are any of the signals complimentary? (this reduces the unique timers required)
Hi, using an oscilloscope or a logic analyzer (I have that one too ) is impossible for my project. I'd have to measure it and enter the value into my UNO every time the duty cycle changed to work with it as a variable.
I can't (don't want to) get the microcontroller that is generating the PWM signals to send the duty cycle values because that would require me to edit the existing third party firmware on that board. The problem with that is that I'd have to do that every time I'll do a firmware update.
The Pin Change Interrupts and the 74HC4067 solutions look like they might do the trick. I'll look into those and see if it'll work. Any other suggestions are welcome.
This may not be as good as the interrupt based way - but if you apply the pwm to a suitable low pass filter, then the output of the filter directly corresponds to the duty cycle - all you need to know is what the 100% duty cycle voltage corresponds to. For example for a 5V pwm, 100% duty cycle corresponds to 5V, 50% to 2.5V. The filters output / 5V will give you the duty cycle.
How fast do you need to measure the duty cycles and with what resolution?
You could low-pass filter the duty cycles into analog values, then use a multiplexer like SparkFun Analog/Digital MUX Breakout - CD74HC4067 - BOB-09056 - SparkFun Electronics to read the signals into your UNO.
(ETA: Yeah, what @rohitbd said.)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.