So just bought an arduino Uno and I've been playing around with it. I want to connect one of the input pins to one of the PWM outputs and measure the output from there by sending it to my computer through Serial
and then plot it in python.
Sorry if this is a basic question. Thanks
-
PWM pins don't give an analog value. They are either 0v of 5v. Your idea is possible, but you'll receive almost exclusively 0's and 1023's.Gerben– Gerben2015年10月11日 13:03:00 +00:00Commented Oct 11, 2015 at 13:03
-
ok cool, I'm just worried that I'll burn out the board...evan54– evan542015年10月11日 13:08:01 +00:00Commented Oct 11, 2015 at 13:08
-
That won't happen here. Just be careful to never connect two pins that are both outputs (as setting one to HIGH and the other to LOW would create a short). If you want to be super-save, you could put a resistor between the two pins (e.g. 1kΩ) instead of a wire.Gerben– Gerben2015年10月11日 16:14:36 +00:00Commented Oct 11, 2015 at 16:14
1 Answer 1
PWM are digital output pins, and it seems that you wish to measure analog equivalent voltage generated by PWM output. If so, you'd need a filter.
Construct a unity gain op-amp based RC filter with cut-off frequency significantly smaller than PWM clock frequency. This will generate a analog waveform that can drive analog circuits. You could connect this to ADC input pin.
You could Google "Active low pass filter" for a lot of schematics and formula.
BUT
To be able to faithfully reproduce analog signal captured through ADC on a computer screen graph, your ADC sample rate must be more than ~2.5 times analog signal's bandwidth.
If your sample rate is close to Nyquist rates, you'd need to filter (interpolate) your digitized signal in software to generate a smooth graph. This is a bit involved in maths and software. Otherwise you'd only get a "spikey" waveform.
Or preferably have a sample rate> 10 times analog bandwidth. This will give large enough sample counts to reliably show analog data without much processing.
-
nope not interested in an "analog equivalent voltage". I just wanted to measure the PWM waveform, and wasn't sure if by using the same board for measuring and generating (of the signal) I could potentially burn it outevan54– evan542015年10月30日 09:33:55 +00:00Commented Oct 30, 2015 at 9:33
-
Usually digital waveforms are better captured by counters + interrupts, because exact voltage level is usually of no concern. i.e. for all transitions (hi->lo, lo->high), trigger interrupt. In ISR record a timer counter value and store. Capture timer clock needs to be (much) faster than PWM clockGPS– GPS2015年10月30日 11:49:22 +00:00Commented Oct 30, 2015 at 11:49