I want to properly connect a Radio Control Receiver signal to a Arduino Pro Mini, Pin 11 so I can detect the 1 ms to 2 ms PWM signal. I calculate a value of 220 ohms will limit the circuit current to 22mA. The Arduino strongly suggests using 20mA with a 40mA max on input pins. Do I need a .1uF cap to ground? Electrolytic cap? I would think adding a cap will cause the signal line to ride at a certain voltage level instead of having a sharp leading/trailing signal levels. TIA
-
1do you mean 1 mS or 1 ms? The first is a measure of electrical conductivity, the other of time – both kind of make sense here, so it's not really clear what you mean. It's more likely that you mean millisecond, but that's abbreviated "ms". – Marcus Müller Jan 03 '20 at 23:06
-
2On a second read, I think you really mean millisecond; I'll go ahead and fix that. Now, why would you prefer to measure an analog voltage instead of counting the length of a pulse with a microcontroller? Measuring voltages accurately is way harder than measuring pulse length in the order of milliseconds, when you have a microcontroller that has timer units running at MHz! By the way, does "1 to 2 ms PWM signal" mean a 1 to 2 ms period, or a 1 to 2 ms duty cycle (out of an unknown, but fixed (?) period)? – Marcus Müller Jan 03 '20 at 23:09
-
I am referring to time with ms. Here is info I'm referencing for PWM servo signal: https://www.pololu.com/blog/17/servo-control-interface-in-detail. I'm using a radio control receiver and want to send a PWM signal to the Arduino to control the heating of a glow plug. – Garry48 Jan 05 '20 at 00:35
-
A friend suggested using a 220 ohm resistor to limit the current in case the pin is accidentally set to output. He also suggested using a 0.1uF cap to help eliminate noise on the pin 11 circuit. I guess I'll bread board it and look at the signal. – Garry48 Jan 05 '20 at 00:37
-
the current-limiting resistor is certainly a good idea; a digital input usually doesn't need very much denoising; 0.1 µF is a bit much if you want to determine the length of the pulse, but a bit too little if you really want to concert the duty cycle to an analog voltage, alternatively. – Marcus Müller Jan 05 '20 at 00:51
-
Wouldn’t this have a better home on the electronics forum? Where did you find a recommended current for an input pin? That’s not really a thing. There’s maximum currents through the internal protection circuitry, but that only applies if you exceed the max voltage range for the pin, and you really shouldn’t do that unless you know what you’re doing. From a compliance standpoint, having a series resistor is a good idea, but I’d personally go 1k-10k if I were concerned with damaging the pin. – Dan Szabo Jan 05 '20 at 14:56
-
Do you want to have an integrator to the PWM so that the Arduino samples an analog voltage through one of its ADCs or do you want to let the Arduino to calculate the pulse width? If it is the second, you don't need a cap and the current limiting resistor is definitely a good idea. If it is the first, lookup an active integrator, possibly followed by a simple signal conditioning circuit so that the voltage lands within specific limits. I would go for the second option, the Ardiuno can return a pulse width estimate very easily. – A_A Jan 06 '20 at 10:52
-
@MarcusMüller do you want to turn your comments to an answer so that this question can be closed gracefully (?). – A_A Jan 06 '20 at 10:52
-
@A_A yeah, might as well. – Marcus Müller Jan 06 '20 at 14:24
1 Answers
Discretize Amplitude or Time – that is the (signal processing question)
Seeing that you're using a microcontroller running at at leas 8 MHz (probably 16 MHz): It's way easier to measure the time a signal was high than to first average out the PWM cycle in analog domain and then convert that analog voltage to digital.
If this was a sigma-delta ADC, which are pretty popular for most applications these days: Technologically, the conversion from analog voltages to digital numbers happens through counting the time a signal was high; I think the Atmega328p uses a successive approximation ADC, though.
The technological reality is that for signals below a couple of GHz, it's easier to build fast digital silicon logic than to build exact analog silicon. Thus, the less complex, more accurate and often less power-hungry solution is always to rather measure in time direction than in amplitude direction.
Implementation
So, I'd stay with the 220 Ω resistor: It really limits the current in the misconfiguration case, and is negligible compared to the proper input impedance.
Whether or not to add a capacitor really depends on what amount of noise you're expecting: you'll need a lot of noise to convert a stable TTL "high" to a "low", or vice versa. It still makes sense to do a bit of filtering, but not really with 0.1 µF:
----|220 Ω| ----·------ GPIO PIN
R |
= C?
|
v GND
If we understand the RC combination as low-pass filter, then 220 Ω -- 100 nF leads to a cutoff frequency of ca 8 kHz, so not enough to average out a PWM cycle (if you wanted to go the analog voltage route), but maybe a little too much if you wanted to the low/high edges nice and sharp for detection. Assuming no significant inteferers between that frequency and 80 kHz, I'd maybe start with 10 nF – I think the ATmega328p has smitt trigger inputs, so you're really pretty safe from transients.
So, you only need to implement a way of measuring time: for the large time scales you're talking about, this could easily done by waiting for the pin to become high, and then just counting the CPU cycles until it turns low again. But that blocks the CPU for anything else – it'd be more elegant to use to use the built-in Timer/Counter units of the microcontroller, which have been invented for exactly that reason. You can program them to start counting at the rising edge of an external input signal, and stop on a negative edge.
- 30,525
- 4
- 34
- 58
-
Marcus, Thank you very much! Just the information I was looking for! I really appreciate your expertise! Have a great 2020! – Garry48 Jan 06 '20 at 16:24
-
-
@Garry48 as this isn't a discussion forum, there's no "thread" to close: you, and only you, can accept an answer, which marks your question as answered. – Marcus Müller Jan 06 '20 at 16:59
